Compare commits

..

2 Commits

Author SHA1 Message Date
90b0994524 add bot cmd
Some checks failed
Deploy Backend / docker (ubuntu-latest) (push) Failing after 30s
2024-10-25 17:44:19 +01:00
53e0ce007d rename cron 2024-10-25 17:39:25 +01:00
3 changed files with 26 additions and 7 deletions

@ -8,7 +8,7 @@ export enum DiscordChannels {
backendLogs = "1296524935237468250", backendLogs = "1296524935237468250",
} }
const DiscordBot = new Client({ const client = new Client({
intents: [], intents: [],
presence: { presence: {
status: "online", status: "online",
@ -23,16 +23,17 @@ const DiscordBot = new Client({
}, },
}); });
DiscordBot.once("ready", () => { client.once("ready", () => {
console.log("Discord bot ready!"); console.log("Discord bot ready!");
}); });
export function initDiscordBot() { export async function initDiscordBot() {
console.log("Initializing discord bot..."); console.log("Initializing discord bot...");
MetadataStorage.instance.build().then(async () => { client.once("ready", async () => {
await DiscordBot.login(Config.discordBotToken!).then(); await client.initApplicationCommands();
}); });
await client.login(Config.discordBotToken!);
} }
/** /**
@ -42,7 +43,7 @@ export function initDiscordBot() {
* @param message the message to log * @param message the message to log
*/ */
export async function logToChannel(channelId: DiscordChannels, message: EmbedBuilder) { export async function logToChannel(channelId: DiscordChannels, message: EmbedBuilder) {
const channel = await DiscordBot.channels.fetch(channelId); const channel = await client.channels.fetch(channelId);
if (channel == undefined) { if (channel == undefined) {
throw new Error(`Channel "${channelId}" not found`); throw new Error(`Channel "${channelId}" not found`);
} }

@ -0,0 +1,18 @@
import { Discord, Slash } from "discordx";
import { CommandInteraction } from "discord.js";
import { PlayerService } from "../../service/player.service";
@Discord()
export class RefreshPlayerScoresCommand {
@Slash({
description: "Refreshes scores for all tracked players",
name: "refresh-player-scores",
defaultMemberPermissions: ["Administrator"],
})
hello(interaction: CommandInteraction) {
interaction.reply("Updating player scores...").then(async response => {
await PlayerService.refreshPlayerScores();
await response.edit("Done!");
});
}
}

@ -73,7 +73,7 @@ app.use(
); );
app.use( app.use(
cron({ cron({
name: "scores-background-refresh", name: "player-scores-tracker-cron",
pattern: "0 4 * * *", // Every day at 04:00 pattern: "0 4 * * *", // Every day at 04:00
timezone: "Europe/London", // UTC time timezone: "Europe/London", // UTC time
protect: true, protect: true,