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

Diff of /trunk/src/App.js

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

revision 5 by rakin, Mon Jul 29 17:28:11 2024 UTC revision 20 by rakin, Mon Jul 29 17:28:14 2024 UTC
# Line 7  const Config = require("./Config"); Line 7  const Config = require("./Config");
7  const Database = require("./Database");  const Database = require("./Database");
8  const Logger = require("./Logger");  const Logger = require("./Logger");
9  const SpamFilter = require("./SpamFilter");  const SpamFilter = require("./SpamFilter");
10    const server = require("./server");
11    const AntiRaid = require("./AntiRaid");
12    
13  class App {  class App {
14      constructor(rootdir) {      constructor(rootdir) {
15          global.app = App.app = this;          global.app = App.app = this;
16          this.rootdir = rootdir;          this.rootdir = rootdir;
17          this.loadConfig();          this.loadConfig();
18            this.env = process.env;
19    
20          this.client = new Client({          this.client = new Client({
21              partials: ["CHANNEL"],              partials: ["CHANNEL"],
# Line 20  class App { Line 23  class App {
23                  Intents.FLAGS.GUILDS,                  Intents.FLAGS.GUILDS,
24                  Intents.FLAGS.GUILD_MESSAGES,                  Intents.FLAGS.GUILD_MESSAGES,
25                  Intents.FLAGS.DIRECT_MESSAGES,                  Intents.FLAGS.DIRECT_MESSAGES,
26                  Intents.FLAGS.DIRECT_MESSAGE_TYPING                  Intents.FLAGS.DIRECT_MESSAGE_TYPING,
27                    Intents.FLAGS.GUILD_PRESENCES,
28                    Intents.FLAGS.GUILD_MEMBERS,
29              ]              ]
30          });          });
31    
# Line 29  class App { Line 34  class App {
34          this.commandManager = new CommandManager(path.resolve(__dirname, rootdir, "commands"));          this.commandManager = new CommandManager(path.resolve(__dirname, rootdir, "commands"));
35          this.logger = new Logger();          this.logger = new Logger();
36          this.spamFilter = new SpamFilter();          this.spamFilter = new SpamFilter();
37            this.antiRaid = new AntiRaid();
38          this.boot();          this.boot();
39      }      }
40    
41      boot() {      boot() {
42          this.on('ready', () => {          this.on('ready', () => {
43              console.log("Logged in as " + this.client.user.tag);              console.log("Logged in as " + this.client.user.tag);
44                server();
45          });          });
46    
47          this.on('messageCreate', async (message) => {          this.on('messageCreate', async (message) => {
48              if (message.author.bot) {              if (message.author.bot || !message.guild || message.channel.type == 'dm') {
49                  return;                  return;
50              }              }
51    
52              await (this.msg = message);              await (this.msg = message);
53                            
54              //await this.spamFilter.start(message);              await this.spamFilter.start(message);
55    
56              await this.commandManager.setMessage(message);              await this.commandManager.setMessage(message);
57    
58              const valid = await this.commandManager.valid();              const valid = await this.commandManager.valid();
59              const has = await this.commandManager.has();              const has = await this.commandManager.has();
60              const snippet = await this.commandManager.snippet();              const snippet = await this.commandManager.snippet();
61                const allowed = await this.commandManager.verify();
62                            
63              if (valid && has) {              if (valid && has && allowed) {
64                  await this.exec();                  await this.exec();
65              }              }
66              else if (valid && snippet !== undefined) {              else if (valid && snippet !== undefined) {
# Line 63  class App { Line 71  class App {
71              else if (valid && !has) {              else if (valid && !has) {
72                  await this.commandManager.notFound();                  await this.commandManager.notFound();
73              }              }
74                else if (valid && has && !allowed) {
75                    await this.commandManager.notAllowed();
76                }
77          });          });
78    
79          this.on("messageUpdate", async (oldMessage, newMessage) => {          this.on("messageUpdate", async (oldMessage, newMessage) => {
# Line 95  class App { Line 106  class App {
106              delete this.config.props[guild.id];              delete this.config.props[guild.id];
107              this.config.write();              this.config.write();
108          })          })
109    
110            this.on('guildMemberAdd', async (member) => {
111                console.log('Joined');
112                await this.antiRaid.start(member);
113            });
114      }      }
115    
116      loadConfig() {      loadConfig() {
# Line 115  class App { Line 131  class App {
131      run() {      run() {
132          this.client.login(process.env.TOKEN);          this.client.login(process.env.TOKEN);
133      }      }
134    
135        tempFileCreate(name) {
136            const fullname = path.join(__dirname, '..', 'tmp', name);
137            const file = fs.createWriteStream(fullname);
138    
139            return {
140                name: fullname,
141                file
142            };
143        }
144  }  }
145    
146  module.exports = App;  module.exports = App;

Legend:
Removed from v.5  
changed lines
  Added in v.20

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26