diff options
| author | Max Isom <[email protected]> | 2020-03-09 15:00:18 -0500 |
|---|---|---|
| committer | Max Isom <[email protected]> | 2020-03-09 15:00:18 -0500 |
| commit | 652cc2e5efed6ddef593570ee90634cbc1c452bb (patch) | |
| tree | 6df810ab7715051c6cfe0613e7d338906260f36a /src/index.ts | |
| parent | eca84c8b6964af29948510a02ebfeb5f23244921 (diff) | |
| download | muse-652cc2e5efed6ddef593570ee90634cbc1c452bb.tar.xz muse-652cc2e5efed6ddef593570ee90634cbc1c452bb.zip | |
Add config command
Diffstat (limited to 'src/index.ts')
| -rw-r--r-- | src/index.ts | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/index.ts b/src/index.ts index 5771988..6681d45 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,12 +3,11 @@ import path from 'path'; import makeDir from 'make-dir'; import Discord from 'discord.js'; import {DISCORD_TOKEN, DISCORD_CLIENT_ID, DATA_DIR} from './utils/config'; +import {Settings} from './models'; import {sequelize} from './utils/db'; import {CommandHandler} from './interfaces'; import handleGuildCreate from './events/guild-create'; -const PREFIX = '!'; - const client = new Discord.Client(); const commands = new Discord.Collection(); @@ -22,12 +21,22 @@ for (const file of commandFiles) { } // Generic message handler -client.on('message', (msg: Discord.Message) => { - if (!msg.content.startsWith(PREFIX) || msg.author.bot) { +client.on('message', async (msg: Discord.Message) => { + // Get guild settings + const settings = await Settings.findByPk(msg.guild!.id); + + if (!settings) { + // Got into a bad state, send owner welcome message + return client.emit('guildCreate', msg.guild); + } + + const {prefix, channel} = settings; + + if (!msg.content.startsWith(prefix) || msg.author.bot || msg.channel.id !== channel) { return; } - const args = msg.content.slice(PREFIX.length).split(/ +/); + const args = msg.content.slice(prefix.length).split(/ +/); const command = args.shift()!.toLowerCase(); if (!commands.has(command)) { |
