diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-09-02 19:26:10 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-09-02 19:26:10 -0400 |
commit | 1623beebadefa38769db134a0fbfce0c34b38846 (patch) | |
tree | f75b71cdda596acfe7bd09812f3cfa3a00a08e1a /src/commands/config | |
parent | 930b1a46830567fd51780f301e550dbf4a87c7f3 (diff) | |
download | tanzanite-1623beebadefa38769db134a0fbfce0c34b38846.tar.gz tanzanite-1623beebadefa38769db134a0fbfce0c34b38846.tar.bz2 tanzanite-1623beebadefa38769db134a0fbfce0c34b38846.zip |
log command
Diffstat (limited to 'src/commands/config')
-rw-r--r-- | src/commands/config/features.ts | 1 | ||||
-rw-r--r-- | src/commands/config/log.ts | 86 |
2 files changed, 87 insertions, 0 deletions
diff --git a/src/commands/config/features.ts b/src/commands/config/features.ts index 7a7c3bb..3c607c7 100644 --- a/src/commands/config/features.ts +++ b/src/commands/config/features.ts @@ -19,6 +19,7 @@ export default class FeaturesCommand extends BushCommand { } public override async exec(message: BushMessage | BushSlashMessage): Promise<unknown> { if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be used in servers.`); + const featureEmbed = new MessageEmbed().setTitle(`${message.guild!.name}'s Features`).setColor(util.colors.default); const enabledFeatures = await message.guild!.getSetting('enabledFeatures'); diff --git a/src/commands/config/log.ts b/src/commands/config/log.ts new file mode 100644 index 0000000..592f700 --- /dev/null +++ b/src/commands/config/log.ts @@ -0,0 +1,86 @@ +import { BushCommand, BushMessage, BushSlashMessage, guildLogsArr, GuildLogType } from '@lib'; +import { ArgumentOptions, Flag } from 'discord-akairo'; +import { TextChannel } from 'discord.js'; + +export default class LogCommand extends BushCommand { + public constructor() { + super('log', { + aliases: ['log', 'logging'], + category: 'config', + description: { + content: 'Set or remove a log channel.', + usage: 'log <logType> [channel]', + examples: ['log automod #automod-logs'] + }, + slash: true, + slashOptions: [ + { + name: 'log_type', + description: 'What log type would you like to change?', + type: 'STRING', + required: true, + choices: guildLogsArr.map((log) => ({ name: log, value: log })) + }, + { + name: 'channel', + description: 'What channel would you like these logs to be sent in?', + type: 'CHANNEL', + required: false + } + ], + channel: 'guild', + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES', 'MANAGE_GUILD'] + }); + } + + *args(): IterableIterator<ArgumentOptions | Flag> { + const log_type = yield { + id: 'log', + type: guildLogsArr, + prompt: { + start: 'What log type would you like to change?', + retry: `{error} Choose either ${util.oxford( + guildLogsArr.map((l) => `\`${l}\``), + 'or' + )}`, + optional: false + } + }; + + const channel = yield { + id: 'channel', + type: 'textChannel', + prompt: { + start: `What channel would you like ${log_type} logs to be sent in?`, + retry: `{error} Choose a valid text channel for ${log_type} logs to be sent in.` + } + }; + + return { log_type, channel }; + } + + public override async exec( + message: BushMessage | BushSlashMessage, + args: { log_type: GuildLogType; channel: TextChannel } + ): Promise<unknown> { + if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be used in servers.`); + const currentLogs = await message.guild.getSetting('logChannels'); + const oldChannel = currentLogs[args.log_type] ?? undefined; + + const action = !!args.channel; + + action ? (currentLogs[args.log_type] = args.channel.id) : delete currentLogs[args.log_type]; + + const success = await message.guild.setSetting('logChannels', currentLogs); + return await message.util.reply( + `${ + success + ? `${util.emojis.success} Successfully ${oldChannel ? 'changed' : 'set'}` + : `${util.emojis.error} Unable to ${oldChannel ? 'change' : 'set'}` + } ${ + oldChannel ? ` the \`${args.log_type}\` log channel from <#${oldChannel}>` : ` the \`${args.log_type}\` log channel` + } to ${args.channel ? `<#${args.channel.id}>` : '`disabled`'}` + ); + } +} |