-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathbotReady.js
More file actions
110 lines (102 loc) · 4.08 KB
/
botReady.js
File metadata and controls
110 lines (102 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const {planExpiringAction} = require('../moderationActions');
const {Op} = require('sequelize');
const {localize} = require('../../../src/functions/localize');
const {embedType} = require('../../../src/functions/helpers');
const {scheduleJob} = require('node-schedule');
<<<<<<< HEAD
// import phishing service so that we can feed it custom patterns from configuration
const { setCustomPatterns } = require('../phishingService');
=======
>>>>>>> bdf48c957889f18888d1525806101cb792e35246
const memberCache = {};
const durationParser = require('parse-duration');
exports.run = async (client) => {
await updateCache(client);
const guild = await client.guilds.fetch(client.config.guildID);
const actions = await client.models['moderation']['ModerationAction'].findAll({
where:
{
expiresOn: {
[Op.gt]: new Date()
}
}
});
for (const action of actions) {
if (!action.expiresOn) continue;
await planExpiringAction(new Date(action.expiresOn), action, guild);
}
if (client.configurations['moderation']['config'].warnsExpire) {
const j = scheduleJob('42 0 * * *', () => {
deleteExpiredWarns(client).then(() => {
});
});
client.jobs.push(j);
deleteExpiredWarns(client).then(() => {
});
}
<<<<<<< HEAD
// configure phishing service with custom patterns from settings
const customPatterns = client.configurations['moderation']['config']['phishing-custom-patterns'];
if (Array.isArray(customPatterns) && customPatterns.length > 0) {
setCustomPatterns(customPatterns);
client.logger.info('[moderation] loaded ' + customPatterns.length + ' custom phishing pattern(s)');
}
=======
>>>>>>> bdf48c957889f18888d1525806101cb792e35246
const verificationConfig = client.configurations['moderation']['verification'];
if (!verificationConfig.enabled || !verificationConfig['restart-verification-channel']) return;
const channel = await client.channels.fetch(verificationConfig['restart-verification-channel']).catch(() => {
});
if (!channel || (channel || {}).type !== 'GUILD_TEXT') return client.logger.error('[moderation] ' + localize('moderation', 'verify-channel-set-but-not-found-or-wrong-type'));
let message = (await channel.messages.fetch()).filter(msg => msg.author.id === client.user.id).last();
if (!message) {
message = await channel.send(localize('moderation', 'generating-message'));
await message.pin();
}
await message.edit(embedType(verificationConfig['verify-channel-first-message'], {}, {
components: [
{
type: 'ACTION_ROW',
components: [
{
type: 'BUTTON',
label: '📨 ' + localize('moderation', 'restart-verification-button'),
customId: `mod-rvp`,
style: 'PRIMARY'
}
]
}
]
}));
};
/**
* Updates the punishment cache
* @private
* @param {Client} client
* @return {Promise<void>}
*/
async function updateCache(client) {
const moduleConfig = client.configurations['moderation']['config'];
memberCache['quarantine'] = (await (await client.guilds.fetch(client.guildID)).members.fetch()).filter(m => !!m.roles.cache.get(moduleConfig['quarantine-role-id']));
}
/**
* Removes expired warns
* @param {Client} client
* @return {Promise<void>}
*/
async function deleteExpiredWarns(client) {
const aD = await client.models['moderation']['ModerationAction'].findAll({
where: {
createdAt: {
[Op.lt]: new Date(new Date().getTime() - durationParser(client.configurations['moderation']['config']['warnExpiration']))
},
type: 'warn'
}
});
for (const action of aD) {
await action.destroy();
}
if (aD.length !== 0) client.logger.info(`Deleted ${aD.length} warns because their expired`);
}
module.exports.updateCache = updateCache;
module.exports.memberCache = memberCache;