feat: add role check for staff commands and fix weird json parsing crash
This commit is contained in:
@@ -1,23 +1,17 @@
|
||||
const ACCOUNTS_FILE = "./accounts.json";
|
||||
|
||||
const Accounts = Bun.file(ACCOUNTS_FILE);
|
||||
|
||||
export const initAccounts = async (): Promise<void> => {
|
||||
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<number> => {
|
||||
console.log("getAccountBalance");
|
||||
const accounts: Record<string, number> = await Accounts.json();
|
||||
console.log("getAccountBalance :: next");
|
||||
const accounts: Record<string, number> = 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<void> => {
|
||||
console.log("setAccountBalance");
|
||||
const accounts: Record<string, number> = await Accounts.json();
|
||||
console.log("setAccountBalance :: next");
|
||||
const accounts: Record<string, number> = 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));
|
||||
};
|
||||
|
||||
@@ -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] ||
|
||||
|
||||
Reference in New Issue
Block a user