2022-09-18 11:57:22 +01:00
|
|
|
import { CommandInteraction, EmbedBuilder, PermissionsBitField, SlashCommandBuilder } from "discord.js";
|
2022-04-24 14:46:37 +01:00
|
|
|
import SettingsHelper from "../helpers/SettingsHelper";
|
|
|
|
import StringTools from "../helpers/StringTools";
|
|
|
|
import { Command } from "../type/command";
|
|
|
|
|
|
|
|
export default class Code extends Command {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
super.CommandBuilder = new SlashCommandBuilder()
|
|
|
|
.setName('code')
|
|
|
|
.setDescription('Manage the verification code of the server')
|
|
|
|
.setDefaultMemberPermissions(PermissionsBitField.Flags.ModerateMembers)
|
|
|
|
.addSubcommand(subcommand =>
|
|
|
|
subcommand
|
|
|
|
.setName('randomise')
|
|
|
|
.setDescription('Regenerates the verification code for this server'))
|
|
|
|
.addSubcommand(subcommand =>
|
|
|
|
subcommand
|
|
|
|
.setName('embed')
|
|
|
|
.setDescription('Sends the embed with the current code to the current channel'));
|
2022-04-24 14:46:37 +01:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
public override async execute(interaction: CommandInteraction) {
|
|
|
|
if (!interaction.isChatInputCommand()) return;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
switch (interaction.options.getSubcommand()) {
|
2022-04-24 14:46:37 +01:00
|
|
|
case "randomise":
|
2022-09-18 11:57:22 +01:00
|
|
|
await this.Randomise(interaction);
|
2022-04-24 14:46:37 +01:00
|
|
|
break;
|
|
|
|
case "embed":
|
2022-09-18 11:57:22 +01:00
|
|
|
await this.SendEmbed(interaction);
|
2022-04-24 14:46:37 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
private async Randomise(interaction: CommandInteraction) {
|
|
|
|
if (!interaction.guildId) return;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
|
|
|
const randomCode = StringTools.RandomString(5);
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
await SettingsHelper.SetSetting("verification.code", interaction.guildId, randomCode);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
await interaction.reply(`Entry code has been set to \`${randomCode}\``);
|
2022-04-24 14:46:37 +01:00
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
private async SendEmbed(interaction: CommandInteraction) {
|
|
|
|
if (!interaction.guildId) return;
|
|
|
|
if (!interaction.channel) return;
|
2022-04-24 14:46:37 +01:00
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
const code = await SettingsHelper.GetSetting("verification.code", interaction.guildId);
|
2022-04-24 14:46:37 +01:00
|
|
|
|
|
|
|
if (!code || code == "") {
|
2022-09-18 11:57:22 +01:00
|
|
|
await interaction.reply("There is no code for this server setup.");
|
2022-04-24 14:46:37 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-09-18 11:57:22 +01:00
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setTitle("Entry Code")
|
|
|
|
.setDescription(code);
|
|
|
|
|
|
|
|
await interaction.channel.send({ embeds: [ embed ]});
|
2022-04-24 14:46:37 +01:00
|
|
|
}
|
|
|
|
}
|