فهرست منبع

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 });