浏览代码

Add allowDM option to allow commands to be run in DMs

ghorsington 4 年之前
父节点
当前提交
c052723ddd
共有 3 个文件被更改,包括 3 次插入6 次删除
  1. 0 6
      bot/src/main.ts
  2. 1 0
      bot/src/model/plugin.ts
  3. 2 0
      bot/src/plugin_manager.ts

+ 0 - 6
bot/src/main.ts

@@ -25,12 +25,6 @@ client.bot.on("message", async m => {
     if (m.author.id == client.botUser.id)
         return;
 
-    if (m.channel.type != "text") {
-        logger.warn("User %s (%s#%s) tried to execute command in DMs. Message: %s.", m.author.id, m.author.username, m.author.discriminator, m.content);
-        await m.reply("DM commands are disabled, sorry!");
-        return;
-    }
-
     if (m.content.startsWith(COMMAND_PREFIX) && await plgMgr.runCommand("prefix", m, m.content.substring(COMMAND_PREFIX.length))) {
         return;
     }

+ 1 - 0
bot/src/model/plugin.ts

@@ -12,6 +12,7 @@ export interface CommandOptions {
     pattern: string | RegExp;
     documentation?: CommandDocumentation;
     auth?: boolean;
+    allowDM?: boolean;
 }
 
 export interface CommandDocumentation {

+ 2 - 0
bot/src/plugin_manager.ts

@@ -128,6 +128,8 @@ export class PluginManager {
             }
 
             if (match) {
+                if (!c.allowDM && m.channel.type == "dm")
+                    return false;
                 if (c.auth && !(await isAuthorisedAsync(m.member)))
                     return false;
                 const eventResult = c.action({ message: m, contents: matchData });