/[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 27 by rakin, Mon Jul 29 17:28:16 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    const AFKEngine = require("./AFKEngine");
15    
16  class App {  class App {
17      constructor(rootdir) {      constructor(rootdir) {
18          global.app = App.app = this;          global.app = App.app = this;
19          this.rootdir = rootdir;          this.rootdir = rootdir;
20          this.loadConfig();          this.loadConfig();
21            this.env = process.env;
22    
23          this.client = new Client({          this.client = new Client({
24              partials: ["CHANNEL"],              partials: ["CHANNEL"],
# Line 20  class App { Line 26  class App {
26                  Intents.FLAGS.GUILDS,                  Intents.FLAGS.GUILDS,
27                  Intents.FLAGS.GUILD_MESSAGES,                  Intents.FLAGS.GUILD_MESSAGES,
28                  Intents.FLAGS.DIRECT_MESSAGES,                  Intents.FLAGS.DIRECT_MESSAGES,
29                  Intents.FLAGS.DIRECT_MESSAGE_TYPING                  Intents.FLAGS.DIRECT_MESSAGE_TYPING,
30                    Intents.FLAGS.GUILD_PRESENCES,
31                    Intents.FLAGS.GUILD_MEMBERS,
32                    Intents.FLAGS.GUILD_BANS
33              ]              ]
34          });          });
35    
# Line 29  class App { Line 38  class App {
38          this.commandManager = new CommandManager(path.resolve(__dirname, rootdir, "commands"));          this.commandManager = new CommandManager(path.resolve(__dirname, rootdir, "commands"));
39          this.logger = new Logger();          this.logger = new Logger();
40          this.spamFilter = new SpamFilter();          this.spamFilter = new SpamFilter();
41            this.antiRaid = new AntiRaid();
42            this.messageFilter = new MessageFilter();
43            this.afkEngine = new AFKEngine();
44          this.boot();          this.boot();
45      }      }
46    
47      boot() {      boot() {
48          this.on('ready', () => {          this.on('ready', () => {
49              console.log("Logged in as " + this.client.user.tag);              console.log("Logged in as " + this.client.user.tag);
50    
51                this.client.user.setStatus(random(['dnd', 'idle']));
52                this.client.user.setActivity("over the server", { type: "WATCHING" });
53    
54                server();
55          });          });
56    
57          this.on('messageCreate', async (message) => {          this.on('messageCreate', async (message) => {
58              if (message.author.bot) {              if (message.author.bot || !message.guild || message.channel.type == 'dm') {
59                  return;                  return;
60              }              }
61    
62              await (this.msg = message);              await (this.msg = message);
63                            
64              //await this.spamFilter.start(message);              await this.spamFilter.start(message);
65                await this.messageFilter.start(message, this.commandManager);
66    
67              await this.commandManager.setMessage(message);              await this.commandManager.setMessage(message);
68    
69              const valid = await this.commandManager.valid();              const valid = await this.commandManager.valid();
70              const has = await this.commandManager.has();              const has = await this.commandManager.has();
71              const snippet = await this.commandManager.snippet();              const snippet = await this.commandManager.snippet();
72                const allowed = await this.commandManager.verify();
73                            
74              if (valid && has) {              if (valid && has && allowed) {
75                  await this.exec();                  await this.exec();
76              }              }
77              else if (valid && snippet !== undefined) {              else if (valid && snippet !== undefined) {
78                  await message.channel.send({                  await message.channel.send({
79                      content: snippet.content                      content: snippet.content,
80                        files: snippet.files.map(f => {
81                            return {
82                                attachment: path.resolve(__dirname, '..', 'storage', f)
83                            }
84                        })
85                  });                  });
86              }              }
87              else if (valid && !has) {              else if (valid && !has) {
88                  await this.commandManager.notFound();                  await this.commandManager.notFound();
89              }              }
90                else if (valid && has && !allowed) {
91                    await this.commandManager.notAllowed();
92                }
93                else if(!valid) {
94                    await this.afkEngine.start(message);
95                }
96          });          });
97    
98          this.on("messageUpdate", async (oldMessage, newMessage) => {          this.on("messageUpdate", async (oldMessage, newMessage) => {
99              if (oldMessage.author.bot)              if (oldMessage.author.bot || oldMessage.content === newMessage.content)
100                  return;                  return;
101    
102              await this.logger.logEdit(oldMessage, newMessage);              await this.logger.logEdit(oldMessage, newMessage);
103          });          });
104    
105    
106            this.on('guildBanAdd', async (ban) => {
107                console.log('test');
108                await this.logger.logBanned(ban);
109            });
110    
111            this.on('guildBanRemove', async (ban) => {
112                console.log('test');
113                await this.logger.logUnbanned(ban);
114            });
115    
116          this.on("messageDelete", async (message) => {          this.on("messageDelete", async (message) => {
117              if (message.author.bot)              if (message.author.bot)
118                  return;                  return;
# Line 95  class App { Line 136  class App {
136              delete this.config.props[guild.id];              delete this.config.props[guild.id];
137              this.config.write();              this.config.write();
138          })          })
139    
140            this.on('guildMemberAdd', async (member) => {
141                console.log('Joined');
142                await this.antiRaid.start(member);
143                await this.logger.logJoined(member);
144            });
145    
146            this.on('guildMemberRemove', async (member) => {
147                await this.logger.logLeft(member);
148            });
149      }      }
150    
151      loadConfig() {      loadConfig() {
# Line 115  class App { Line 166  class App {
166      run() {      run() {
167          this.client.login(process.env.TOKEN);          this.client.login(process.env.TOKEN);
168      }      }
169    
170        tempFileCreate(name) {
171            const fullname = path.join(__dirname, '..', 'tmp', name);
172            const file = fs.createWriteStream(fullname);
173    
174            return {
175                name: fullname,
176                file
177            };
178        }
179  }  }
180    
181  module.exports = App;  module.exports = App;

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26