added update command

main
Benjamin Kraft 4 months ago
parent 67a7e165a1
commit 51ea3a4e52
  1. 2
      src/bot.ts
  2. 8
      src/commands/add.ts
  3. 8
      src/commands/list.ts
  4. 8
      src/commands/remove.ts
  5. 22
      src/commands/update.ts
  6. 10
      src/util.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();
});
}

@ -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)

@ -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){

@ -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)

@ -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();

@ -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;
}
Loading…
Cancel
Save