feat: edit gemmes of user

This commit is contained in:
Pihkaal
2025-07-28 22:18:42 +02:00
parent 4f73000585
commit 7a70894b8b
3 changed files with 32 additions and 15 deletions

View File

@@ -9,11 +9,15 @@ export const initAccounts = async (): Promise<void> => {
}; };
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 Accounts.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 Accounts.write(JSON.stringify(accounts)); await Accounts.write(JSON.stringify(accounts));
console.log("getAccountBalance :: next")
return 0; return 0;
}; };
@@ -22,8 +26,11 @@ 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 Accounts.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 Accounts.write(JSON.stringify(accounts));
console.log("setAccountBalance :: next")
}; };

View File

@@ -138,8 +138,8 @@ client.on("ready", async (client) => {
await initAccounts(); await initAccounts();
// await fn(); await fn();
// setInterval(fn, env.WOV_FETCH_INTERVAL); setInterval(fn, env.WOV_FETCH_INTERVAL);
}); });
client.on("messageCreate", async (message) => { client.on("messageCreate", async (message) => {
@@ -169,20 +169,27 @@ client.on("messageCreate", async (message) => {
`'${args[0]}' n'est pas dans le clan (la honte). **Attention les majuscules sont importantes**`, `'${args[0]}' n'est pas dans le clan (la honte). **Attention les majuscules sont importantes**`,
); );
} else { } else {
if(args.length === 2) {
if (
(args[1][0] !== "+" && args[1][0] !== "-") ||
!args[1] ||
isNaN(Number(args[1].substring(1)))
) {
await message.reply(
`Format: \`@LBF gemmes <pseudo> <+GEMMES|-GEMMES>\`.\nExemple:\`@LBF gemmes Yuno -10000\`. **Attention les majuscules sont importantes**`,
);
return;
}
const mult = args[1][0] === '+' ? 1 : -1;
const delta = Number(args[1].substring(1)) * mult;
const balance = await getAccountBalance(clanMember.playerId);
await setAccountBalance(clanMember.playerId, Math.max(0, balance + delta));
}
const balance = await getAccountBalance(clanMember.playerId); const balance = await getAccountBalance(clanMember.playerId);
await message.reply(`Gemmes accumulées par ${playerName}: ${balance}`); await message.reply(`Gemmes accumulées par ${playerName}: ${balance}`);
} }
} else if (command === "zero") {
const playerName = message.author.displayName.replace("🕸 |", "").trim();
const clanMembers = await getClanMembers();
const clanMember = clanMembers.find((x) => x.username === playerName);
if (!clanMember) {
await message.reply("Pas du clan pas de gemmes");
} else {
await setAccountBalance(clanMember.playerId, 0);
await message.reply("Zero gemmes mtn bouuh");
}
} }
} }
}); });

View File

@@ -34,8 +34,11 @@ export const checkForNewQuest = async (): Promise<QuestResult | null> => {
const lastId = lastQuest.quest.id; const lastId = lastQuest.quest.id;
const cacheFile = Bun.file(".cache/.quest_cache"); const cacheFile = Bun.file(".cache/.quest_cache");
await mkdir(".cache", { recursive: true }); await mkdir(".cache", { recursive: true });
if ((await cacheFile.exists()) && (await cacheFile.text()) === lastId) { if (await cacheFile.exists()) {
return null; const cachedQuestId = await cacheFile.text();
if(cachedQuestId === lastId || cachedQuestId === "IGNORE") {
return null;
}
} }
await cacheFile.write(lastId); await cacheFile.write(lastId);