feat: edit gemmes of user
This commit is contained in:
@@ -9,11 +9,15 @@ export const initAccounts = async (): Promise<void> => {
|
||||
};
|
||||
|
||||
export const getAccountBalance = async (playerId: string): Promise<number> => {
|
||||
console.log("getAccountBalance")
|
||||
const accounts: Record<string, number> = await Accounts.json();
|
||||
console.log("getAccountBalance :: next")
|
||||
if (accounts[playerId]) return accounts[playerId];
|
||||
|
||||
accounts[playerId] = 0;
|
||||
console.log("getAccountBalance :: next")
|
||||
await Accounts.write(JSON.stringify(accounts));
|
||||
console.log("getAccountBalance :: next")
|
||||
|
||||
return 0;
|
||||
};
|
||||
@@ -22,8 +26,11 @@ 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")
|
||||
accounts[playerId] = balance;
|
||||
|
||||
await Accounts.write(JSON.stringify(accounts));
|
||||
console.log("setAccountBalance :: next")
|
||||
};
|
||||
|
||||
33
src/index.ts
33
src/index.ts
@@ -138,8 +138,8 @@ client.on("ready", async (client) => {
|
||||
|
||||
await initAccounts();
|
||||
|
||||
// await fn();
|
||||
// setInterval(fn, env.WOV_FETCH_INTERVAL);
|
||||
await fn();
|
||||
setInterval(fn, env.WOV_FETCH_INTERVAL);
|
||||
});
|
||||
|
||||
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**`,
|
||||
);
|
||||
} 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);
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -34,9 +34,12 @@ export const checkForNewQuest = async (): Promise<QuestResult | null> => {
|
||||
const lastId = lastQuest.quest.id;
|
||||
const cacheFile = Bun.file(".cache/.quest_cache");
|
||||
await mkdir(".cache", { recursive: true });
|
||||
if ((await cacheFile.exists()) && (await cacheFile.text()) === lastId) {
|
||||
if (await cacheFile.exists()) {
|
||||
const cachedQuestId = await cacheFile.text();
|
||||
if(cachedQuestId === lastId || cachedQuestId === "IGNORE") {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
await cacheFile.write(lastId);
|
||||
return lastQuest;
|
||||
|
||||
Reference in New Issue
Block a user