63 lines
1.9 KiB
JavaScript
63 lines
1.9 KiB
JavaScript
import { PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
|
import fs from "fs/promises";
|
|
|
|
export default {
|
|
name: "remove",
|
|
description: "Stoppt den Listener für Plugin-Updates",
|
|
aliases: [],
|
|
guild: ["all"],
|
|
nsfw: false,
|
|
user_permissions: [PermissionsBitField.Flags.Administrator],
|
|
bot_permissions: [],
|
|
args_required: 1,
|
|
args_usage: "[ressourcen_id]",
|
|
cooldown: 5,
|
|
|
|
data: new SlashCommandBuilder()
|
|
.setName("remove")
|
|
.setDescription("Entfernt einen Plugin-Update-Listener")
|
|
.addStringOption((opt) =>
|
|
opt.setName("ressourcen_id").setDescription("Spiget Ressourcen-ID").setRequired(true)
|
|
),
|
|
|
|
async execute(client, ctx, args) {
|
|
const resourceID = ctx.isSlash
|
|
? ctx.interaction.options.getString("ressourcen_id")
|
|
: args[0];
|
|
|
|
const guildID = ctx.guild.id;
|
|
const filePath = `./serverdata/${guildID}.json`;
|
|
|
|
let data;
|
|
try {
|
|
const raw = await fs.readFile(filePath, "utf8");
|
|
data = JSON.parse(raw);
|
|
} catch {
|
|
return ctx.reply("Dieser Server hat keine beobachteten Ressourcen!");
|
|
}
|
|
|
|
const index = data.watchedResources.findIndex(
|
|
(r) => String(r.resourceID) === String(resourceID)
|
|
);
|
|
|
|
if (index === -1) {
|
|
return ctx.reply(`Fehler: Ressource \`${resourceID}\` wurde auf diesem Server nicht beobachtet.`);
|
|
}
|
|
|
|
const removedName = data.watchedResources[index].resourceName ?? resourceID;
|
|
data.watchedResources.splice(index, 1);
|
|
|
|
try {
|
|
if (data.watchedResources.length === 0) {
|
|
await fs.unlink(filePath);
|
|
} else {
|
|
await fs.writeFile(filePath, JSON.stringify(data, null, 2));
|
|
}
|
|
} catch (e) {
|
|
client.logger.error(e);
|
|
return ctx.reply("Beim Aktualisieren der Beobachtungsdaten ist ein Fehler aufgetreten.");
|
|
}
|
|
|
|
return ctx.reply(`✅ **${removedName}** (\`${resourceID}\`) wird nicht mehr beobachtet.`);
|
|
},
|
|
}; |