add delete command to reset a lfg channel
This commit is contained in:
parent
79673bdf91
commit
19d3aa7819
|
@ -4,9 +4,10 @@ import { dbClient } from '../src/db.ts';
|
||||||
|
|
||||||
console.log('Attempting to insert default actions into command_cnt');
|
console.log('Attempting to insert default actions into command_cnt');
|
||||||
const actions = [
|
const actions = [
|
||||||
'cmd-setup',
|
'cmd-delete',
|
||||||
'cmd-info',
|
'cmd-info',
|
||||||
'cmd-report',
|
'cmd-report',
|
||||||
|
'cmd-setup',
|
||||||
];
|
];
|
||||||
for (const action of actions) {
|
for (const action of actions) {
|
||||||
await dbClient.execute('INSERT INTO command_cnt(command) values(?)', [action]).catch((e) => {
|
await dbClient.execute('INSERT INTO command_cnt(command) values(?)', [action]).catch((e) => {
|
||||||
|
|
|
@ -5,8 +5,9 @@ import utils from '../utils.ts';
|
||||||
import info from './info.ts';
|
import info from './info.ts';
|
||||||
import report from './report.ts';
|
import report from './report.ts';
|
||||||
import setup from './setup.ts';
|
import setup from './setup.ts';
|
||||||
|
import deleteCmd from './delete.ts';
|
||||||
|
|
||||||
export const commands: Array<Command> = [info, report, setup];
|
export const commands: Array<Command> = [deleteCmd, info, report, setup];
|
||||||
|
|
||||||
export const createSlashCommands = async (bot: Bot) => {
|
export const createSlashCommands = async (bot: Bot) => {
|
||||||
const globalCommands: MakeRequired<CreateApplicationCommand, 'name'>[] = [];
|
const globalCommands: MakeRequired<CreateApplicationCommand, 'name'>[] = [];
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
import config from '../../config.ts';
|
||||||
|
import { ApplicationCommandFlags, ApplicationCommandTypes, Bot, Interaction, InteractionResponseTypes } from '../../deps.ts';
|
||||||
|
import { failColor, somethingWentWrong, successColor } from '../commandUtils.ts';
|
||||||
|
import { dbClient, lfgChannelSettings, queries } from '../db.ts';
|
||||||
|
import { CommandDetails } from '../types/commandTypes.ts';
|
||||||
|
import utils from '../utils.ts';
|
||||||
|
|
||||||
|
const details: CommandDetails = {
|
||||||
|
name: 'delete-lfg-channel',
|
||||||
|
description: `Removes all settings from ${config.name} related to this LFG channel. Events will not be deleted.`,
|
||||||
|
type: ApplicationCommandTypes.ChatInput,
|
||||||
|
defaultMemberPermissions: ['ADMINISTRATOR'],
|
||||||
|
};
|
||||||
|
|
||||||
|
const execute = async (bot: Bot, interaction: Interaction) => {
|
||||||
|
dbClient.execute(queries.callIncCnt('cmd-delete')).catch((e) => utils.commonLoggers.dbError('delete.ts', 'call sproc INC_CNT on', e));
|
||||||
|
|
||||||
|
if (interaction.guildId && interaction.channelId) {
|
||||||
|
if (!lfgChannelSettings.has(`${interaction.guildId}-${interaction.channelId}`)) {
|
||||||
|
// Cannot delete a lfg channel that has not been set up
|
||||||
|
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||||
|
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||||
|
data: {
|
||||||
|
flags: ApplicationCommandFlags.Ephemeral,
|
||||||
|
embeds: [{
|
||||||
|
color: failColor,
|
||||||
|
title: 'Unable to delete LFG channel.',
|
||||||
|
description:
|
||||||
|
'This channel is already is not an LFG channel. If you need to setup the channel, please run `/setup` in this channel.\n\nThis will not harm any active events in this channel and simply resets the settings for this channel.',
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
}).catch((e: Error) => utils.commonLoggers.interactionSendError('delete.ts', interaction, e));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove it from the DB
|
||||||
|
let dbError = false;
|
||||||
|
await dbClient.execute('DELETE FROM guild_settings WHERE guildId = ? AND lfgChannelId = ?', [interaction.guildId, interaction.channelId]).catch((e) => {
|
||||||
|
utils.commonLoggers.dbError('delete.ts', 'delete guild/lfgChannel', e);
|
||||||
|
dbError = true;
|
||||||
|
});
|
||||||
|
if (dbError) {
|
||||||
|
somethingWentWrong(bot, interaction, 'deleteDBDeleteFail');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lfgChannelSettings.delete(`${interaction.guildId}-${interaction.channelId}`);
|
||||||
|
|
||||||
|
// Complete the interaction
|
||||||
|
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
|
||||||
|
type: InteractionResponseTypes.ChannelMessageWithSource,
|
||||||
|
data: {
|
||||||
|
flags: ApplicationCommandFlags.Ephemeral,
|
||||||
|
embeds: [{
|
||||||
|
color: successColor,
|
||||||
|
title: 'LFG Channel settings removed!',
|
||||||
|
description: `${config.name} has finished removing the settings for this channel. You may safely dismiss this message.`,
|
||||||
|
}],
|
||||||
|
},
|
||||||
|
}).catch((e: Error) => utils.commonLoggers.interactionSendError('delete.ts', interaction, e));
|
||||||
|
} else {
|
||||||
|
somethingWentWrong(bot, interaction, 'deleteMissingGuildIdChannelId');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default {
|
||||||
|
details,
|
||||||
|
execute,
|
||||||
|
};
|
Loading…
Reference in New Issue