-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.js
94 lines (83 loc) · 3.44 KB
/
message.js
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
const Discord = require('discord.js');
const { firebaseSpamLinkArray } = require('../firebase/firebase_handler');
const { COLORS, PREFIX } = require('../utils/constants');
const { logger } = require('../utils/logger');
module.exports = {
name: 'message',
/**
* @param {Discord.Message} message
* @param {Discord.Client} client
* */
async execute(message, client) {
if (message.author.bot) return;
if (message.channel.type === 'dm') {
const { messageHandler } = require('./guildMemberAdd');
messageHandler(message, client);
return;
}
if (!message.content.startsWith(PREFIX)) await this.checkSpamMessage(message, client);
if (!message.content.startsWith(PREFIX)) return;
let embed;
const args = message.content.slice(PREFIX.length).trim().split(' ');
const command = args.shift().toLowerCase();
let commandFileData;
if (command === 'thanks' || command === 'thankyou' || command === 'ty') commandFileData = client.commands.get('thank');
else commandFileData = client.commands.get(command);
if (!commandFileData) return;
logger.log(`Recieved command from: ${message.author.tag} , command: ${message.content} `);
try {
await commandFileData.execute(message, args, client);
} catch (e) {
logger.error(`Command: ${command} Error: ${e.message} | ${e?.stack}`);
embed = new Discord.MessageEmbed({
title: 'Error Occured',
description: 'I am not feeling too well my friend',
color: COLORS.red,
});
return message.channel.send(embed).then((msg) => {
msg.delete({ timeout: 5000 });
});
}
},
/**
* Checks if given message is a nitro spam message
* @param {Discord.Message} message
* @param {Discord.Client} client
* */
async checkSpamMessage(message, client) {
const msg = message.content;
const spamArray = firebaseSpamLinkArray.map((e) => e.link);
let flag = false;
if (msg.toLowerCase().includes('@everyone') && msg.toLowerCase().includes('nitro')) {
flag = true;
} else {
for (let index = 0; index < spamArray.length; index++) {
if (msg.toLowerCase().includes(spamArray[index])) {
flag = true;
break;
}
}
}
if (flag) {
const member = message.guild.member(message.author.id);
try {
await member.send(
[
`Dear ${member},`,
'We have noticed you are not following our guidelines properly',
'You have spammed the server. Please do not repeat the same',
].join('\n')
);
} catch (error) {}
const embed = new Discord.MessageEmbed()
.setTitle(`${member.user.tag} used spam link`)
.setDescription(`Message :-\n\`\`\`${message.content}\`\`\``)
.setThumbnail(member.user.displayAvatarURL())
.setColor(COLORS.cyan);
message.delete();
const serverConfig = client.configs.get(message.guild.id);
const channel = client.channels.cache.get(serverConfig.moderator_channel_id);
channel.send(embed);
}
},
};