diff --git a/src/account.ts b/src/account.ts index 020f957..a590d33 100644 --- a/src/account.ts +++ b/src/account.ts @@ -1,23 +1,17 @@ const ACCOUNTS_FILE = "./accounts.json"; -const Accounts = Bun.file(ACCOUNTS_FILE); - export const initAccounts = async (): Promise => { - if (!(await Accounts.exists())) { - Accounts.write("{}"); + if (!(await Bun.file(ACCOUNTS_FILE).exists())) { + Bun.file(ACCOUNTS_FILE).write("{}"); } }; export const getAccountBalance = async (playerId: string): Promise => { - console.log("getAccountBalance"); - const accounts: Record = await Accounts.json(); - console.log("getAccountBalance :: next"); + const accounts: Record = await Bun.file(ACCOUNTS_FILE).json(); if (accounts[playerId]) return accounts[playerId]; accounts[playerId] = 0; - console.log("getAccountBalance :: next"); - await Accounts.write(JSON.stringify(accounts)); - console.log("getAccountBalance :: next"); + await Bun.file(ACCOUNTS_FILE).write(JSON.stringify(accounts)); return 0; }; @@ -26,11 +20,8 @@ export const setAccountBalance = async ( playerId: string, balance: number, ): Promise => { - console.log("setAccountBalance"); - const accounts: Record = await Accounts.json(); - console.log("setAccountBalance :: next"); + const accounts: Record = await Bun.file(ACCOUNTS_FILE).json(); accounts[playerId] = balance; - await Accounts.write(JSON.stringify(accounts)); - console.log("setAccountBalance :: next"); + await Bun.file(ACCOUNTS_FILE).write(JSON.stringify(accounts)); }; diff --git a/src/index.ts b/src/index.ts index bdeb908..32ee540 100644 --- a/src/index.ts +++ b/src/index.ts @@ -146,7 +146,7 @@ client.on("ready", async (client) => { }); client.on("messageCreate", async (message) => { - if (message.author.bot) return; + if (message.author.bot || !message.member) return; if (message.content.startsWith(`<@${client.user!.id}>`)) { const [command, ...args] = message.content @@ -173,6 +173,13 @@ client.on("messageCreate", async (message) => { ); } else { if (args.length === 2) { + if (!message.member.roles.cache.has("1147963065640439900")) { + await message.reply( + "Tu t'es cru chez mémé ou quoi faut être staff", + ); + return; + } + if ( (args[1][0] !== "+" && args[1][0] !== "-") || !args[1] ||