Explorar el Código

Skip running command on unauthorised user

ghorsington hace 4 años
padre
commit
ff8adac9b5
Se han modificado 1 ficheros con 7 adiciones y 9 borrados
  1. 7 9
      bot/src/plugin_manager.ts

+ 7 - 9
bot/src/plugin_manager.ts

@@ -2,6 +2,7 @@ import path from "path";
 import fs from "fs";
 import { Message, Client, ClientEvents } from "discord.js";
 import { EventType, BotEvent, ICommand, isPlugin, BotEventData, isCustomEvent, IPlugin } from "./model/plugin";
+import { isAuthorisedAsync } from "./util";
 
 
 interface IDocumentationData {
@@ -109,26 +110,23 @@ export class PluginManager {
         const lowerCaseContent = content.toLowerCase();
         for (const c of this.commands) {
             let match = false;
-            let eventResult: void | Promise<void> = undefined;
+            let matchData: string | RegExpMatchArray = "";
             if (typeof (c.pattern) == "string" && lowerCaseContent.startsWith(c.pattern)) {
                 match = true;
-                eventResult = c.action({
-                    message: m,
-                    contents: content
-                });
+                matchData = c.pattern;
             }
             else if (c.pattern instanceof RegExp) {
                 const result = c.pattern.exec(content);
                 if (result != null) {
                     match = true;
-                    eventResult = c.action({
-                        message: m,
-                        contents: result
-                    });
+                    matchData = result;
                 }
             }
 
             if (match) {
+                if (c.auth && !(await isAuthorisedAsync(m.member)))
+                    return false;
+                const eventResult = c.action({ message: m, contents: matchData });
                 if (eventResult instanceof Promise)
                     await eventResult;
                 return true;