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 |
|
|
15 |
class App { |
class App { |
16 |
constructor(rootdir) { |
constructor(rootdir) { |
17 |
global.app = App.app = this; |
global.app = App.app = this; |
18 |
this.rootdir = rootdir; |
this.rootdir = rootdir; |
19 |
this.loadConfig(); |
this.loadConfig(); |
20 |
|
this.env = process.env; |
21 |
|
|
22 |
this.client = new Client({ |
this.client = new Client({ |
23 |
partials: ["CHANNEL"], |
partials: ["CHANNEL"], |
25 |
Intents.FLAGS.GUILDS, |
Intents.FLAGS.GUILDS, |
26 |
Intents.FLAGS.GUILD_MESSAGES, |
Intents.FLAGS.GUILD_MESSAGES, |
27 |
Intents.FLAGS.DIRECT_MESSAGES, |
Intents.FLAGS.DIRECT_MESSAGES, |
28 |
Intents.FLAGS.DIRECT_MESSAGE_TYPING |
Intents.FLAGS.DIRECT_MESSAGE_TYPING, |
29 |
|
Intents.FLAGS.GUILD_PRESENCES, |
30 |
|
Intents.FLAGS.GUILD_MEMBERS, |
31 |
|
Intents.FLAGS.GUILD_BANS |
32 |
] |
] |
33 |
}); |
}); |
34 |
|
|
37 |
this.commandManager = new CommandManager(path.resolve(__dirname, rootdir, "commands")); |
this.commandManager = new CommandManager(path.resolve(__dirname, rootdir, "commands")); |
38 |
this.logger = new Logger(); |
this.logger = new Logger(); |
39 |
this.spamFilter = new SpamFilter(); |
this.spamFilter = new SpamFilter(); |
40 |
|
this.antiRaid = new AntiRaid(); |
41 |
|
this.messageFilter = new MessageFilter(); |
42 |
this.boot(); |
this.boot(); |
43 |
} |
} |
44 |
|
|
45 |
boot() { |
boot() { |
46 |
this.on('ready', () => { |
this.on('ready', () => { |
47 |
console.log("Logged in as " + this.client.user.tag); |
console.log("Logged in as " + this.client.user.tag); |
48 |
|
|
49 |
|
this.client.user.setStatus(random(['dnd', 'idle'])); |
50 |
|
this.client.user.setActivity("over the server", { type: "WATCHING" }); |
51 |
|
|
52 |
|
server(); |
53 |
}); |
}); |
54 |
|
|
55 |
this.on('messageCreate', async (message) => { |
this.on('messageCreate', async (message) => { |
56 |
if (message.author.bot) { |
if (message.author.bot || !message.guild || message.channel.type == 'dm') { |
57 |
return; |
return; |
58 |
} |
} |
59 |
|
|
60 |
await (this.msg = message); |
await (this.msg = message); |
61 |
|
|
62 |
//await this.spamFilter.start(message); |
await this.spamFilter.start(message); |
63 |
|
await this.messageFilter.start(message, this.commandManager); |
64 |
|
|
65 |
await this.commandManager.setMessage(message); |
await this.commandManager.setMessage(message); |
66 |
|
|
67 |
const valid = await this.commandManager.valid(); |
const valid = await this.commandManager.valid(); |
68 |
const has = await this.commandManager.has(); |
const has = await this.commandManager.has(); |
69 |
const snippet = await this.commandManager.snippet(); |
const snippet = await this.commandManager.snippet(); |
70 |
|
const allowed = await this.commandManager.verify(); |
71 |
|
|
72 |
if (valid && has) { |
if (valid && has && allowed) { |
73 |
await this.exec(); |
await this.exec(); |
74 |
} |
} |
75 |
else if (valid && snippet !== undefined) { |
else if (valid && snippet !== undefined) { |
80 |
else if (valid && !has) { |
else if (valid && !has) { |
81 |
await this.commandManager.notFound(); |
await this.commandManager.notFound(); |
82 |
} |
} |
83 |
|
else if (valid && has && !allowed) { |
84 |
|
await this.commandManager.notAllowed(); |
85 |
|
} |
86 |
}); |
}); |
87 |
|
|
88 |
this.on("messageUpdate", async (oldMessage, newMessage) => { |
this.on("messageUpdate", async (oldMessage, newMessage) => { |
89 |
if (oldMessage.author.bot) |
if (oldMessage.author.bot || oldMessage.content === newMessage.content) |
90 |
return; |
return; |
91 |
|
|
92 |
await this.logger.logEdit(oldMessage, newMessage); |
await this.logger.logEdit(oldMessage, newMessage); |
93 |
}); |
}); |
94 |
|
|
95 |
|
|
96 |
|
this.on('guildBanAdd', async (ban) => { |
97 |
|
console.log('test'); |
98 |
|
await this.logger.logBanned(ban); |
99 |
|
}); |
100 |
|
|
101 |
|
this.on('guildBanRemove', async (ban) => { |
102 |
|
console.log('test'); |
103 |
|
await this.logger.logUnbanned(ban); |
104 |
|
}); |
105 |
|
|
106 |
this.on("messageDelete", async (message) => { |
this.on("messageDelete", async (message) => { |
107 |
if (message.author.bot) |
if (message.author.bot) |
108 |
return; |
return; |
126 |
delete this.config.props[guild.id]; |
delete this.config.props[guild.id]; |
127 |
this.config.write(); |
this.config.write(); |
128 |
}) |
}) |
129 |
|
|
130 |
|
this.on('guildMemberAdd', async (member) => { |
131 |
|
console.log('Joined'); |
132 |
|
await this.antiRaid.start(member); |
133 |
|
await this.logger.logJoined(member); |
134 |
|
}); |
135 |
|
|
136 |
|
this.on('guildMemberRemove', async (member) => { |
137 |
|
await this.logger.logLeft(member); |
138 |
|
}); |
139 |
} |
} |
140 |
|
|
141 |
loadConfig() { |
loadConfig() { |
156 |
run() { |
run() { |
157 |
this.client.login(process.env.TOKEN); |
this.client.login(process.env.TOKEN); |
158 |
} |
} |
159 |
|
|
160 |
|
tempFileCreate(name) { |
161 |
|
const fullname = path.join(__dirname, '..', 'tmp', name); |
162 |
|
const file = fs.createWriteStream(fullname); |
163 |
|
|
164 |
|
return { |
165 |
|
name: fullname, |
166 |
|
file |
167 |
|
}; |
168 |
|
} |
169 |
} |
} |
170 |
|
|
171 |
module.exports = App; |
module.exports = App; |