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) { |
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 |
|
|
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.guild || oldMessage.channel.type == 'dm' || oldMessage.content === newMessage.content) |
127 |
return; |
return; |
128 |
|
|
129 |
|
let msg = await this.msg; |
130 |
|
await (this.msg = newMessage); |
131 |
|
|
132 |
|
await this.spamFilter.basic(newMessage); |
133 |
|
await this.messageFilter.start(newMessage, this.commandManager); |
134 |
|
|
135 |
await this.logger.logEdit(oldMessage, newMessage); |
await this.logger.logEdit(oldMessage, newMessage); |
136 |
|
await (this.msg = msg); |
137 |
|
}); |
138 |
|
|
139 |
|
this.on("messageReactionAdd", async (reaction, message) => { |
140 |
|
console.log('inside'); |
141 |
|
|
142 |
|
if (!reaction || !reaction.message || !message.guild || message.channel.type == 'dm') { |
143 |
|
return; |
144 |
|
} |
145 |
|
|
146 |
|
await (this.msg = reaction.message); |
147 |
|
await this.starboard.handle(reaction, message); |
148 |
|
}); |
149 |
|
|
150 |
|
this.on('guildBanAdd', async (ban) => { |
151 |
|
console.log('test'); |
152 |
|
await this.logger.logBanned(ban); |
153 |
|
}); |
154 |
|
|
155 |
|
this.on('guildBanRemove', async (ban) => { |
156 |
|
console.log('test'); |
157 |
|
await this.logger.logUnbanned(ban); |
158 |
}); |
}); |
159 |
|
|
160 |
this.on("messageDelete", async (message) => { |
this.on("messageDelete", async (message) => { |
161 |
if (message.author.bot) |
if (message.author.bot || !message.guild || message.channel.type == 'dm') |
162 |
return; |
return; |
163 |
|
|
164 |
await this.logger.logDelete(message); |
await this.logger.logDelete(message); |
184 |
this.on('guildMemberAdd', async (member) => { |
this.on('guildMemberAdd', async (member) => { |
185 |
console.log('Joined'); |
console.log('Joined'); |
186 |
await this.antiRaid.start(member); |
await this.antiRaid.start(member); |
187 |
|
await this.logger.logJoined(member); |
188 |
|
}); |
189 |
|
|
190 |
|
this.on('guildMemberRemove', async (member) => { |
191 |
|
await this.logger.logLeft(member); |
192 |
}); |
}); |
193 |
} |
} |
194 |
|
|