muse/src/commands/config.ts

64 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-03-09 21:00:18 +01:00
import {TextChannel} from 'discord.js';
2020-03-09 17:57:39 +01:00
import {CommandHandler} from '../interfaces';
2020-03-09 21:00:18 +01:00
import {Settings} from '../models';
2020-03-09 17:57:39 +01:00
const config: CommandHandler = {
name: 'config',
description: 'Change various bot settings.',
2020-03-09 21:00:18 +01:00
execute: async (msg, args) => {
if (args.length === 0) {
// Show current settings
const settings = await Settings.findByPk(msg.guild!.id);
if (settings) {
let response = `prefix: \`${settings.prefix}\`\n`;
response += `channel: ${msg.guild!.channels.cache.get(settings.channel)!.toString()}`;
await msg.channel.send(response);
}
return;
}
2020-03-09 17:57:39 +01:00
const setting = args[0];
2020-03-09 21:00:18 +01:00
if (args.length !== 2) {
await msg.channel.send('🚫 incorrect number of arguments');
return;
}
2020-03-09 17:57:39 +01:00
switch (setting) {
2020-03-09 21:00:18 +01:00
case 'prefix': {
const newPrefix = args[1];
await Settings.update({prefix: newPrefix}, {where: {guildId: msg.guild!.id}});
await msg.channel.send(`👍 prefix updated to \`${newPrefix}\``);
2020-03-09 17:57:39 +01:00
break;
2020-03-09 21:00:18 +01:00
}
case 'channel': {
const channel = msg.guild!.channels.cache.find(c => c.name === args[1]);
if (channel && channel.type === 'text') {
await Settings.update({channel: channel.id}, {where: {guildId: msg.guild!.id}});
await Promise.all([
(channel as TextChannel).send('hey apparently I\'m bound to this channel now'),
msg.react('👍')
]);
} else {
await msg.channel.send('🚫 either that channel doesn\'t exist or you want me to become sentient and listen to a voice channel');
}
2020-03-09 17:57:39 +01:00
break;
2020-03-09 21:00:18 +01:00
}
2020-03-09 17:57:39 +01:00
default:
2020-03-09 21:00:18 +01:00
await msg.channel.send('🚫 I\'ve never met this setting in my life');
2020-03-09 17:57:39 +01:00
}
}
};
export default config;