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_FILE = "./accounts.json";
|
||||||
|
|
||||||
const Accounts = Bun.file(ACCOUNTS_FILE);
|
|
||||||
|
|
||||||
export const initAccounts = async (): Promise<void> => {
|
export const initAccounts = async (): Promise<void> => {
|
||||||
if (!(await Accounts.exists())) {
|
if (!(await Bun.file(ACCOUNTS_FILE).exists())) {
|
||||||
Accounts.write("{}");
|
Bun.file(ACCOUNTS_FILE).write("{}");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAccountBalance = async (playerId: string): Promise<number> => {
|
export const getAccountBalance = async (playerId: string): Promise<number> => {
|
||||||
console.log("getAccountBalance");
|
const accounts: Record<string, number> = await Bun.file(ACCOUNTS_FILE).json();
|
||||||
const accounts: Record<string, number> = await Accounts.json();
|
|
||||||
console.log("getAccountBalance :: next");
|
|
||||||
if (accounts[playerId]) return accounts[playerId];
|
if (accounts[playerId]) return accounts[playerId];
|
||||||
|
|
||||||
accounts[playerId] = 0;
|
accounts[playerId] = 0;
|
||||||
console.log("getAccountBalance :: next");
|
await Bun.file(ACCOUNTS_FILE).write(JSON.stringify(accounts));
|
||||||
await Accounts.write(JSON.stringify(accounts));
|
|
||||||
console.log("getAccountBalance :: next");
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
@@ -26,11 +20,8 @@ export const setAccountBalance = async (
|
|||||||
playerId: string,
|
playerId: string,
|
||||||
balance: number,
|
balance: number,
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
console.log("setAccountBalance");
|
const accounts: Record<string, number> = await Bun.file(ACCOUNTS_FILE).json();
|
||||||
const accounts: Record<string, number> = await Accounts.json();
|
|
||||||
console.log("setAccountBalance :: next");
|
|
||||||
accounts[playerId] = balance;
|
accounts[playerId] = balance;
|
||||||
|
|
||||||
await Accounts.write(JSON.stringify(accounts));
|
await Bun.file(ACCOUNTS_FILE).write(JSON.stringify(accounts));
|
||||||
console.log("setAccountBalance :: next");
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ client.on("ready", async (client) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
client.on("messageCreate", async (message) => {
|
client.on("messageCreate", async (message) => {
|
||||||
if (message.author.bot) return;
|
if (message.author.bot || !message.member) return;
|
||||||
|
|
||||||
if (message.content.startsWith(`<@${client.user!.id}>`)) {
|
if (message.content.startsWith(`<@${client.user!.id}>`)) {
|
||||||
const [command, ...args] = message.content
|
const [command, ...args] = message.content
|
||||||
@@ -173,6 +173,13 @@ client.on("messageCreate", async (message) => {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (args.length === 2) {
|
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 (
|
if (
|
||||||
(args[1][0] !== "+" && args[1][0] !== "-") ||
|
(args[1][0] !== "+" && args[1][0] !== "-") ||
|
||||||
!args[1] ||
|
!args[1] ||
|
||||||
|
|||||||
Reference in New Issue
Block a user