/[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 10 by rakin, Mon Jul 29 17:28:12 2024 UTC revision 33 by rakin, Mon Jul 29 17:28:17 2024 UTC
# Line 9  const Logger = require("./Logger"); Line 9  const Logger = require("./Logger");
9  const SpamFilter = require("./SpamFilter");  const SpamFilter = require("./SpamFilter");
10  const server = require("./server");  const server = require("./server");
11  const AntiRaid = require("./AntiRaid");  const AntiRaid = require("./AntiRaid");
12    const MessageFilter = require("./MessageFilter");
13    const { random } = require("../commands/pixabay");
14    const AFKEngine = require("./AFKEngine");
15    const Starboard = require("./Starboard");
16    
17  class App {  class App {
18      constructor(rootdir) {      constructor(rootdir) {
# Line 26  class App { Line 30  class App {
30                  Intents.FLAGS.DIRECT_MESSAGE_TYPING,                  Intents.FLAGS.DIRECT_MESSAGE_TYPING,
31                  Intents.FLAGS.GUILD_PRESENCES,                  Intents.FLAGS.GUILD_PRESENCES,
32                  Intents.FLAGS.GUILD_MEMBERS,                  Intents.FLAGS.GUILD_MEMBERS,
33                    Intents.FLAGS.GUILD_BANS,
34                    Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
35                    Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
36              ]              ]
37          });          });
38    
# Line 35  class App { Line 42  class App {
42          this.logger = new Logger();          this.logger = new Logger();
43          this.spamFilter = new SpamFilter();          this.spamFilter = new SpamFilter();
44          this.antiRaid = new AntiRaid();          this.antiRaid = new AntiRaid();
45            this.messageFilter = new MessageFilter();
46            this.afkEngine = new AFKEngine();
47            this.starboard = new Starboard();
48          this.boot();          this.boot();
49      }      }
50    
51      boot() {      boot() {
52            const events = {
53                MESSAGE_REACTION_ADD: 'messageReactionAdd',
54            };
55            
56          this.on('ready', () => {          this.on('ready', () => {
57              console.log("Logged in as " + this.client.user.tag);              console.log("Logged in as " + this.client.user.tag);
58    
59                this.client.user.setStatus(random(['dnd', 'idle']));
60                this.client.user.setActivity("over the server", { type: "WATCHING" });
61    
62              server();              server();
63          });          });
64    
65            this.on('raw', async event => {
66                if (!events.hasOwnProperty(event.t))
67                    return;
68            
69                const { d: data } = event;
70                const user = this.client.users.cache.find(i => i.id === data.user_id);
71                const channel = this.client.channels.cache.find(i => i.id === data.channel_id) || await user.createDM();
72            
73                if (channel.messages.cache.has(data.message_id))
74                    return;
75            
76                const message = await channel.messages.fetch(data.message_id);
77            
78                const emojiKey = (data.emoji.id) ? `${data.emoji.name}:${data.emoji.id}` : data.emoji.name;
79                const reaction = message.reactions.cache.get(emojiKey);
80            
81                this.client.emit(events[event.t], reaction, user);
82            });
83    
84          this.on('messageCreate', async (message) => {          this.on('messageCreate', async (message) => {
85              if (message.author.bot) {              if (message.author.bot || !message.guild || message.channel.type == 'dm') {
86                  return;                  return;
87              }              }
88    
89              await (this.msg = message);              await (this.msg = message);
90                            
91             // await this.spamFilter.start(message);              await this.spamFilter.start(message);
92                await this.messageFilter.start(message, this.commandManager);
93    
94              await this.commandManager.setMessage(message);              await this.commandManager.setMessage(message);
95    
96              const valid = await this.commandManager.valid();              const valid = await this.commandManager.valid();
97              const has = await this.commandManager.has();              const has = await this.commandManager.has();
98              const snippet = await this.commandManager.snippet();              const snippet = await this.commandManager.snippet();
99                const allowed = await this.commandManager.verify();
100                            
101              if (valid && has) {              if (valid && has && allowed) {
102                  await this.exec();                  await this.exec();
103              }              }
104              else if (valid && snippet !== undefined) {              else if (valid && snippet !== undefined) {
105                  await message.channel.send({                  await message.channel.send({
106                      content: snippet.content                      content: snippet.content,
107                        files: snippet.files.map(f => {
108                            return {
109                                attachment: path.resolve(__dirname, '..', 'storage', f)
110                            }
111                        })
112                  });                  });
113              }              }
114              else if (valid && !has) {              else if (valid && !has) {
115                  await this.commandManager.notFound();                  await this.commandManager.notFound();
116              }              }
117                else if (valid && has && !allowed) {
118                    await this.commandManager.notAllowed();
119                }
120                else if(!valid) {
121                    await this.afkEngine.start(message);
122                }
123          });          });
124    
125          this.on("messageUpdate", async (oldMessage, newMessage) => {          this.on("messageUpdate", async (oldMessage, newMessage) => {
126              if (oldMessage.author.bot)              if (oldMessage.author.bot || oldMessage.content === newMessage.content)
127                  return;                  return;
128    
129              await this.logger.logEdit(oldMessage, newMessage);              await this.logger.logEdit(oldMessage, newMessage);
130          });          });
131    
132            this.on("messageReactionAdd", async (reaction, message) => {
133                console.log('inside');
134    
135                if (!reaction || !reaction.message) {
136                    return;
137                }
138                
139                await (this.msg = reaction.message);
140                await this.starboard.handle(reaction, message);
141            });
142    
143            this.on('guildBanAdd', async (ban) => {
144                console.log('test');
145                await this.logger.logBanned(ban);
146            });
147    
148            this.on('guildBanRemove', async (ban) => {
149                console.log('test');
150                await this.logger.logUnbanned(ban);
151            });
152    
153          this.on("messageDelete", async (message) => {          this.on("messageDelete", async (message) => {
154              if (message.author.bot)              if (message.author.bot)
155                  return;                  return;
# Line 106  class App { Line 177  class App {
177          this.on('guildMemberAdd', async (member) => {          this.on('guildMemberAdd', async (member) => {
178              console.log('Joined');              console.log('Joined');
179              await this.antiRaid.start(member);              await this.antiRaid.start(member);
180                await this.logger.logJoined(member);
181            });
182    
183            this.on('guildMemberRemove', async (member) => {
184                await this.logger.logLeft(member);
185          });          });
186      }      }
187    

Legend:
Removed from v.10  
changed lines
  Added in v.33

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26