-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanageViolations.js
More file actions
152 lines (152 loc) Β· 5.03 KB
/
manageViolations.js
File metadata and controls
152 lines (152 loc) Β· 5.03 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
var MongoClient = require('mongodb')
.MongoClient;
var url = require("./token.json")
.mongo;
var assert = require("assert")
var db = null;
var Discord = require("discord.js");
var client = null;
var modlog = null;
var whoaaaaaaa = require("./disallowed.json")
String.prototype.replaceAll = require("./helpers/replaceAll");
MongoClient.connect(url, {
authSource: "admin"
}, function (err, _db) {
assert.equal(null, err);
console.log("Connected successfully to server");
db = _db
global.db = _db
});
exports.setClient = (_client) => {
client = _client;
modlog = _client.guilds.get("433009422990835716")
.channels.get("433090183122911232");
//console.log(modlog)
};
exports.getViolations = async (id) => db ? await db.collection("violations")
.find({
uid: id,
archived: false
})
.toArray() : null;
exports.sendDm = async (auto, member, prev, content, indicated) => {
var dm = await member.createDM();
var punishmentMessage = "";
if (prev == 0) {
punishmentMessage = "Since this is your first chat violation, this is just a warning. If you recieve 2 more warnings your souls and tags will be reset, and you will be kicked from the server."
} else if (prev == 1) {
punishmentMessage = "This is your second chat violation. If you recieve another warning, your souls and tags will be reset, and you will be kicked from the server."
} else {
punishmentMessage = "As you have recieved 3 warnings, you were kicked from the server, and your souls reset."
}
if (auto) {
dm.send(new Discord.RichEmbed()
.setTitle("Your message was deemed to be against Nightborn rules")
.setDescription("We do not allow racism of any kind.")
.setColor(0xFF0000)
.addField("Your punishment", punishmentMessage)
.addField("Flagged content", indicated)
.addField("Was this in error?", "Speak to one of the dons, or VoidCrafted."))
} else {
dm.send(new Discord.RichEmbed()
.setTitle("You were deemed to be breaking Nightborn rules")
.setDescription("We do not allow racism of any kind.")
.setColor(0xFF0000)
.addField("Your punishment", punishmentMessage)
.setFooter("Manually added violation"))
}
}
module.exports.manualAddViol = async (message) => {
if (!message.member.roles.has("433018096144482325") && !message.member.roles.has("363891136533626890")) return;
if (false && !message.mentions.length) {
message.reply("Invalid usage. Could not detect a mention. If you only have the ID put \\<@id>");
return;
}
if (true) {
console.log("cmd")
var person = message.mentions.members.first();
console.log(person)
var viols = await exports.getViolations(person.id);
await exports.sendDm(false, person, viols.length, message.content)
await exports.addViol(person, message.content);
modlog.send(new Discord.RichEmbed()
.setTitle("[Violation]")
.setDescription(`Violation number ${viols.length + 1} by <@${person.id}>`)
.addField("Manual Violation", "This was manually added by " + message.author.username)
.setColor(0xFF0000))
if (viols.length == 2) {
exports.exile(person);
}
}
}
exports.indicate = (text) => {
whoaaaaaaa.map(whoa => {
text = text.toLowerCase()
.replaceAll(whoa, "__" + whoa + "__")
});
return text;
}
exports.exile = async (member) => {
exports.archiveAll(member);
try {
await member.kick("Recieved 3 violations")
} catch (e) {
modlog.send({
embed: {
title: "Couldn't kick a member",
description: "Couldn't kick <@" + member.id + "> because of a permission error.",
color: 0xFF0000
}
})
}
}
exports.hasViolation = async (message) => {
if (db) {
var fails = whoaaaaaaa.some((banned) => {
return message.content.toLowerCase()
.indexOf(banned) !== -1;
});
if (fails) {
var viols = await exports.getViolations(message.author.id);
await exports.sendDm(true, message.member, viols.length, message.content, exports.indicate(message.content))
await exports.addViol(message.member, message.content, true);
modlog.send(new Discord.RichEmbed()
.setTitle("Violation in #" + message.channel.name)
.setDescription(`Violation number ${viols.length + 1} by <@${message.member.id}>`)
.addField("Detected content", exports.indicate(message.content))
.setColor(0xFF0000))
if (viols.length == 2) {
exports.exile(message.member);
}
await message.delete()
}
}
}
exports.archiveAll = async (member) => await db.collection("violations")
.updateMany({
uid: member.id,
archived: false
}, {
$set: {
archived: true
}
})
exports.addViol = async (member, content, auto) => {
if (auto) {
db.collection("violations")
.insertOne({
uid: member.id,
archived: false,
manual: false,
messageContent: content,
messageContentIndicated: exports.indicate(content)
})
} else {
db.collection("violations")
.insertOne({
uid: member.id,
archived: false,
manual: true
})
}
}