/[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 20 by rakin, Mon Jul 29 17:28:14 2024 UTC revision 45 by rakin, Mon Jul 29 17:28:20 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    const { runTimeouts, setTimeoutv2 } = require("./setTimeout");
17    
18  class App {  class App {
19      constructor(rootdir) {      constructor(rootdir) {
# Line 26  class App { Line 31  class App {
31                  Intents.FLAGS.DIRECT_MESSAGE_TYPING,                  Intents.FLAGS.DIRECT_MESSAGE_TYPING,
32                  Intents.FLAGS.GUILD_PRESENCES,                  Intents.FLAGS.GUILD_PRESENCES,
33                  Intents.FLAGS.GUILD_MEMBERS,                  Intents.FLAGS.GUILD_MEMBERS,
34                    Intents.FLAGS.GUILD_BANS,
35                    Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
36                    Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS,
37              ]              ]
38          });          });
39    
# Line 35  class App { Line 43  class App {
43          this.logger = new Logger();          this.logger = new Logger();
44          this.spamFilter = new SpamFilter();          this.spamFilter = new SpamFilter();
45          this.antiRaid = new AntiRaid();          this.antiRaid = new AntiRaid();
46            this.messageFilter = new MessageFilter();
47            this.afkEngine = new AFKEngine();
48            this.starboard = new Starboard();
49          this.boot();          this.boot();
50      }      }
51    
52      boot() {      boot() {
53            const events = {
54                MESSAGE_REACTION_ADD: 'messageReactionAdd',
55            };
56            
57          this.on('ready', () => {          this.on('ready', () => {
58              console.log("Logged in as " + this.client.user.tag);              console.log("Logged in as " + this.client.user.tag);
59    
60                this.client.user.setStatus(random(['dnd', 'idle']));
61                this.client.user.setActivity("over the server", { type: "WATCHING" });
62    
63              server();              server();
64                
65                runTimeouts();
66    
67                // setTimeoutv2(path.resolve(__dirname, '../queues/send.js'), 10000, "Hello world");
68            });
69    
70            this.on('raw', async event => {
71                if (!events.hasOwnProperty(event.t))
72                    return;
73            
74                const { d: data } = event;
75                const user = this.client.users.cache.find(i => i.id === data.user_id);
76                const channel = this.client.channels.cache.find(i => i.id === data.channel_id) || await user.createDM();
77            
78                if (channel.messages.cache.has(data.message_id))
79                    return;
80            
81                const message = await channel.messages.fetch(data.message_id);
82            
83                const emojiKey = (data.emoji.id) ? `${data.emoji.name}:${data.emoji.id}` : data.emoji.name;
84                const reaction = message.reactions.cache.get(emojiKey);
85            
86                this.client.emit(events[event.t], reaction, user);
87          });          });
88    
89          this.on('messageCreate', async (message) => {          this.on('messageCreate', async (message) => {
# Line 52  class App { Line 94  class App {
94              await (this.msg = message);              await (this.msg = message);
95                            
96              await this.spamFilter.start(message);              await this.spamFilter.start(message);
97                await this.messageFilter.start(message, this.commandManager);
98    
99              await this.commandManager.setMessage(message);              await this.commandManager.setMessage(message);
100    
# Line 65  class App { Line 108  class App {
108              }              }
109              else if (valid && snippet !== undefined) {              else if (valid && snippet !== undefined) {
110                  await message.channel.send({                  await message.channel.send({
111                      content: snippet.content                      content: snippet.content,
112                        files: snippet.files.map(f => {
113                            return {
114                                attachment: path.resolve(__dirname, '..', 'storage', f)
115                            }
116                        })
117                  });                  });
118              }              }
119              else if (valid && !has) {              else if (valid && !has) {
# Line 74  class App { Line 122  class App {
122              else if (valid && has && !allowed) {              else if (valid && has && !allowed) {
123                  await this.commandManager.notAllowed();                  await this.commandManager.notAllowed();
124              }              }
125                else if(!valid) {
126                    await this.afkEngine.start(message);
127                }
128          });          });
129    
130          this.on("messageUpdate", async (oldMessage, newMessage) => {          this.on("messageUpdate", async (oldMessage, newMessage) => {
131              if (oldMessage.author.bot)              if (oldMessage.author.bot || !oldMessage.guild || oldMessage.channel.type == 'dm' || oldMessage.content === newMessage.content)
132                  return;                  return;
133    
134                let msg = await this.msg;
135                await (this.msg = newMessage);
136            
137                await this.spamFilter.basic(newMessage);
138                await this.messageFilter.start(newMessage, this.commandManager);
139    
140              await this.logger.logEdit(oldMessage, newMessage);              await this.logger.logEdit(oldMessage, newMessage);
141                await (this.msg = msg);
142            });
143    
144            this.on("messageReactionAdd", async (reaction, message) => {
145                console.log('inside');
146    
147                if (!reaction || !reaction.message || !message.guild || message.channel.type == 'dm') {
148                    return;
149                }
150                
151                await (this.msg = reaction.message);
152                await this.starboard.handle(reaction, message);
153            });
154    
155            this.on('guildBanAdd', async (ban) => {
156                console.log('test');
157                await this.logger.logBanned(ban);
158            });
159    
160            this.on('guildBanRemove', async (ban) => {
161                console.log('test');
162                await this.logger.logUnbanned(ban);
163          });          });
164    
165          this.on("messageDelete", async (message) => {          this.on("messageDelete", async (message) => {
166              if (message.author.bot)              if (message.author.bot || !message.guild || message.channel.type == 'dm')
167                  return;                  return;
168    
169              await this.logger.logDelete(message);              await this.logger.logDelete(message);
# Line 110  class App { Line 189  class App {
189          this.on('guildMemberAdd', async (member) => {          this.on('guildMemberAdd', async (member) => {
190              console.log('Joined');              console.log('Joined');
191              await this.antiRaid.start(member);              await this.antiRaid.start(member);
192                await this.logger.logJoined(member);
193            });
194    
195            this.on('guildMemberRemove', async (member) => {
196                await this.logger.logLeft(member);
197          });          });
198      }      }
199    

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26