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

Legend:
Removed from v.11  
changed lines
  Added in v.49

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26