From f34cd8e427f78e509ef695fd2fbd137c99ada9e9 Mon Sep 17 00:00:00 2001 From: 1computer1 Date: Thu, 16 May 2019 21:02:44 -0400 Subject: [PATCH] Add config option for prefixes --- README.md | 2 ++ config.example.json | 2 ++ src/listeners/messageInvalid.js | 5 +++-- src/struct/CompilerClient.js | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index eb38582..e1c49ac 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,8 @@ The container is locked down, so there is no networking, limited memory and CPU - `owner` - The owner(s) of the bot. Use an array for multiple owners. - `token` - The bot token. + - `prefix` - The prefix for commands. + - `codePrefix` - The prefix for code evaluation. - `languages` Languages to use. The language names here are different from the user-facing ones. Check the folders in `docker/` for the language names. diff --git a/config.example.json b/config.example.json index 0110d99..dc6ecac 100644 --- a/config.example.json +++ b/config.example.json @@ -1,6 +1,8 @@ { "owner": "12345678901234", "token": "MTU1fdsYNTRb2RT.FcD2l1ig.jIuKqwertyd432RROhF5A", + "prefix": ">", + "codePrefix": ">", "languages": [ "haskell", "python", diff --git a/src/listeners/messageInvalid.js b/src/listeners/messageInvalid.js index 332c4cd..8da7238 100644 --- a/src/listeners/messageInvalid.js +++ b/src/listeners/messageInvalid.js @@ -59,8 +59,9 @@ class MessageInvalidListener extends Listener { } parseMessage(message) { - const regex1 = /^\s*>\s*(.+?)?\s*```(.+?)\n([^]+)```\s*$/; - const regex2 = /^\s*>\s*(.+?)?\s*`(.+?) \s*([^]+)`\s*$/; + const prefix = this.client.config.codePrefix.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); + const regex1 = new RegExp(`^\\s*${prefix}\\s*(.+?)?\\s*\`\`\`(.+?)\\n([^]+)\`\`\`\\s*$`); + const regex2 = new RegExp(`^\\s*${prefix}\\s*(.+?)?\\s*\`(.+?) \\s*([^]+)\`\\s*$`); const match = message.content.match(regex1) || message.content.match(regex2); if (!match) { return null; diff --git a/src/struct/CompilerClient.js b/src/struct/CompilerClient.js index 36b4ed5..ed4a16b 100644 --- a/src/struct/CompilerClient.js +++ b/src/struct/CompilerClient.js @@ -13,7 +13,7 @@ class CompilerClient extends AkairoClient { this.commandHandler = new CommandHandler(this, { directory: path.join(__dirname, '../commands'), - prefix: '>', + prefix: config.prefix, allowMention: true, commandUtil: true, commandUtilLifetime: 3e5,