/[sudobot]/trunk/src/CommandManager.js
ViewVC logotype

Diff of /trunk/src/CommandManager.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 7 by rakin, Mon Jul 29 17:28:12 2024 UTC revision 46 by rakin, Mon Jul 29 17:28:21 2024 UTC
# Line 2  const fs = require("fs"); Line 2  const fs = require("fs");
2  const path = require("path");  const path = require("path");
3  const MessageEmbed = require("./MessageEmbed");  const MessageEmbed = require("./MessageEmbed");
4  const SnippetManager = require("./SnippetManager");  const SnippetManager = require("./SnippetManager");
5    const Shield = require("./Shield");
6  const { escapeRegex } = require("./util");  const { escapeRegex } = require("./util");
7    
8  class CommandManager {  class CommandManager {
9      constructor(cmdDir) {      constructor(cmdDir, loadCommands = true, loadSnippets = true) {
10          this.msg = null;          this.msg = null;
11          this.commandsDirectory = cmdDir;          this.commandsDirectory = cmdDir;
12          this.commands = [];          this.commands = [];
# Line 14  class CommandManager { Line 15  class CommandManager {
15          this.args = [];          this.args = [];
16          this.options = [];          this.options = [];
17          this.normalArgs = [];          this.normalArgs = [];
18          this.loadCommands();  
19          this.snippetManager = new SnippetManager();          if (loadCommands)
20                this.loadCommands();
21            
22            if (loadSnippets)
23                this.snippetManager = new SnippetManager();
24            
25            this.shield = new Shield();
26      }      }
27    
28      setMessage(msg) {      setMessage(msg) {
29          this.msg = msg;          this.msg = msg;
30          this.argv = msg.content.split(/ +/g);          this.argv = msg.content.split(/ +/g);
31          this.args = this.argv;          this.args = this.argv;
32          this.commandName = this.args.shift().trim().replace(new RegExp(`^${escapeRegex(app.config.get('prefix'))}`), "");          this.commandName = this.args.shift().trim().replace(new RegExp(`^${escapeRegex(app.config.props[msg.guild.id].prefix)}`), "");
33      }      }
34    
35      loadCommands() {      loadCommands() {
# Line 44  class CommandManager { Line 51  class CommandManager {
51      }      }
52    
53      snippet() {      snippet() {
54          return this.snippetManager.find(this.commandName);          return this.snippetManager.find(this.msg.guild.id, this.commandName);
55      }      }
56    
57      hasValid() {      hasValid() {
# Line 52  class CommandManager { Line 59  class CommandManager {
59      }      }
60    
61      valid() {      valid() {
62          return this.msg.content.startsWith(app.config.get('prefix'));          return this.msg.content.startsWith(app.config.props[this.msg.guild.id].prefix);
63      }      }
64    
65      async notFound() {      async notFound() {
# Line 67  class CommandManager { Line 74  class CommandManager {
74          }          }
75      }      }
76    
77        async notAllowed() {
78            if (app.config.get('warn_notallowed')) {
79                await app.msg.reply({
80                    embeds: [
81                        new MessageEmbed()
82                        .setColor('#f14a60')
83                        .setDescription(`:x: You don't have permission to run this command.`)
84                    ]
85                });
86            }
87        }
88    
89      async exec() {      async exec() {
90          let cmd = this.commands[this.commandName];          let cmd = this.commands[this.commandName];
91    
# Line 77  class CommandManager { Line 96  class CommandManager {
96    
97          return await cmd.handle(this.msg, this);          return await cmd.handle(this.msg, this);
98      }      }
99    
100        verify() {
101            return this.shield.verify(this.msg, this);
102        }
103  }  }
104    
105  module.exports = CommandManager;  module.exports = CommandManager;

Legend:
Removed from v.7  
changed lines
  Added in v.46

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26