/[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 23 by rakin, Mon Jul 29 17:28:15 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    const MessageFilter = require("./MessageFilter");
13    const { random } = require("../commands/pixabay");
14    
15  class App {  class App {
16      constructor(rootdir) {      constructor(rootdir) {
17          global.app = App.app = this;          global.app = App.app = this;
18          this.rootdir = rootdir;          this.rootdir = rootdir;
19          this.loadConfig();          this.loadConfig();
20            this.env = process.env;
21    
22          this.client = new Client({          this.client = new Client({
23              partials: ["CHANNEL"],              partials: ["CHANNEL"],
# Line 20  class App { Line 25  class App {
25                  Intents.FLAGS.GUILDS,                  Intents.FLAGS.GUILDS,
26                  Intents.FLAGS.GUILD_MESSAGES,                  Intents.FLAGS.GUILD_MESSAGES,
27                  Intents.FLAGS.DIRECT_MESSAGES,                  Intents.FLAGS.DIRECT_MESSAGES,
28                  Intents.FLAGS.DIRECT_MESSAGE_TYPING                  Intents.FLAGS.DIRECT_MESSAGE_TYPING,
29                    Intents.FLAGS.GUILD_PRESENCES,
30                    Intents.FLAGS.GUILD_MEMBERS,
31              ]              ]
32          });          });
33    
# Line 29  class App { Line 36  class App {
36          this.commandManager = new CommandManager(path.resolve(__dirname, rootdir, "commands"));          this.commandManager = new CommandManager(path.resolve(__dirname, rootdir, "commands"));
37          this.logger = new Logger();          this.logger = new Logger();
38          this.spamFilter = new SpamFilter();          this.spamFilter = new SpamFilter();
39            this.antiRaid = new AntiRaid();
40            this.messageFilter = new MessageFilter();
41          this.boot();          this.boot();
42      }      }
43    
44      boot() {      boot() {
45          this.on('ready', () => {          this.on('ready', () => {
46              console.log("Logged in as " + this.client.user.tag);              console.log("Logged in as " + this.client.user.tag);
47    
48                this.client.user.setStatus(random(['dnd', 'idle']));
49                this.client.user.setActivity("over the server", { type: "WATCHING" });
50    
51                server();
52          });          });
53    
54          this.on('messageCreate', async (message) => {          this.on('messageCreate', async (message) => {
55              if (message.author.bot) {              if (message.author.bot || !message.guild || message.channel.type == 'dm') {
56                  return;                  return;
57              }              }
58    
59              await (this.msg = message);              await (this.msg = message);
60                            
61              //await this.spamFilter.start(message);              await this.spamFilter.start(message);
62                await this.messageFilter.start(message, this.commandManager);
63    
64              await this.commandManager.setMessage(message);              await this.commandManager.setMessage(message);
65    
66              const valid = await this.commandManager.valid();              const valid = await this.commandManager.valid();
67              const has = await this.commandManager.has();              const has = await this.commandManager.has();
68              const snippet = await this.commandManager.snippet();              const snippet = await this.commandManager.snippet();
69                const allowed = await this.commandManager.verify();
70                            
71              if (valid && has) {              if (valid && has && allowed) {
72                  await this.exec();                  await this.exec();
73              }              }
74              else if (valid && snippet !== undefined) {              else if (valid && snippet !== undefined) {
# Line 63  class App { Line 79  class App {
79              else if (valid && !has) {              else if (valid && !has) {
80                  await this.commandManager.notFound();                  await this.commandManager.notFound();
81              }              }
82                else if (valid && has && !allowed) {
83                    await this.commandManager.notAllowed();
84                }
85          });          });
86    
87          this.on("messageUpdate", async (oldMessage, newMessage) => {          this.on("messageUpdate", async (oldMessage, newMessage) => {
# Line 95  class App { Line 114  class App {
114              delete this.config.props[guild.id];              delete this.config.props[guild.id];
115              this.config.write();              this.config.write();
116          })          })
117    
118            this.on('guildMemberAdd', async (member) => {
119                console.log('Joined');
120                await this.antiRaid.start(member);
121            });
122      }      }
123    
124      loadConfig() {      loadConfig() {
# Line 115  class App { Line 139  class App {
139      run() {      run() {
140          this.client.login(process.env.TOKEN);          this.client.login(process.env.TOKEN);
141      }      }
142    
143        tempFileCreate(name) {
144            const fullname = path.join(__dirname, '..', 'tmp', name);
145            const file = fs.createWriteStream(fullname);
146    
147            return {
148                name: fullname,
149                file
150            };
151        }
152  }  }
153    
154  module.exports = App;  module.exports = App;

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26