-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
447 lines (440 loc) · 14.4 KB
/
bot.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
const Discord = require('discord.js');
const fs = require('fs');
require('dotenv/config');
// initialize our bot
const bot = new Discord.Client();
bot.commands = new Discord.Collection();
//settings
let prefix;
const owner = process.env.OWNER;
const token = process.env.TOKEN;
//initialize firebase
const firebase = require('firebase');
const wordList = require('./node_modules/word-list-json/words.json').words;
function scramble(s) {
var arr = s.split('');
var n = arr.length;
for(var i = 0 ; i<n-1 ; ++i) {
var j = Math.floor(Math.random() * n);
var temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
s = arr.join('');
return s;
}//for punish scrambling
function aphasia(s) {
var output = ''
for (var n = 0; n < s.trim().split(' ').length; n++) {
let number = Math.floor(Math.random() * wordList.length);
output = output + wordList[number] + ' '
}
return output;
}//aphasia thingy
function eee(s){
var arr = s.split('');
var n = arr.length;
var e = true;
for (var i = 0; i < n; i++){
if (arr[i] != 'e'){
e = false;
}
}
return e;
}//eee test
function testdadjoke(s){
if (s.startsWith('i am ') || s.startsWith('i\'m ') || s.startsWith('im ') || s.startsWith('i‘m ') || s.startsWith('i’m ')){
return true;
}
}
function dadjoke(s = ''){
for (var i = 0; i < s.length - 1; i++){
if (testdadjoke(s.split(' ').slice(i).join(' ').toLowerCase())){
var t = s.split(' ').slice(i).join(' ');
if (s.toLowerCase().startsWith('i am')){
return t.split(' ').slice(2).join(' ');
}
return t.split(' ').slice(1).join(' ');
}
}
return false;
}
var config = {
apiKey: "AIzaSyCF8MfWZcvprGTr3egGrPxE1TwdnUD71hA",
authDomain: "extilebot.firebaseapp.com",
databaseURL: "https://extilebot.firebaseio.com",
projectId: "extilebot",
storageBucket: "extilebot.appspot.com",
messagingSenderId: "638492185735",
appId: "1:638492185735:web:2d99b99948fdfa1abe1422",
measurementId: "G-GTGD4B5T7T"
};
firebase.initializeApp(config);
//read commands files
fs.readdir('./cmds', (err,files) => {
if (err) {
console.log(err);
}
let cmdFiles = files.filter(f => f.split('.').pop() === 'js');
if (cmdFiles.length === 0){
console.log('No files found');
return;
}
cmdFiles.forEach((f,i) => {
let props = require(`./cmds/${f}`);
console.log(`${i+1}: ${f} loaded`);
bot.commands.set(props.help.name, props);
})
});
bot.on('ready', async () => {
console.log('Hello, I\'m ready');
bot.user.setActivity('&help | ' + bot.guilds.cache.size.toString() + ' servers', { type: 'WATCHING' });
});
bot.on('messageUpdate', (oldMessage, newMessage) => {
if (oldMessage.content == 'Pinging...' && oldMessage.author.id == bot.user.id) {
var oldMessageTimestamp = oldMessage.createdTimestamp;
var newMessageTimestamp = newMessage.editedTimestamp;
newMessage.edit(`Pong! \`\`${Math.floor(newMessageTimestamp - oldMessageTimestamp)}ms\`\``);
}
var msg = newMessage.content.split('\u200b').join('');
msg = msg.split('\u200d').join('');
if (msg.toLowerCase().includes('biswadev')){
firebase.database().ref(newMessage.guild.id + '/punishedMembers').update({
[newMessage.author.id]: newMessage.author.id
});
newMessage.delete();
newMessage.channel.send('<@!' + newMessage.author.id + '>, Obsessed!');
newMessage.channel.send('<@!' + newMessage.author.id + '> was punished for obsession');
}
var bphrases;
var banping;
firebase.database().ref(newMessage.guild.id).once('value').then(function (snap) {
if (snap.val()){
if (snap.val().bphrases){
bphrases = snap.val().bphrases;
}
if (snap.val().banping){
banping = snap.val().banping;
}
}
}).then(() => {
var usedbphrase = false;
if (banping > 0){
if (newMessage.mentions.members.size >= banping){
newMessage.channel.send('<@' + newMessage.member.id + '> was banned for spam pinging')
newMessage.member.ban();
return;
}
}
for (var phrase in bphrases){
if (msg.toLowerCase().includes(phrase) && !(msg.startsWith(prefix) && newMessage.member.hasPermission('MANAGE_MESSAGES'))){
if (bphrases[phrase] == 'ban'){
newMessage.channel.send('<@' + newMessage.member.id + '> was banned for saying a banned phrase');
newMessage.member.ban('Saying a banned phrase');
}
if (bphrases[phrase] == 'kick'){
newMessage.channel.send('<@' + newMessage.member.id + '> was kicked for saying a banned phrase');
newMessage.member.kick('Saying a banned phrase');
}
if (bphrases[phrase] == 'aphasia'){
newMessage.channel.send('<@' + newMessage.member.id + '> was inflicted with aphasia for saying a banned phrase');
firebase.database().ref(newMessage.guild.id + '/aphasicMembers').update({
[newMessage.author.id]: newMessage.author.id
});
}
if (bphrases[phrase] == 'punish'){
newMessage.channel.send('<@' + newMessage.member.id + '> was punished for saying a banned phrase');
firebase.database().ref(newMessage.guild.id + '/punishedMembers').update({
[newMessage.author.id]: newMessage.author.id
});
}
if (bphrases[phrase] == 'mute'){
var muterole = newMessage.guild.roles.cache.find(role => role.name == "Muted");//find muted role
if (!muterole){
muterole = newMessage.guild.roles.create({
data: {
name: 'Muted',
hoist: false,
permissions: 263232,
mentionable: false,
}
});
}
newMessage.guild.channels.cache.forEach(tc => {
tc.updateOverwrite(muterole, {
SEND_MESSAGES: false,
SPEAK: false
});
});
newMessage.channel.send('<@' + newMessage.member.id + '> was muted for saying a banned phrase');
newMessage.member.roles.add(muterole);
}
usedbphrase = true;
}
}
if (usedbphrase){
newMessage.delete();
return;
}
});
});//ping command
bot.on('message', async message => {
if (message.author.bot) return;
if (message.channel.type === 'dm') return;
var punished = false;
var aphasic = false;
var obsessed = false;
var prefix = '&';
var pingus = false;
var oofed = true;
var dadjoking = true;
var eeeee = true;
var lawl = true;
var henlo = true;
var msg = message.content.split('\u200b').join('');
msg = msg.split('\u200d').join('');
var bphrases;
var banping;
if (message.content.includes('@everyone') || message.content.includes('@here') || (message.content.includes('<@') && message.content.includes('>'))) pingus = true;
firebase.database().ref(message.guild.id).once('value').then(function (snap) {
if (msg.toLowerCase().includes('biswadev')) obsessed = true;
if (snap.val()){
prefix = snap.val().prefix;
if (snap.val().punishedMembers){
if (snap.val().punishedMembers[message.author.id]){
punished = true;
}
}
if (snap.val().bphrases){
bphrases = snap.val().bphrases;
}
if (snap.val().aphasicMembers){
if (snap.val().aphasicMembers[message.author.id]){
aphasic = true;
}
}
if (snap.val().banping){
banping = snap.val().banping;
}
if (snap.val().aresp){
dadjoking = snap.val().aresp.dadjoking;
eeeee = snap.val().aresp.eeeee;
lawl = snap.val().aresp.lawl;
henlo = snap.val().aresp.henlo;
}
}
}).then(() => {
if (banping > 0){
if (message.mentions.members.size >= banping){
message.channel.send('<@' + message.member.id + '> was banned for spam pinging');
message.delete();
message.member.ban();
return;
}
}
if (true){
if (eee(msg) == true && msg.length >= 5 && eeeee){
message.channel.send('https://tenor.com/view/ea-sports-e-ea-meme-gif-14922519');
return;
}//eee response
if ((msg.toLowerCase() == 'henlo') && henlo){
message.channel.send('Henlo, <@!' + message.author.id + '>');
return;
}//henlo response
if ((msg.toLowerCase() == 'lawl') && lawl){
message.channel.send('Lawl');
return;
}//lawl response
if (!pingus && message.content.toLowerCase().substring(0,18) == 'alexa, simon says '){
message.delete();
message.channel.send(message.content.split(' ').slice(3).join(' '));
return;
}//repeat after me
}//autoresponses
if (obsessed){
firebase.database().ref(message.guild.id + '/punishedMembers').update({
[message.author.id] : message.author.id
}).then(() => {
message.delete();
message.channel.send('<@!' + message.author.id + '>, Obsessed!');
message.channel.send('<@!' + message.author.id + '> was punished for obsession');
return;
});
return;
}//obsession
var usedbphrase = false;
for (var phrase in bphrases){
if (msg.toLowerCase().includes(phrase) && !(msg.startsWith(prefix) && message.member.hasPermission('MANAGE_MESSAGES'))){
if (bphrases[phrase] == 'ban'){
message.channel.send('<@' + message.member.id + '> was banned for saying a banned phrase');
message.member.ban('Saying a banned phrase');
}
if (bphrases[phrase] == 'kick'){
message.channel.send('<@' + message.member.id + '> was kicked for saying a banned phrase');
message.member.kick('Saying a banned phrase');
}
if (bphrases[phrase] == 'aphasia'){
message.channel.send('<@' + message.member.id + '> was inflicted with aphasia for saying a banned phrase');
firebase.database().ref(message.guild.id + '/aphasicMembers').update({
[message.author.id]: message.author.id
});
}
if (bphrases[phrase] == 'punish'){
message.channel.send('<@' + message.member.id + '> was punished for saying a banned phrase');
firebase.database().ref(message.guild.id + '/punishedMembers').update({
[message.author.id]: message.author.id
});
}
if (bphrases[phrase] == 'mute'){
var muterole = message.guild.roles.cache.find(role => role.name == "Muted");//find muted role
if (!muterole){
muterole = message.guild.roles.create({
data: {
name: 'Muted',
hoist: false,
permissions: 263232,
mentionable: false,
}
});
}
message.guild.channels.cache.forEach(tc => {
tc.updateOverwrite(muterole, {
SEND_MESSAGES: false,
SPEAK: false
});
});
message.channel.send('<@' + message.member.id + '> was muted for saying a banned phrase');
message.member.roles.add(muterole);
}
usedbphrase = true;
}
}
if (usedbphrase){
message.delete();
return;
}
let message_array = msg.split(' ');
let command = message_array[0];
let args = message_array.slice(1);
if (punished){
message.delete().catch(error => {
message.channel.send('Give message deletion perms please');
});
if (msg.includes('$') || msg.includes(',tex') || msg.includes('~tex')) {
message.channel.send(`${message.author}: ${scramble(msg)}`).then(function() {
const filter = response => {
if (response.author.id == 419356082981568522 || response.author.id == 510789298321096704) {
return true;
}
else {
return false;
}
}
message.channel.awaitMessages(filter, {max: 1, time: 10000}).then(function(collected) {
collected.first().delete();
})
})
} else {
message.channel.send(`${message.author}: ${scramble(msg)}`);
}
}//punished scrambling
if (aphasic){
if (!punished){
message.delete().catch(error => {
message.channel.send('Give message deletion perms please');
});
}
if ( msg.split('$').length - 2 * msg.split('$$').length > 1 || msg.split('$$').length > 1 || msg.includes(',tex') || msg.includes('~tex')) {
message.channel.send(`${message.author}: ${aphasia(msg)}`).then(function() {
const filter = response => {
if (response.author.id == 419356082981568522 || response.author.id == 510789298321096704) {
return true;
} else {
return false;
}
}
message.channel.awaitMessages(filter, {max: 1, time: 10000}).then(function(collected) {
collected.first().delete();
})
})
} else {
message.channel.send(`${message.author}: ${aphasia(msg)}`);
}
}//aphasic randomwordsing
if (!punished && !aphasic && dadjoking){
if (!pingus && dadjoke(msg)){
var joke = dadjoke(msg);
message.channel.send('Hi ' + joke + ', I\'m Extile');
return;
}//dad jokes
oofed = false;
}
if (!command.startsWith(prefix)) return;
if (bot.commands.get(command.slice(prefix.length))){
let cmd = bot.commands.get(command.slice(prefix.length));
if (cmd){
console.log(message.author.username + ' ran the ' + command + ' command');
cmd.run(bot, message, args, firebase, prefix, oofed);
return;
}
message.channel.send('\'' + command.slice(prefix.length) + '\'is not recognized as an internal or external command, operable program, or batch file\nUse ' + prefix + 'help to get my command list');
}
});
});
bot.on('guildCreate', async gData => {
var inv2;
gData.systemChannel.createInvite({
maxAge: 0,
unique: false
}).then(inv => {
inv2 = inv.url;
});
firebase.database().ref(gData.id).update({
'guildName': gData.name,
'guildOwner': gData.owner.user.username,
'guildOwnerId': gData.owner.id,
'guildMembercount': gData.memberCount,
'prefix': '&',
'punishedMembers' : {},
'aphasicMembers' : {},
'rouletteWL' : {},
'rouletteGame' : {},//{leader: leaderid, playerList: {set of the things}, order: [set], curIndex: 0, playersLeft: {set of ids}}
'hype': 0,
'aresp': {
'dadjoking': true,
'eeeee': true,
'lawl': true,
'henlo': true
},
});
if (inv2){
firebase.database().ref(gData.id).set({
invite: inv2
});
}
gData.systemChannel.send('Hello, I\'m Extile! Use &help to access my help function, and join my support server at https://discord.gg/HaJQ3vU for any questions, comments, or suggestions!');
bot.user.setActivity('&help | ' + bot.guilds.cache.size.toString() + ' servers', { type: 'WATCHING' });
});
bot.on('guildMemberAdd', async gMember => {
firebase.database().ref(gMember.guild.id).update({
'guildMembercount': gMember.guild.memberCount,
});
var wcChnl = gMember.guild.systemChannel;
if (!wcChnl) return;
wcChnl.send('Welcome <@!' + gMember.id + '> to the server!');
});
bot.on('guildMemberRemove', async gMember => {
firebase.database().ref(gMember.guild.id).update({
'guildMembercount': gMember.guild.memberCount,
'guildOwner' : gMember.guild.owner.user.username,
'guildOwnerId' : gMember.guild.owner.id
});
});
bot.on('guildDelete', async guild => {
firebase.database().ref().update({
[guild.id]: null
});
bot.user.setActivity('&help | ' + bot.guilds.cache.size.toString() + ' servers', { type: 'WATCHING' });
});
// Bot login
bot.login(token);