This repository has been archived by the owner on Feb 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathspam.js
125 lines (108 loc) · 5.29 KB
/
spam.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
var Discord = require("discord.js");
var client = new Discord.Client();
client.login("YOUR BOT TOKEN HERE");
client.on("ready", () => {
console.log("I'm ready to do work!");
});
const slowmode_mentions = new Map();
const slowmode_links = new Map();
const slowmode_attachments = new Map();
const ratelimit = 7500; // within 7.5 seconds
const logChannel = "LOG CHANNEL ID HERE"; // logs channel id
client.on("message", message => {
if (message.content.startsWith("!ping")) {
let startTime = Date.now();
message.channel.send("Ping...").then(newMessage => {
let endTime = Date.now();
newMessage.edit("Pong! Took `" + Math.round(endTime - startTime) + "ms`!");
});
}
function log(logmessage) {
if (message.guild.channels.has(logChannel)) {
message.guild.channels.get(logChannel).send({ embed: logmessage}).then().catch(err => console.log(err));
}
}
// set the max mentions/links/attachments that are allowed
let banLevel = {
"mentions": 10,
"links": 10,
"attachments": 10
};
// Ignore bots, DMs, Webhooks, if this bot has no perms, and Mods
if (message.author.bot || !message.guild || !message.member || !message.guild.member(client.user).hasPermission("BAN_MEMBERS") || message.member.hasPermission("MANAGE_MESSAGES")) return;
// Ignore if 1 mention and it's a bot (bot interaction)
if (message.mentions.users.size == 1 && message.mentions.users.first().bot) return;
// If there is no trace of the author in the slowmode map, add them.
let entry_mentions = slowmode_mentions.get(message.author.id);
let entry_links = slowmode_links.get(message.author.id);
let entry_attachments = slowmode_attachments.get(message.author.id);
if (!entry_mentions) {
entry_mentions = 0;
slowmode_mentions.set(message.author.id, entry_mentions);
}
if (!entry_links) {
entry_links = 0;
slowmode_links.set(message.author.id, entry_links);
}
if (!entry_attachments) {
entry_attachments = 0;
slowmode_attachments.set(message.author.id, entry_attachments);
}
// Count the unique user and roles mentions, links and attachments
entry_mentions += message.mentions.users.size + message.mentions.roles.size;
entry_links += message.embeds.length;
entry_attachments += message.attachments.size;
// Set all the amounts in the slowmode maps
slowmode_mentions.set(message.author.id, entry_mentions);
slowmode_links.set(message.author.id, entry_links);
slowmode_attachments.set(message.author.id, entry_attachments);
// If the total number of links in the last ratelimit is above the server ban level, ban user
if (entry_links > banLevel.links) {
message.member.ban(1).then(member => {
message.channel.send(`:ok_hand: banned \`${message.author.tag}\` for \`link spam\``);
log(new Discord.RichEmbed().setTitle(':hammer: Banned').setColor(0xFF0000).setTimestamp().addField('User', `${message.author.tag} (${message.author.id})`).addField('Reason', `Posting too many links (${entry_links}x)`));
slowmode_links.delete(message.author.id);
})
.catch(e => {
log(new Discord.RichEmbed().setTitle(':x: ERROR').setColor(0x000001).setTimestamp().addField('User', `${message.author.tag} (${message.author.id})`).addField('Reason', `Could not ban because they have a higher role`));
});
} else {
setTimeout(()=> {
entry_links -= message.embeds.length;
if(entry_links <= 0) slowmode_links.delete(message.author.id);
}, ratelimit);
}
if (entry_mentions > banLevel.mentions) {
message.member.ban(1).then(member => {
message.channel.send(`:ok_hand: banned \`${message.author.tag}\` for \`mention spam\``);
log(new Discord.RichEmbed().setTitle(':hammer: Banned').setColor(0xFF0000).setTimestamp().addField('User', `${message.author.tag} (${message.author.id})`).addField('Reason', `Mentioning too many users (${entry_mentions}x)`));
slowmode_mentions.delete(message.author.id);
})
.catch(e => {
log(new Discord.RichEmbed().setTitle(':x: ERROR').setColor(0x000001).setTimestamp().addField('User', `${message.author.tag} (${message.author.id})`).addField('Reason', `Could not ban because they have a higher role`));
});
} else {
setTimeout(()=> {
entry_mentions -= message.mentions.users.size + message.mentions.roles.size;
if(entry_mentions <= 0) slowmode_mentions.delete(message.author.id);
}, ratelimit);
}
if (entry_attachments > banLevel.attachments) {
message.member.ban(1).then(member => {
message.channel.send(`:ok_hand: banned \`${message.author.tag}\` for \`image spam\``);
log(new Discord.RichEmbed().setTitle(':hammer: Banned').setColor(0xFF0000).setTimestamp().addField('User', `${message.author.tag} (${message.author.id})`).addField('Reason', `Posting too many images (${entry_attachments}x)`));
slowmode_attachments.delete(message.author.id);
})
.catch(e => {
log(new Discord.RichEmbed().setTitle(':x: ERROR').setColor(0x000001).setTimestamp().addField('User', `${message.author.tag} (${message.author.id})`).addField('Reason', `Could not ban because they have a higher role`));
});
} else {
setTimeout(()=> {
entry_attachments -= message.attachments.size;
if(entry_attachments <= 0) slowmode_attachments.delete(message.author.id);
}, ratelimit);
}
});
process.on("unhandledRejection", err => {
console.error("Uncaught Promise Error: \n" + err.stack);
});