diff --git a/src/bot.ts b/src/bot.ts index ddc5da2..a52c8d8 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -18,7 +18,7 @@ export class UEMEloBot extends Client { this.commands = commands; const token = await this.login(); console.log(`Discord Token: ${token}`); - setInterval(this.updatePlayers.bind(this), 10 * 60 * 1000); + setInterval(this.updatePlayers.bind(this), 30 * 60 * 1000); await this.updatePlayers(); }); } diff --git a/src/commands/add.ts b/src/commands/add.ts index c62292f..9bdd86b 100644 --- a/src/commands/add.ts +++ b/src/commands/add.ts @@ -1,6 +1,7 @@ import {Interaction, PermissionsBitField} from "discord.js"; import {Command} from "../command"; import {UEMEloBot} from "../bot"; +import {checkServer} from "../util"; class Add extends Command { constructor() { @@ -18,12 +19,9 @@ class Add extends Command { const riotId = interaction.options.getString("riot-id", true); const [gameName, tagLine] = riotId.split("#"); - const serverID = interaction.guild?.id; - if (!serverID){ - console.error("Server ID is missing!"); - await interaction.reply({content: "Fehler!", ephemeral: true}); + const serverID = await checkServer(interaction); + if (!serverID) return; - } const player = await client.addPlayer(gameName, tagLine, serverID); if (player) diff --git a/src/commands/list.ts b/src/commands/list.ts index 6987d81..553a19e 100644 --- a/src/commands/list.ts +++ b/src/commands/list.ts @@ -2,6 +2,7 @@ import {Interaction, EmbedBuilder, APIEmbedField, codeBlock} from "discord.js"; import {Command} from "../command"; import {UEMEloBot} from "../bot"; import {eloToNumber, Player} from "../player"; +import {checkServer} from "../util"; class List extends Command { constructor() { @@ -11,12 +12,9 @@ class List extends Command { if (!interaction.isChatInputCommand()) return; - const serverID = interaction.guild?.id; - if (!serverID){ - console.error("Server ID is missing!"); - await interaction.reply({content: "Fehler!", ephemeral: true}); + const serverID = await checkServer(interaction); + if (!serverID) return; - } let players = (interaction.client as UEMEloBot).servers.ensure(serverID, () => []); if (players.length === 0){ diff --git a/src/commands/remove.ts b/src/commands/remove.ts index ac2a1fc..5459737 100644 --- a/src/commands/remove.ts +++ b/src/commands/remove.ts @@ -1,6 +1,7 @@ import {Interaction, PermissionsBitField} from "discord.js"; import {Command} from "../command"; import {UEMEloBot} from "../bot"; +import {checkServer} from "../util"; class Remove extends Command { constructor() { @@ -18,12 +19,9 @@ class Remove extends Command { const riotId = interaction.options.getString("riot-id", true); const [gameName, tagLine] = riotId.split("#"); - const serverID = interaction.guild?.id; - if (!serverID){ - console.error("Server ID is missing!"); - await interaction.reply({content: "Fehler!", ephemeral: true}); + const serverID = await checkServer(interaction); + if (!serverID) return; - } const player = await client.removePlayer(gameName, tagLine, serverID); if (player) diff --git a/src/commands/update.ts b/src/commands/update.ts new file mode 100644 index 0000000..bd0b41f --- /dev/null +++ b/src/commands/update.ts @@ -0,0 +1,22 @@ +import {Interaction} from "discord.js"; +import {Command} from "../command"; +import {UEMEloBot} from "../bot"; + +class Update extends Command { + constructor() { + super("update", "Ränge jetzt aktualisieren (passiert automatisch alle 30min)"); + } + async execute(interaction: Interaction) { + if (!interaction.isChatInputCommand()) + return; + + await interaction.deferReply({ephemeral: true}); + + let client = interaction.client as UEMEloBot; + await client.updatePlayers(); + + await interaction.editReply({content: "Aktualisiert!"}); + } +} + +export default new Update(); \ No newline at end of file diff --git a/src/util.ts b/src/util.ts new file mode 100644 index 0000000..152a569 --- /dev/null +++ b/src/util.ts @@ -0,0 +1,10 @@ +import {ChatInputCommandInteraction} from "discord.js"; + +export async function checkServer(interaction: ChatInputCommandInteraction){ + const serverID = interaction.guild?.id; + if (!serverID){ + console.error("Server ID is missing!"); + await interaction.reply({content: "Fehler!", ephemeral: true}); + } + return serverID; +} \ No newline at end of file