|
| 1 | +import { Command } from 'discord-akairo'; |
| 2 | +import { MessageEmbed } from 'discord.js'; |
| 3 | +import pupa from 'pupa'; |
| 4 | +import SwanModule from '@/app/models/swanModule'; |
| 5 | +import type { GuildMessage, SwanModuleDocument } from '@/app/types'; |
| 6 | +import type { ModuleCommandArguments } from '@/app/types/CommandArguments'; |
| 7 | +import { noop, toggleModule } from '@/app/utils'; |
| 8 | +import { module as config } from '@/conf/commands/admin'; |
| 9 | +import messages from '@/conf/messages'; |
| 10 | +import settings from '@/conf/settings'; |
| 11 | + |
| 12 | +class ModuleCommand extends Command { |
| 13 | + constructor() { |
| 14 | + super('module', { |
| 15 | + aliases: config.settings.aliases, |
| 16 | + details: config.details, |
| 17 | + clientPermissions: config.settings.clientPermissions, |
| 18 | + userPermissions: config.settings.userPermissions, |
| 19 | + channel: 'guild', |
| 20 | + args: [ |
| 21 | + { |
| 22 | + id: 'moduleName', |
| 23 | + type: 'string', |
| 24 | + }, |
| 25 | + { |
| 26 | + id: 'enabled', |
| 27 | + type: 'string', |
| 28 | + }, |
| 29 | + ], |
| 30 | + }); |
| 31 | + } |
| 32 | + |
| 33 | + public async exec(message: GuildMessage, args: ModuleCommandArguments): Promise<void> { |
| 34 | + const modules: SwanModuleDocument[] = await SwanModule.find(); |
| 35 | + |
| 36 | + if (!args.moduleName) { |
| 37 | + const embed = new MessageEmbed() |
| 38 | + .setTitle(config.embed.title) |
| 39 | + .setURL(config.embed.link) |
| 40 | + .setColor(settings.colors.default) |
| 41 | + .setDescription(config.embed.content) |
| 42 | + .setFooter(pupa(messages.global.executedBy, { member: message.member })); |
| 43 | + void message.channel.send(embed).catch(noop); |
| 44 | + return; |
| 45 | + } |
| 46 | + |
| 47 | + const module = modules.find(m => m.name === args.moduleName); |
| 48 | + if (!module) { |
| 49 | + void message.channel.send(config.messages.noModuleFound).catch(noop); |
| 50 | + return; |
| 51 | + } |
| 52 | + |
| 53 | + if (!args.enabled) { |
| 54 | + void message.channel.send(pupa(config.messages.noStatus, { module })).catch(noop); |
| 55 | + return; |
| 56 | + } |
| 57 | + |
| 58 | + const enabled = args.enabled === 'on'; |
| 59 | + |
| 60 | + toggleModule(this.client, module, enabled); |
| 61 | + await SwanModule.findOneAndUpdate({ name: module.name }, { enabled }); |
| 62 | + |
| 63 | + void message.channel.send(pupa(config.messages.success, { status: enabled ? 'activé' : 'désactivé' })).catch(noop); |
| 64 | + } |
| 65 | +} |
| 66 | + |
| 67 | +export default ModuleCommand; |
0 commit comments