Browse Source

Add docs for prefix commands

ghorsington 4 years ago
parent
commit
0770b535f6
4 changed files with 22 additions and 7 deletions
  1. 1 1
      bot/src/main.ts
  2. 2 0
      bot/src/plugin_manager.ts
  3. 9 4
      bot/src/plugins/help.ts
  4. 10 2
      bot/src/plugins/violation.ts

+ 1 - 1
bot/src/main.ts

@@ -11,7 +11,7 @@ import { logger } from "./logging";
 import { PluginManager } from "./plugin_manager";
 
 export const plgMgr: PluginManager = new PluginManager(path.resolve(path.dirname(module.filename), "plugins"));
-const COMMAND_PREFIX = "/";
+export const COMMAND_PREFIX = "/";
 
 client.bot.on("ready", async () => {
     logger.info("Starting up NoctBot");

+ 2 - 0
bot/src/plugin_manager.ts

@@ -6,6 +6,7 @@ import { isAuthorisedAsync } from "./util";
 
 
 interface IDocumentationData {
+    type: CommandType;
     name: string;
     doc?: string;
     example?: string;
@@ -67,6 +68,7 @@ export class PluginManager {
 
     get documentation(): IDocumentationData[] {
         return this.commands.filter(m => m.documentation !== undefined).map(m => ({
+            type: m.type,
             name: m.pattern.toString(),
             doc: m.documentation?.description,
             example: m.documentation?.example,

+ 9 - 4
bot/src/plugins/help.ts

@@ -1,5 +1,5 @@
 import { isAuthorisedAsync } from "../util";
-import { plgMgr } from "src/main";
+import { plgMgr, COMMAND_PREFIX } from "src/main";
 import { Command, ICommandData, Plugin } from "src/model/plugin";
 import { client } from "src/client";
 
@@ -14,10 +14,15 @@ export class Help {
 
         let baseCommands = "\n";
         let modCommands = "\n";
+        let prefixCommands = "\n";
         
         for (const doc of plgMgr.documentation) {
-            if (isAuthed && doc.auth)
-                modCommands = `${modCommands}${doc.example}  -  ${doc.doc}\n`;
+            if (isAuthed && doc.auth) {
+                if (doc.type == "prefix") 
+                    prefixCommands = `${prefixCommands}${COMMAND_PREFIX}${doc.example}  -  ${doc.doc}\n`;
+                else if (doc.type == "mention")
+                    modCommands = `${modCommands}${doc.example}  -  ${doc.doc}\n`;
+            }
             else if (!doc.auth)
                 baseCommands = `${baseCommands}${doc.example} - ${doc.doc}\n`;
         }
@@ -25,7 +30,7 @@ export class Help {
         let msg = `Hello! I am ${client.botUser.username}! My job is to help with C(O)M-related problems!\nPing me with one of the following commands:\n\`\`\`${baseCommands}\`\`\``;
 
         if (isAuthed)
-            msg = `${msg}\n👑**Moderator commands**👑\n\`\`\`${modCommands}\`\`\``;
+            msg = `${msg}\n👑**Moderator commands**👑\n\`\`\`${modCommands}\`\`\`\n**Prefix commands**\`\`\`${prefixCommands}\`\`\``;
 
         message.reply(msg);
     }

+ 10 - 2
bot/src/plugins/violation.ts

@@ -137,7 +137,11 @@ export class ViolationPlugin {
     @Command({
         type: "prefix",
         pattern: "mute",
-        auth: true
+        auth: true,
+        documentation: {
+            example: "mute[?!] <user> [<duration>] [<reason>]",
+            description: "Mutes for a given duration and reason. ? = dry run, ! = no announcement"
+        }
     })
     async muteUser({ message }: ICommandData): Promise<void> {
         const info = await this.parseCommand(message);
@@ -157,7 +161,11 @@ export class ViolationPlugin {
     @Command({
         type: "prefix",
         pattern: "unmute",
-        auth: true
+        auth: true,
+        documentation: {
+            example: "unmute <user>",
+            description: "Unmutes user"
+        }
     })
     async unmuteUser({ message }: ICommandData): Promise<void> {
         await this.removeTimedViolation(Mute, message, "mute");