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 |
|
|
14 |
class App { |
class App { |
15 |
constructor(rootdir) { |
constructor(rootdir) { |
16 |
global.app = App.app = this; |
global.app = App.app = this; |
17 |
this.rootdir = rootdir; |
this.rootdir = rootdir; |
18 |
this.loadConfig(); |
this.loadConfig(); |
19 |
|
this.env = process.env; |
20 |
|
|
21 |
this.client = new Client({ |
this.client = new Client({ |
22 |
partials: ["CHANNEL"], |
partials: ["CHANNEL"], |
24 |
Intents.FLAGS.GUILDS, |
Intents.FLAGS.GUILDS, |
25 |
Intents.FLAGS.GUILD_MESSAGES, |
Intents.FLAGS.GUILD_MESSAGES, |
26 |
Intents.FLAGS.DIRECT_MESSAGES, |
Intents.FLAGS.DIRECT_MESSAGES, |
27 |
Intents.FLAGS.DIRECT_MESSAGE_TYPING |
Intents.FLAGS.DIRECT_MESSAGE_TYPING, |
28 |
|
Intents.FLAGS.GUILD_PRESENCES, |
29 |
|
Intents.FLAGS.GUILD_MEMBERS, |
30 |
] |
] |
31 |
}); |
}); |
32 |
|
|
35 |
this.commandManager = new CommandManager(path.resolve(__dirname, rootdir, "commands")); |
this.commandManager = new CommandManager(path.resolve(__dirname, rootdir, "commands")); |
36 |
this.logger = new Logger(); |
this.logger = new Logger(); |
37 |
this.spamFilter = new SpamFilter(); |
this.spamFilter = new SpamFilter(); |
38 |
|
this.antiRaid = new AntiRaid(); |
39 |
|
this.messageFilter = new MessageFilter(); |
40 |
this.boot(); |
this.boot(); |
41 |
} |
} |
42 |
|
|
43 |
boot() { |
boot() { |
44 |
this.on('ready', () => { |
this.on('ready', () => { |
45 |
console.log("Logged in as " + this.client.user.tag); |
console.log("Logged in as " + this.client.user.tag); |
46 |
|
server(); |
47 |
}); |
}); |
48 |
|
|
49 |
this.on('messageCreate', async (message) => { |
this.on('messageCreate', async (message) => { |
50 |
if (message.author.bot) { |
if (message.author.bot || !message.guild || message.channel.type == 'dm') { |
51 |
return; |
return; |
52 |
} |
} |
53 |
|
|
54 |
await (this.msg = message); |
await (this.msg = message); |
55 |
|
|
56 |
//await this.spamFilter.start(message); |
await this.spamFilter.start(message); |
57 |
|
await this.messageFilter.start(message, this.commandManager); |
58 |
|
|
59 |
await this.commandManager.setMessage(message); |
await this.commandManager.setMessage(message); |
60 |
|
|
61 |
const valid = await this.commandManager.valid(); |
const valid = await this.commandManager.valid(); |
62 |
const has = await this.commandManager.has(); |
const has = await this.commandManager.has(); |
63 |
const snippet = await this.commandManager.snippet(); |
const snippet = await this.commandManager.snippet(); |
64 |
|
const allowed = await this.commandManager.verify(); |
65 |
|
|
66 |
if (valid && has) { |
if (valid && has && allowed) { |
67 |
await this.exec(); |
await this.exec(); |
68 |
} |
} |
69 |
else if (valid && snippet !== undefined) { |
else if (valid && snippet !== undefined) { |
74 |
else if (valid && !has) { |
else if (valid && !has) { |
75 |
await this.commandManager.notFound(); |
await this.commandManager.notFound(); |
76 |
} |
} |
77 |
|
else if (valid && has && !allowed) { |
78 |
|
await this.commandManager.notAllowed(); |
79 |
|
} |
80 |
}); |
}); |
81 |
|
|
82 |
this.on("messageUpdate", async (oldMessage, newMessage) => { |
this.on("messageUpdate", async (oldMessage, newMessage) => { |
109 |
delete this.config.props[guild.id]; |
delete this.config.props[guild.id]; |
110 |
this.config.write(); |
this.config.write(); |
111 |
}) |
}) |
112 |
|
|
113 |
|
this.on('guildMemberAdd', async (member) => { |
114 |
|
console.log('Joined'); |
115 |
|
await this.antiRaid.start(member); |
116 |
|
}); |
117 |
} |
} |
118 |
|
|
119 |
loadConfig() { |
loadConfig() { |
134 |
run() { |
run() { |
135 |
this.client.login(process.env.TOKEN); |
this.client.login(process.env.TOKEN); |
136 |
} |
} |
137 |
|
|
138 |
|
tempFileCreate(name) { |
139 |
|
const fullname = path.join(__dirname, '..', 'tmp', name); |
140 |
|
const file = fs.createWriteStream(fullname); |
141 |
|
|
142 |
|
return { |
143 |
|
name: fullname, |
144 |
|
file |
145 |
|
}; |
146 |
|
} |
147 |
} |
} |
148 |
|
|
149 |
module.exports = App; |
module.exports = App; |