mirror of
https://gitlab.edgegamers.io/discord/ds-bot.git
synced 2025-12-06 00:22:41 -08:00
68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
import { CacheType, CommandInteraction, SlashCommandSubcommandBuilder } from "discord.js";
|
|
import { DSBot } from "../../../../api/DSBot";
|
|
import { SubCommand } from "../../../../api/data/Command";
|
|
import { DSVoice, VoiceChannelMode } from "../../../DSVoice";
|
|
|
|
export class AddCommand extends SubCommand {
|
|
name = "add";
|
|
data: SlashCommandSubcommandBuilder = new SlashCommandSubcommandBuilder()
|
|
.setName(this.name)
|
|
.setDescription("Add a user to the list")
|
|
.addUserOption(option =>
|
|
option.setName("user")
|
|
.setDescription("The user to add to the list")
|
|
.setRequired(true));
|
|
|
|
main: DSBot;
|
|
type: VoiceChannelMode;
|
|
|
|
constructor(main: DSBot, type: VoiceChannelMode) {
|
|
super();
|
|
this.main = main;
|
|
this.type = type;
|
|
}
|
|
|
|
async handleCommand(interaction: CommandInteraction<CacheType>): Promise<boolean> {
|
|
const user = interaction.options.getUser("user", true);
|
|
if (!interaction.guildId) {
|
|
interaction.reply("This command can only be used in a server!");
|
|
|
|
return false;
|
|
}
|
|
|
|
if (user.id === interaction.user.id) {
|
|
interaction.reply("You can't add yourself to the list!");
|
|
|
|
return false;
|
|
}
|
|
|
|
const voiceModule = this.main.modules.getModule<DSVoice>(DSVoice);
|
|
if (!voiceModule) {
|
|
interaction.reply("The voice module is not loaded!");
|
|
|
|
return false;
|
|
}
|
|
const config = await voiceModule.getVoiceData(interaction.user.id, interaction.guildId);
|
|
if (!config) {
|
|
interaction.reply("You don't have a voice channel!");
|
|
|
|
return false;
|
|
}
|
|
|
|
const list = this.type === VoiceChannelMode.WHITELIST ? config.whitelist : config.blacklist;
|
|
|
|
if (list.indexOf(user.id) !== -1) {
|
|
interaction.reply({ content: `${user.toString()} has already been ${this.type}.`, ephemeral: true });
|
|
|
|
return false;
|
|
}
|
|
|
|
list.push(user.id);
|
|
|
|
voiceModule.updateUserChannel(config, interaction.guildId);
|
|
interaction.reply({ content: `${user.toString()} has been ${this.type}`, ephemeral: true });
|
|
|
|
return true;
|
|
}
|
|
}
|