-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
590 lines (502 loc) · 13.2 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
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
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
//Zombot
const Discord = require('discord.js');
const client = new Discord.Client();
const Random = require('./ZombotModules/Random');
const Items = require('./ZombotModules/Items');
const Events = require('./ZombotModules/Events');
const Vehicles = require('./ZombotModules/Vehicles');
const Weather = require('./ZombotModules/Weather');
client.login('-KEY-');
client.once('ready', () => {
console.log('Zombot RISES! Ver. ' + version);
console.log('Items: ' + items.length);
console.log('Events: ' + events.length);
guild = client.guilds.cache.get('757471211449221200');
welcomeChannel = client.channels.cache.get('757474321793810463');
applicationChannel = client.channels.cache.get('757477790189879296');
radioChannel = client.channels.cache.get('833142245669863495');
moderatorRole = guild.roles.cache.get('757641212600516830');
entryRole = guild.roles.cache.get('926942858433413182');
acceptedRole = guild.roles.cache.get('757713868129566810');
if(!debug)
{
Weather.SetWeatherChannel(client.channels.cache.get('923391549600055307'));
}
else // Debug land
{
}
});
// Important junk
const prefix = ';';
const debug = false;
const version = "1.6F";
const color = '#d7fc03';
const clearMax = 99;
//chance of getting nothing
const itemNothingChance = 30; //30
const partMissingChance = 75;
//Timer stuff
var lootTimerList = {};
var eventTimerList = {};
const lootTimerTime = 60 * 2; //2, seconds to minutes
const eventTimerTime = 60 * 15; //15
setInterval(OnSecond, 1000);
const items = Items.items;
const itemTags = Items.itemTags;
const events = Events.events;
const eventTags = Events.eventTags;
var welcomeChannel = null;
var applicationChannel = null;
var radioChannel = null;
var guild = null;
var entryRole = null;
var acceptedRole = null;
const blacklist = [
'757477790189879296',
'757471211449221204',
'757833067686789170',
'757715088886071486',
'758509012387364912',
'758876960964476928',
'758041962409492480',
'758051356404875366',
]
const helpMessage = new Discord.MessageEmbed()
.setColor(color)
.setTitle("*BRAINS:*\n")
.addFields(
{name: prefix + "loot [tag]", value: "Displays a random loot item. Chance to find nothing. (pass in a tag to get a category item, or \"tags\" to see all tags.)"},
{name: prefix + "randomevent (" + prefix + "re) (tag)", value: "Displays a random event. (Also allows tag search.)"},
{name: prefix + "walkietalkie (" + prefix + "wt)", value: "Used for the walkie/radio feature."},
{name: prefix + "generatevehicle (" + prefix + "gv)", value: "Generates a random vehicle. (Your choice where the keys are.)"},
{name: prefix + "weather", value: "Show the current weather."},
{name: prefix + "roll", value: "Roll a random number."},
)
.setFooter("In your HEAAAAAAD, ZOMBEH, ZOMBEH, ZOMBEH -EH -EH (ver. " + version + ")");
const adminHelpMessage = new Discord.MessageEmbed()
.setColor(color)
.setTitle("*BIG BRAINS:*\n")
.addFields(
{name: "------------", value: "*Moderator*"},
{name: prefix + "clear [amount (1-" + clearMax + ")]", value: "Clears previous amount of messages."},
{name: prefix + "accept [user]", value: "Allows a user to roleplay."},
{name: "------------", value: "*Admin*"},
{name: prefix + "say", value: "Speak as Zombot."},
{name: prefix + "setweather [id]", value: "Set the current weather."},
{name: prefix + "item [name]", value: "Prints the Item's info."},
{name: prefix + "testloot [name]", value: "Show the loot message for a specific item."},
)
.setFooter("Admin and Mod stuff.");
client.on('guildMemberAdd', async(member) => {
let embed = new Discord.MessageEmbed()
.setColor(color)
.setDescription(`**${member}` + " has joined!**");
welcomeChannel.send(embed);
member.roles.add(entryRole);
});
client.on('guildMemberRemove', async(member) => {
let embed = new Discord.MessageEmbed()
.setColor('#AA0000')
.setDescription(`**${member}` + " has left.**");
welcomeChannel.send(embed);
});
var lastUser;
var lastMessage;
client.on('message', message =>
{
if (!message.content.startsWith(prefix) || message.author.bot)
return;
// Hopefully no race condition
lastUser = String(message.author.id);
lastMessage = message;
if(!IsAdmin())
{
if (IsBlacklisted(message.channel.id))
return;
}
const args = message.content.slice(prefix.length).trim().split(' ');
const command = args.shift().toLowerCase();
if(command === 'help')
{
SendMessage(helpMessage);
}
// Loot
if (command === 'loot')
{
if(args[0] === "tags")
PrintTags(itemTags);
else
LootItem(args[0], null); // We could pass multiple tags in the future
}
// RandomEvent
if (command === 'randomevent' || command === 're')
{
if(args[0] === "tags")
PrintTags(eventTags);
else
PlayEvent(args[0]);
}
if(command === 'walkietalkie' || command === 'wt')
{
UseWalkieTalkie(args)
return;
}
if(command === 'generatevehicles' || command === 'gv')
{
let outStr = Vehicles.Generate();
SendMessage(outStr);
return;
}
if(command === 'weather')
{
SendMessage("*The weather is " + Weather.GetWeather() + "*");
return;
}
if(command === 'roll')
{
let high = Number(args[0])
if(high < 2 || high === undefined || args.length === 0)
{
SendMessage("Usage: " + prefix + "roll [max] (Rolls a number between 1 and max)");
return
}
let rand = Random.Range(1, high);
SendMessage("You rolled a **" + rand + "**! (1-" + high + ") (" + `${message.author}` + ")");
}
//Admin commands
if(command === 'ahelp')
{
if(!IsModerator())
{
SendMessage("You're not supposed to do that. :eye::lips::eye:", 3000);
return;
}
SendMessage(adminHelpMessage);
return;
}
if(command === 'clear')
{
if(!IsModerator())
{
SendMessage("You're not supposed to do that. :eye::lips::eye:", 3000);
return;
}
let count = Number.parseInt(args[0]);
if(!count || count < 1 || count > clearMax)
{
SendMessage("Usage: " + prefix + "clear [amount (2-" + clearMax + ")] - Doesn't work on messages older than 2 weeks.");
return;
}
let user = lastMessage.mentions.members.first();
lastMessage.channel.bulkDelete(count + 1)
.then( SendMessage("Deleted " + count + " messages.", 3000, false) )
.catch((err) => {
SendMessage("Failed to Delete Messages.", 3000);
return;
}); // We add 1 to include the command
return;
}
if(command === 'accept')
{
if(!IsModerator())
{
SendMessage("You're not supposed to do that. :eye::lips::eye:", 3000);
return;
}
let member = lastMessage.mentions.members.first();
if(!member)
{
SendMessage("Usage: " + prefix + "accept [tagged user]");
return;
}
if (HasRole(member, entryRole))
{
member.roles.remove(entryRole);
member.roles.add(acceptedRole);
applicationChannel.send("**Welcome " + `${member}` + "!** Your application is approved.")
.then(message.delete());
}
else
{
applicationChannel.send("**Hey " + `${member}` + "!** Your character is approved.")
.then(message.delete());
}
return;
}
if(command === 'say')
{
if(!IsAdmin())
{
SendMessage("You're not supposed to do that. :eye::lips::eye:", 3000);
return;
}
let data = args.join(' ');
SendMessage(data, 3000);
return;
}
if(command === 'setweather')
{
if(!IsAdmin())
{
SendMessage("You're not supposed to do that. :eye::lips::eye:", 3000);
return;
}
if(isNaN(Number(args[0])))
return;
if(Weather.SetWeather(args[0]))
SendMessage("Weather Set: " + Weather.GetWeather());
else
SendMessage("Weather Set Failed.");
return;
}
if(command === 'item')
{
if(!IsAdmin())
{
SendMessage("You're not supposed to do that. :eye::lips::eye:", 3000);
return;
}
let name = args.join(' ');
let item = items.find(item => { return item.name === name; });
if(!IsFalsy(item))
SendMessage(JSON.stringify(item));
else
SendMessage("Item not found.");
return;
}
if(command === 'testloot')
{
if(!IsAdmin())
{
SendMessage("You're not supposed to do that. :eye::lips::eye:", 3000);
return;
}
let name = args.join(' ');
let item = items.find(item => { return item.name === name; });
if(!IsFalsy(item))
LootItem(null, item);
else
SendMessage("Item not found.");
return;
}
if(debug)
{
if(command === 'c')
{
client.emit('guildMemberAdd', message.member);
}
if(command === 'd')
{
client.emit('guildMemberRemove', message.member);
}
if(command === 'm')
{
SendMessage("Test", 0, false);
SendMessage("Test2");
}
}
});
function UseWalkieTalkie(args)
{
if(args.length < 2)
{
SendMessage("Usage: " + prefix + "walkietalkie(" + prefix + "wt) [channel #] [message]");
return;
}
let channel = Number(args.shift());
let text = args.join(' ');
if(channel < 1 || channel > 99 || IsFalsy(channel))
{
SendMessage("Invalid channel ID (Use: 1 - 97 for walkie-talkie channels, 98 for AM, 99 for FM)");
return;
}
let channelText = channel.toString();
if(channel === 99)
channelText = "FM";
else if(channel === 98)
channelText = "AM";
let radioMessage = "[Radio](" + channelText + ") \"" + text + "\" (" + lastMessage.author.username + ")";
if(radioChannel)
radioChannel.send(radioMessage);
SendMessage(radioMessage);
}
function HasRole(member, inRole)
{
return member.roles.cache.some(role => role.id === inRole.id);
}
function IsAdmin(member)
{
if(!member)
member = lastMessage.member;
return member.permissions.has('ADMINISTRATOR');
}
function IsModerator(member)
{
if(!member)
member = lastMessage.member;
return IsAdmin(member) || HasRole(member, moderatorRole);
}
function PrintTags(tagArray)
{
var outStr = "Tags: ";
for(i in tagArray)
{
if(!IsAdmin() && String(tagArray[i]).startsWith("_"))
continue;
outStr += tagArray[i] + " ";
}
SendMessage(outStr);
}
function LootNothing()
{
SendMessage("You looted **nothing**. (" + `${lastMessage.author}` + ")");
}
function LootItem(tag, forceItem = null)
{
let timer = lootTimerList[lastUser];
if(!IsFalsy(timer))
{
SendMessage("( Loot time left: " + (Math.floor(timer / 60) + 1) + " minutes | " + `${lastMessage.author}` + ")");
return;
}
if(itemNothingChance > 0)
{
if (Random.Range(1,100) <= itemNothingChance)
{
LootNothing();
lootTimerList[lastUser] = lootTimerTime;
return;
}
}
let item = forceItem;
if(IsFalsy(forceItem))
item = GetRandomItemByTag(items, String(tag).toLowerCase(), itemTags);
if(item === null)
{
SendMessage("(Loot Failed, try again.)");
return;
}
let outStr = "You looted ";
let article = "";
if(IsFalsy(item.article))
article = "a ";
else if(item.article != "none")
article = item.article + " ";
if(!IsFalsy(item.money))
outStr += "**" + item.money + Random.Range(item.min, item.max) + " " + item.name + (IsFalsy(item.emoji) ? "" : " " + item.emoji) + "**!";
else if(!IsFalsy(item.packageContents))
outStr += article + "**" + item.name + (IsFalsy(item.emoji) ? "" : " " + item.emoji) + " with " + Random.Range(item.min, item.max) + " " + item.packageContents + "**!";
else if((item.min == 1 && item.max == 1))
outStr += article + "**" + item.name + (IsFalsy(item.emoji) ? "" : " " + item.emoji) + "**!";
else
outStr += "**" + Random.Range(item.min, item.max) + " " + item.name + (IsFalsy(item.emoji) ? "" : " " + item.emoji) + "**!";
if(!IsFalsy(item.part))
{
if(Random.Range(1,100) < partMissingChance)
outStr += " (missing " + item.part + ")";
else
outStr += " (" + item.part + " included)";
}
outStr += " (" + `${lastMessage.author}` + ")";
SendMessage(outStr);
lootTimerList[lastUser] = lootTimerTime;
}
function IsFalsy(thing)
{
let type = typeof(thing);
if(Boolean(thing) === false ||
type === "undefined" ||
(type === "number" && isNaN(thing)) ||
String(thing) === "null" ||
String(thing) === "undefined")
{
return true;
}
return false;
}
function GetRandomItemByTag(array, tag, tagList)
{
//Gather pool
let lootPool = [];
if(IsFalsy(tag))
{
lootPool = array;
}
else
{
if(!IsAdmin())
{
if(String(tag).startsWith("_") || !tagList.includes(tag))
return null;
}
for(i in array)
{
if(array[i].tags.includes(tag))
{
lootPool.push(array[i]);
}
}
}
if(lootPool.length === 0)
return null;
return Random.Weighted(lootPool);
}
function PlayEvent(tag)
{
let timer = eventTimerList[lastUser];
if(!IsFalsy(timer))
{
SendMessage("( Event time left: " + (Math.floor(timer / 60) + 1) + " minutes | " + `${lastMessage.author}` + ")");
return;
}
var event = GetRandomItemByTag(events, String(tag).toLowerCase(), eventTags);
if(event === null)
{
SendMessage("(Event Failed, try again.)");
return;
}
var text;
if(event.min === 1 && event.max === 1)
text = event.text;
else
text = String(event.text).replace("#", Random.Range(event.min, event.max));
text += " (" + `${lastMessage.author}` + ")";
SendMessage(text);
eventTimerList[lastUser] = eventTimerTime;
}
function SendMessage(text, delay = 0, deleteInput = true)
{
lastMessage.channel.send(text)
.then( msg => {
if(deleteInput)
{
lastMessage.delete();
}
if(!isNaN(delay) && delay > 0)
{
setTimeout(() => msg.delete(), delay);
}
})
.catch();
}
function OnSecond()
{
DecrementTimer(lootTimerList);
DecrementTimer(eventTimerList);
}
function DecrementTimer(timer)
{
for(it in timer)
{
if(timer[it] > 0)
--timer[it];
}
}
function IsBlacklisted(channelID)
{
if(blacklist.find(it => it === channelID) != undefined)
{
return true;
}
return false;
}