-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
221 lines (207 loc) · 10.1 KB
/
index.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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require("fs");
const config = require("./src/config.json");
const token = config.token;
const clientID = config.clientid;
const prefix = "!"
const normalChat = config.chat;
const userRoleID = config.userrole;
const evalPerm = config.evalAllowed;
const owner = config.ownerid;
const colors = config.possibleCaptchaColors;
const blockedAccountIDs = config.blockedIDs;
const query = require("./src/Query.json")
// Configuration File: src/config.json
var waitingQueue = [];
var queue = [];
var kicked = [];
client.on("guildMemberAdd", (member) => {
member.user.send({
embed: {
color: 0xffff00,
description: "To verify yourself as a human, write `" + prefix + "receive` in the #verify channel to receive your captcha via Direct Message"
}
});
});
client.on('ready', () => {
console.log(config.botStarted + ` ${client.user.tag}!`);
client.user.setPresence({ status: 'online', game: { name: config.gameMessage } });
if(config.setNewAvatar){
client.user.setAvatar(config.avatar);
}
});
client.on('message', (message) => {
if (!message.guild) return;
let file = JSON.parse(fs.readFileSync("./src/config.json", "utf8"));
let queryFile = JSON.parse(fs.readFileSync("./src/Query.json", "utf8"));
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
var time = new Date();
var content = message.content;
var author = message.author.id;
if (file.blockedIDs[message.author.id]) {
if (file.blockedIDs[message.author.id].blocked == "true") {
message.member.kick();
console.log(message.member + " was kicked.");
}
}
if (message.author.id != clientID) {
if (message.content === prefix + "receive" || message.content === prefix + "verify" || message.content === prefix + "captcha") {
if (message.channel.name === "verify") {
if (message.member.roles.has(userRoleID)) {
message.author.send({
embed: {
color: 0xff0000,
description: "Already verified on `" + message.guild.name + "`"
}
});
} else {
var captcha = Math.floor(Math.random() * 9000) + 1001;
var floor = Math.floor(Math.random() * 10000) + 1;
let webshot = require("webshot");
var fontFace, fontSize, fontPosition;
if (floor < 5000) {
fontFace = "Comic Sans MS";
} else if (floor >= 5000) {
fontFace = "Arial";
}
var floorx = Math.floor(Math.random() * 10000) + 1;
fontSize = Math.floor(Math.random() * 20) + 35;
var height = Math.floor(Math.random() * 20) + 10 + "%";
var width = Math.floor(Math.random() * 20) + 10 + "%";
var fontColor = colors[Math.floor(Math.random() * 4) + 1];
var bgColor = colors[Math.floor(Math.random() * 4) + 1];
var rotate = Math.floor(Math.random() * 70) + 11;
var letterSpacing = Math.floor(Math.random() * 30) + 10;
var boxWidth = Math.floor(Math.random() * 30) + 30;
var boxHeight = Math.floor(Math.random() * 30) + 30;
var boxColor = colors[Math.floor(Math.random() * 4) + 1];
var boxBorderSize = Math.floor(Math.random() * 7) + 1 + "px";
var boxMarginTop = Math.floor(Math.random() * 70) + 10 + "%";
var boxMarginLeft = Math.floor(Math.random() * 70) + 10 + "%";
if (Math.random() > Math.random()) {
var rbackup = rotate;
rotate -= rbackup;
rotate -= rbackup;
}
if (bgColor === fontColor) {
fontColor = colors[Math.floor(Math.random() * 4) + 1];
}
webshot('<html><body style=\'background-image: url("http://b.reich.io/jjvoab.png");\'><h1 style="font-family:' + fontFace + '; color:' + fontColor + '; font-size:' + fontSize + 'px; position: absolute; top:' + height + ';left:' + width + '; -moz-transform: rotate(' + rotate + 'deg); -ms-transform: rotate(' + rotate + 'deg);-o-transform: rotate(' + rotate + 'deg);-webkit-transform: rotate(' + rotate + 'deg);letter-spacing: ' + letterSpacing + 'px;"><i><del>' + captcha + '</del></i></h1></body></html>', './captchas/' + floor + '.png', {
siteType: 'html',
screenSize: {
width: 500,
height: 500
}
}, function (err) {
message.author.send("", {
files: ['./captchas/' + floor + ".png"]
})
});
setTimeout(function () {
fs.unlinkSync("./captchas/" + floor + ".png");
}, 30000);
message.author.send({
embed: {
color: 0x0000ff,
description: "\n**Please memorise the Captha <code> below!** \nReturn to #verify channel. \nWrite `!verify` <code> in the #verify channel \nto see the protected server channels."
}
});
message.delete();
queryFile.query[author + "x" + captcha] = {
verified: "false"
};
fs.writeFile("./src/Query.json", JSON.stringify(queryFile));
queue.push(author + "x" + captcha);
waitingQueue.push(message.author.id);
console.log(queue);
}
}
} else if (message.channel.name === "verify" && message.content.includes(prefix + "verify")) {
var input = message.content.substr(8);
for (i = 0; i < queue.length; i++) {
var cpoint = queue[i].indexOf("x");
}
cpoint++;
for (i = 0; i < queue.length; i++) {
var oldcaptcha = queue[i].substr(cpoint);
}
if (input === oldcaptcha) {
if (message.member.roles.has(userRoleID)) {
message.author.send({
embed: {
color: 0xff0000,
description: "Already verified on `" + message.guild.name + "`"
}
});
} else {
message.author.send({
embed: {
color: 0x00ff00,
description: "Successfully verified on `" + message.guild.name + "`"
}
});
client.channels.find('name', normalChat).send("<@" + message.author.id + "> was successfully verified.");
queryFile.query[message.author.id + "x" + oldcaptcha].verified = "true";
queue.pop();
fs.appendFileSync("./verify_logs.txt", "[VerifyBot] " + time.getHours() + ":" + time.getMinutes() + ":" + time.getSeconds() + "| " + message.author.tag + "(" + message.author.id + ") verified himself.\n");
message.member.addRole(userRoleID).catch(error => console.log(error));
}
} else {
if (message.content.toLowerCase() != prefix + "verify") {
message.author.send("You were kicked from " + message.guild.name + " (WRONG_CAPTCHA)");
message.delete();
message.member.kick();
}
}
}
}
if (message.content.toLowerCase().startsWith(prefix + "ban")) {
if (message.member.hasPermission('ADMINISTRATOR')) {
message.guild.member(message.mentions.users.first()).kick();
}
}
if (message.content.toLowerCase().startsWith(prefix + "block")) {
if (message.member.hasPermission('ADMINISTRATOR')) {
if (!file.blockedIDs[args[0]]) {
file.blockedIDs[args[0]] = {
blocked: "true"
};
fs.writeFileSync("./src/config.json", JSON.stringify(file));
message.channel.send("Added `" + message.content.substr(7) + "` to the blocked list.");
} else {
message.channel.send("ID is already blocked.");
}
} else {
return message.channel.send("Missing Permissions");
}
}
if (message.content.toLowerCase().startsWith(prefix + "removeBlock")) {
if (message.member.hasPermission('ADMINISTRATOR')) {
if (file.blockedIDs[args[0]].blocked == "true") {
file.blockedIDs[args[0]].blocked = "false";
fs.writeFileSync("./src/config.json", JSON.stringify(file));
message.channel.send("Successfully removed the block for `" + args[0] + "`.")
} else {
message.channel.send("ID is not blocked.");
}
} else {
return message.channel.send("Missing Permissions");
}
}
if (message.content.startsWith(prefix + "clear") && message.content.indexOf("captcha") === "-1") {
if (message.member.hasPermission('ADMINISTRATOR')) {
message.channel.bulkDelete(message.content.substr(7));
} else {
return message.channel.send("Missing Permissions");
}
}
if (message.channel.name === "verify") {
message.delete();
}
if (message.author.id === owner && evalPerm === "true" && message.content.startsWith(prefix + "eval")) {
message.channel.send(":outbox_tray: Output: ```JavaScript\n" + eval(message.content.substr(6)) + "\n```");
}
});
client.login(config.token);