-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
4241 lines (3351 loc) · 185 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
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// CONSTANTS
//
process.on('uncaughtException', err =>{console.log(err)})
process.on('unhandledRejection', err =>{console.log(err)})
const Discord = require("discord.js");
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [ 'DIRECT_MESSAGES', 'GUILD_PRESENCES',
'GUILD_MEMBERS',
'GUILDS',
'GUILD_VOICE_STATES',
'GUILD_MESSAGES',
'GUILD_MESSAGE_REACTIONS'] });
//const client = new Discord.client();
const mineflayer = require("mineflayer");
const moment = require("moment");
const momenttz = require("moment-timezone");
const fs = require("fs");
const yaml = require("js-yaml");
const math = require("mathjs");
const sm = require("string-similarity");
const ms = require("ms");
const numeral = require("numeral");
const readline = require("readline");
const cn = require("comma-number");
const cron = require("node-cron");
const prettyMilliseconds = require("pretty-ms");
const chalk = require("chalk");
const EasyMatch = require('@notlegend/easymatch');
const sqlite3 = require('sqlite3');
//import { createRequire } from "module";
/*
const { Client, Intents } = require('discord.js');
//import Client from 'discord.js';
//import { Intents } from 'discord.js';
import mineflayer from 'mineflayer';
import moment from 'moment';
import fs from 'fs';
import yaml from 'js-yaml';
//import Math from 'mathjs';
import sm from 'string-similarity';
import ms from 'ms';
import numeral from 'numeral';
import readline from 'readline';
import cn from 'comma-number';
import cron from 'node-cron';
import prettyMilliseconds from 'pretty-ms';
import chalk from 'chalk';
import EasyMatch from '@notlegend/easymatch';
import sqlite3 from 'sqlite3';
//import { Intents } from 'discord.js'
const client = new Client({ intents: [ 'DIRECT_MESSAGES', 'GUILD_MESSAGES' ] });
*/
let db = new sqlite3.Database(__dirname+`/database/database.sqlite`, (err) => {
if (err) return console.error(err.message)
console.log("Database connected!")
})
db.serialize(function() {
db.run("CREATE TABLE IF NOT EXISTS baltop (pos INT, ign TEXT, value TEXT)");
db.run("CREATE TABLE IF NOT EXISTS ftop (pos INT, faction TEXT, value TEXT)");
db.run("CREATE TABLE IF NOT EXISTS verified (discord TEXT, ign TEXT, code TEXT, verified TEXT, deposits INT, walls INT, buffers INT)");
db.run("CREATE TABLE IF NOT EXISTS rotations (user TEXT, rotated TEXT, server TEXT)");
db.run("CREATE TABLE IF NOT EXISTS settigns (feature TEXT, channel TEXT, enabled TEXT, message TEXT DEFAULT 'null')");
});
let bot;
let config = yaml.load(fs.readFileSync(`./config.yml`, "utf8"))
let prefix = config["Discord_Configs"]["prefix"]
// FILE PATHS
let payPal = `./Data/paypal.json`;
let configpath = `./Configs/config.json`;
let permpath = `./Configs/permissions.json`;
let playtimepath = `./Data/playtime.json`;
let verifiedPath = `./Data/verifiedUsers.json`;
let RRPath = `./Data/rotate-roster.json`;
let userStatsPath = `./Data/userStats.json`;
let otherInfoPath = `./Data/otherInfo.json`;
// WALL CHECKS & BUFFER CHECKS
let wallsOverdue = 0
let buffersOverdue = 0
let args = [];
//Rotations
let rotateCheck;
let rotatePlayers = []
let rotateTimeout;
// FTOP
let timeOut;
let ftopMSG;
let ftopReadyToSend = false
let rawFTop = []
// FWHO
let fwhoTimeout;
let fwhoReady = false
let fwhoChannel;
let fWhoData = []
// FWHO ONLINE
let fwhoOnlineTimeout;
let fwhoOnlineReady = false
let fwhoOnlineChannel;
let fWhoOnlineData = []
let fOnlineFac;
//FWHO OFFLINE
let fwhoOfflineTimeout;
let fwhoOfflineReady = false
let fwhoOfflineChannel;
let fWhoOfflineData = []
let fOfflineFac;
// PLAYER ONLINE
let status = []
let player = []
// FLIST
let flistTimeout;
let flistReady = false
let flistChannel;
let flistData = []
let flistSplit = []
let flistFacs = []
let flistOn = []
let flistLand = []
let flistPMP = []
// force
let forceTimeout;
let forceReady = false
let forceChannel;
let forceData = []
// BALANCE
let balanceData;
let balanceReady = false;
let balanceChannel;
let balPerson;
// BALANCE TOP
let balanceTopData = []
let balanceTopReady = false;
let balanceTopChannel;
// WEEWOO
let weewooIsEnabled = false;
// COOLDOWNS
let cooldowns = {}
// MATCHER
let matcher = new EasyMatch(`[`, `]`);
// BOT LOGIN REASON
let botReason = {
host: config["altinfo"]["serverIP"],
port: config["altinfo"]["serverPort"],
username: config["altinfo"]["email"],
password: config["altinfo"]["password"],
version: config["altinfo"]["version"],
auth: "microsoft",
viewDistance: "tiny",
session: reload(`./session.json`).session,
logErrors: false,
plugins : {
blocks : false,
sound : false,
physics : false,
block_actions : false
}
}
//
// EMBED COLORS
//
let maincolor = `#0aa0aa`;
let errorcolor = `#d63b3b`;
//
// FUNCTIONS
//
function rotateLog(rUser, user){
let rotateMsg = `${rUser} was rotated for ${user}`
let writeData = `\r\n${getFormattedTime(new Date())} - ${rotateMsg}`
db.run(`INSERT INTO rotations VALUES('${user}', '${rUser}', '${config.serverip}')`)
// fs.writeFile(`./rotate/rotateLOG${config["altinfo"]["serverIP"]}.txt`, writeData, { flag: 'a+' }, () => {})
}
function rotateEmbed(rotateUser, invUser){
console.log(rotateUser, invUser)
let cfg = reload(configpath)
let rMsg = cfg["configuration"]["Messages"]["rotateMsg"]
rMsg = rMsg.replace(/\[rUser]+/, `**${rotateUser}**`)
rMsg = rMsg.replace(/\[user]+/, `**${invUser}**`)
let embed = new Discord.MessageEmbed()
.setDescription(`${rMsg}`)
.setColor(maincolor)
.setTimestamp();
//SENDING EMBED
client.channels.cache.get(cfg["configuration"]["Channels"]["rotateLogChannel"]).send(embed)
}
function bufferCheck(ign) {
db.all(`SELECT * FROM verified WHERE ign='${ign}'`,async (err,verified)=>{
if(err) return console.log(err);
db.all(`SELECT * FROM channels`, (err,settigns)=>{
if(err) return console.log(err)
if(settings[0].buffer !== 'null'){
let bufferChannel = settings[0].buffer
bufferChannel = client.channels.cache.get(bufferChannel)
if(!bufferChannel) return
let totalBuffer = verified[0].buffers + 1
db.run(`UPDATE verifed SET buffers=${totalBuffer} WHERE ign='${ign}'`)
db.all(`SELECT * FROM verified ORDER BY buffers ASC`,(err,leaderboard)=>{
if(err) return console.log(err)
for(i in leaderboard){
if(leaderboard[i].ign == ign){
let bufferEmbed = new Discord.MessageEmbed()
.setColor(maincolor)
.setTitle(`**Buffers have been checked!**`)
.addField(`**Discord:**`,`<@${userDiscord}>`,true)
.addField(`**In game name:`,`\`${ign}\``,true)
.addField(`Checked at:`,`${getFormattedTime(new Date())}`,true)
.setDescription(`**Total checks:** ${totalAmount} - #${leaderboard[i]}`)
.setThumbnail(`https://minotar.net/helm/${ign}/190.png`)
bufferChannel.send(bufferEmbed)
}
}
})
}
})
});
}
function weeWoo(ign) {
let verifiedDB = reload(verifiedPath)
let maincfg = reload(configpath)
let userDiscord = client.users.cache.get(verifiedDB[ign]["Discord"])
let wallChannel
if(maincfg["configuration"]) {
if(maincfg["configuration"]["Channels"]) {
if(maincfg["configuration"]["Channels"]["wallChannel"]) {
wallChannel = maincfg["configuration"]["Channels"]["wallChannel"]
} else return
} else return
} else return
wallChannel = client.channels.cache.get(wallChannel)
if(!wallChannel) return
let roles = config["ingame_configs"]["roles_toTag"]
let realRoles = []
let msg = {
"guild" : client.guilds.get(config["Discord_Configs"]["main_guild"])
}
roles.cache.forEach(lolxd => {
realRoles.push(getRole(msg, lolxd) == false ? `Not a role [${lolxd}]` : getRole(msg, lolxd).toString())
})
let message = `${realRoles.join(" ")}`
wallChannel.send(message).then(res => {
res.delete()
})
wallChannel.send(message).then(res => {
res.delete()
})
wallChannel.send(message).then(res => {
res.delete()
let embed = new Discord.MessageEmbed()
.setColor(errorcolor)
.setDescription(`:boom: WeeWoo has been set off by ${userDiscord}`)
res.channel.send(embed)
})
if(maincfg["configuration"]) {
if(maincfg["configuration"]["Messages"]) {
if(maincfg["configuration"]["Messages"]["weewooMsg"]) {
if(bot) {
if(config["ingame_configs"]["ingame_features_isEnabled"] == false) return
if(config["ingame_configs"]["weewoo_ingame"] == false) return
bot.chat(maincfg["configuration"]["Messages"]["weewooMsg"])
}
}
}
}
}
function wallCheck(ign) {
db.all(`SELECT * FROM verified WHERE ign='${ign}'`,async (err,verified)=>{
if(err) return console.log(err);
db.all(`SELECT * FROM channels`, (err,settigns)=>{
if(err) return console.log(err)
if(settings[0].walls !== 'null'){
let bufferChannel = settings[0].walls
bufferChannel = client.channels.cache.get(bufferChannel)
if(!bufferChannel) return
let totalBuffer = verified[0].buffers + 1
db.run(`UPDATE verifed SET walls=${totalBuffer} WHERE ign='${ign}'`)
db.all(`SELECT * FROM verified ORDER BY walls ASC`,(err,leaderboard)=>{
if(err) return console.log(err)
for(i in leaderboard){
if(leaderboard[i].ign == ign){
let bufferEmbed = new Discord.MessageEmbed()
.setColor(maincolor)
.setTitle(`**Walls have been checked!**`)
.addField(`**Discord:**`,`<@${userDiscord}>`,true)
.addField(`**In game name:`,`\`${ign}\``,true)
.addField(`Checked at:`,`${getFormattedTime(new Date())}`,true)
.setDescription(`**Total checks:** ${totalAmount} - #${leaderboard[i]}`)
.setThumbnail(`https://minotar.net/helm/${ign}/190.png`)
bufferChannel.send(bufferEmbed)
}
}
})
}
})
});
}
function cooldown(user, type, lengthMS) {
if(!cooldowns[type]) {
cooldowns[type] = {}
}
cooldowns[type][user] = {
isValidCooldown : true,
cooldownSet : new Date()
}
setTimeout(() => {
cooldowns[type][user]["isValidCooldown"] = false
}, lengthMS)
}
function getRandomChars(amount) {
let thing = []
for(let i = 0; i < amount; i++) {
let characters = `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`
thing.push(characters[Math.floor(Math.random()*characters.length)])
}
return thing.join("")
}
function convertToPage(message, dataArray, page, title, entitiesPerPage) {
let pageData = []
let perPage;
if(!entitiesPerPage || isNaN(entitiesPerPage)) perPage = 20
else perPage = entitiesPerPage
let numb1 = perPage/2
let dataLength = dataArray.length
let calc1 = Math.ceil(dataLength / numb1)
let calc2 = calc1 * numb1
let totalpages = math.round(`${eval(calc2 / perPage)}`)
if(totalpages < 1) totalpages = 1
let currentpage = 1
if(!page || isNaN(parseInt(page))) currentpage = 1
else currentpage = parseInt(page)
if(currentpage > totalpages) currentpage = totalpages
if(currentpage == 1) {
dataArray.forEach(player => {
if(dataArray.indexOf(player) < perPage) {
pageData.push(`${player}`)
}
})
}
else {
let newthing = dataArray.slice(eval(perPage*(currentpage-1)))
newthing.forEach(player => {
if(newthing.indexOf(player) < perPage) {
pageData.push(`${player}`)
}
})
}
let embed = new Discord.MessageEmbed()
.setColor(maincolor)
.setDescription(`${title}\nPage ${currentpage}/${totalpages}\n \n ${pageData.join("\n")}`)
//.addField(title, `${pageData.join("\n")}`, true)
.setTimestamp()
.setTitle(title)
if(dataArray.length === 0) return message.channel.send(new Discord.MessageEmbed().setColor(errorcolor).setDescription(`:x: An error occurred recieving/parsing the data`))
//console.log(embed)
message.channel.send(({ embeds: [embed] }))
}
function botMsg(chat) {
if(chat.includes("Total server value:") || chat.toLowerCase().includes("server total")) {
} else
if(chat.includes("$")) {
if(chat.split(/ +/g).length > 8) return
let ftopReplaced = chat.trim().split("Total server value:").join("").split("Total:").join("").split("$ ").join("").split("ServerTotal").join("")
let ftopRaw = parseFTop(ftopReplaced)
if(ftopRaw) {
rawFTop.push(ftopRaw)
timeOut = setTimeout(() => {
if(ftopReadyToSend == false) return
if(ftopMSG == undefined) return
let fTop = reload(`./Data/ftop.json`)
let ftopFactions = []
let ftopValues = []
rawFTop.forEach(element => {
let ftopSplit = element.split(/ +/)
let ftopValueNumber = parseInt(ftopSplit[2].replace(/[\$€£¥₩,]+/g, ""))
if(fTop[ftopSplit[1]]) {
let difference = ftopValueNumber - fTop[ftopSplit[1]]
fTop[ftopSplit[1]] = ftopValueNumber
ftopFactions.push(`**${ftopSplit[0]}** ${ftopSplit[1]}`)
ftopValues.push(`${ftopSplit[2]} \`[${ftopValueNumber < fTop[ftopSplit[1]] ? `-` : `+`}$${cn(Math.abs(difference))}]\``)
} else {
let difference = `N/A`
fTop[ftopSplit[1]] = ftopValueNumber
ftopFactions.push(`**${ftopSplit[0]}** ${ftopSplit[1]}`)
ftopValues.push(`${ftopSplit[2]} \`[${difference}]\``)
}
fs.writeFile(`./Data/ftop.json`, ``, (err) => {
fs.writeFile(`./Data/ftop.json`, JSON.stringify(fTop, null, 4), (err) => {});
});
})
let embed = new Discord.MessageEmbed()
.setColor(maincolor)
.setTitle(`Factions Top - \`${config["altinfo"]["serverIP"]}\``)
.addField(`Faction`, ftopFactions.join("\n"), true)
.addField(`Value`, ftopValues.join("\n"), true)
.setFooter(`${config["altinfo"]["serverIP"]}`)
.setTimestamp(new Date())
ftopMSG.send(embed)
rawFTop = []
ftopMSG = undefined
}, 250)
}
}
if(fwhoReady == true) {
fWhoData.push(chat)
if(chat.includes(config["ingame_configs"]["fwho_stopArg"])) fwhoReady = false
fwhoTimeout = setTimeout(() => {
if(fwhoChannel == undefined) return
for(let i = 0; i < fWhoData.length; i++) {
let fwhoThing = fWhoData[i].split("***").join("⭑⭑⭑").split("**").join("⭑⭑").split("*").join("⭑").split("_").join("-")
if(fwhoThing.includes(": ")) {
fwhoThing = fwhoThing.split(": ").join(":** ")
fwhoThing = "**" + fwhoThing
}
fWhoData[i] = fwhoThing
}
let cleanContent = fWhoData.join("\n")
if(cleanContent.length < 2048) {
let fWho = new Discord.MessageEmbed()
.setColor(maincolor)
.setTitle(`F Who:`)
.setDescription(cleanContent)
.setFooter(`${config["altinfo"]["serverIP"]}`)
.setTimestamp(new Date())
fwhoChannel.send(fWho)
fWhoData = []
fwhoReady = false
fwhoChannel = undefined
} else {
let splitSections = []
function cleanTheContent() {
splitSections.push(cleanContent.substr(0, 2048))
cleanContent = cleanContent.slice(0, 2048)
}
while(cleanContent.length > 2048) {
cleanTheContent()
}
let fWho = new Discord.MessageEmbed()
.setColor(maincolor)
.setTitle(`Factions Who`)
.setDescription(splitSections[0])
fwhoChannel.send(fWho)
for(let i = 1; i < splitSections.length; i++) {
let newR = new Discord.MessageEmbed()
.setColor(maincolor)
.setDescription(splitSections[i])
if(i === splitSections.length-1) newR.setFooter(`${config["altinfo"]["serverIP"]}`).setTimestamp(new Date())
fwhoChannel.send(newR)
}
fWhoData = []
fwhoReady = false
fwhoChannel = undefined
}
}, 250)
}
if(rotateCheck == true){
fWhoOnlineData.push(chat)
if(chat.includes(config["ingame_configs"]["fwho_stopArg"])) rotateCheck = false
fwhoOnlineTimeout = setTimeout(() => {
let availablePlayers = []
let onlinePlayers = []
for(let i in bot.players) {availablePlayers.push(i)}
fWhoOnlineData.forEach(ee => {
if(ee.includes(config["ingame_configs"]["fwho_stopArg"])) return fWhoOnlineData.splice(fWhoOnlineData.indexOf(ee), fWhoOnlineData.length-1)
let split = ee.split(/\ +/g)
for(let i = 0; i < split.length; i++) {
let replaced = split[i].replace(/[\*\+\-\ \,✯\➎\➍\➌\➋\➊]+/g, "").replace(/[,***]+/, "").replace(/\*+/, "")
if(availablePlayers.includes(replaced) && !onlinePlayers.includes(`${replaced}`)) rotatePlayers.push(`${replaced}`);
}
})
},300)
}
if(fwhoOnlineReady == true) {
fWhoOnlineData.push(chat)
if(chat.includes(config["ingame_configs"]["fwho_stopArg"])) fwhoOnlineReady = false
fwhoOnlineTimeout = setTimeout(() => {
if(fwhoOnlineChannel == undefined) return
let availablePlayers = []
let onlinePlayers = []
for(let i in bot.players) {availablePlayers.push(i)}
fWhoOnlineData.forEach(ee => {
if(ee.includes(config["ingame_configs"]["fwho_stopArg"])) return fWhoOnlineData.splice(fWhoOnlineData.indexOf(ee), fWhoOnlineData.length-1)
let split = ee.split(/\ +/g)
for(let i = 0; i < split.length; i++) {
let replaced = split[i].replace(/[\*\+\-\ \,✯\➎\➍\➌\➋\➊]+/g, "").replace(/[,***]+/, "").replace(/\*+/, "")
if(availablePlayers.includes(replaced) && !onlinePlayers.includes(`${replaced}`)) onlinePlayers.push(`${replaced}`)
}
})
if(onlinePlayers.length == 0) {fwhoOnlineChannel.send(new Discord.MessageEmbed()
.setColor(errorcolor)
.setDescription(`:x: There is no one online in ${fOnlineFac}`))
}else if(onlinePlayers.length == 1)
{let fwho = new Discord.MessageEmbed()
.setColor(maincolor)
.setDescription(`There is __${onlinePlayers.length}__ player online in ${fOnlineFac}: **${onlinePlayers}** `)
fwhoOnlineChannel.send(fwho);
}
else {
let fWho = new Discord.MessageEmbed()
.setColor(maincolor)
.setDescription(`There are __${onlinePlayers.length}__ players online in ${fOnlineFac}: **${onlinePlayers.join(", ")}** `)
.setTimestamp(new Date())
fwhoOnlineChannel.send(fWho);
}
fWhoOnlineData = []
fwhoOnlineReady = false
fwhoOnlineChannel = undefined
fOnlineFac = undefined
}, 300)
}
if(flistReady == true) {
// FLIST func
let tempData = chat.replace( /[()\\\/]/g, " " )
tempData = tempData.replace(/[:,-]+/g, '');
tempData = tempData.replace(/\ +/g," ")
if(!tempData.includes('Power')) return
flistSplit = tempData.split(" ")
flistFacs.push(`**${flistSplit[0]}**`+`\`[${flistSplit[1]}|${flistSplit[2]}]\``)
flistLand.push(`${flistSplit[7]} claims`)
flistPMP.push(`${flistSplit[8]} | ${flistSplit[9]}`)
flistData.push(tempData)
flistTimeout = setTimeout(() => {
if(flistChannel == undefined) return
let fWho = new Discord.MessageEmbed()
.setColor(maincolor)
.setTitle(`Factions List`)
.addField(`**Faction:**`,`${flistFacs.join("\n")}`,true)
.addField(`**Claims:**`,`${flistLand.join("\n")}`,true)
.addField(`**Power | Max:**`,`${flistPMP.join("\n")}`,true)
.setFooter(`${config["altinfo"]["serverIP"]}`)
.setTimestamp(new Date())
flistChannel.send(fWho)
flistData = []
flistReady = false
flistChannel = undefined
flistFacs = []
flistOn = []
flistLand = []
flistPMP = []
}, 350)
}
if(forceReady == true) {
forceData.push(chat)
forceTimeout = setTimeout(() => {
if(forceChannel == undefined) return
let fWho = new Discord.MessageEmbed()
.setColor(maincolor)
.setTitle(`force`)
.setDescription("```" + forceData.join("\n") + "```")
.setFooter(`${config["altinfo"]["serverIP"]}`)
.setTimestamp(new Date())
forceChannel.send(fWho)
forceData = []
forceReady = false
forceChannel = undefined
}, 350)
}
if(balanceReady == true) {
if(chat.includes("$")) {
balanceData = chat
let parseBal;
if(balanceChannel == undefined) return
balanceData = balanceData.split(' ')
balanceData.forEach(split => {
if(split.includes("$")){
parseBal = split
}
})
let bal = new Discord.MessageEmbed()
.setColor(maincolor)
.setTitle(`:dollar:`)
.setDescription(`**${balPerson}\'s balance:** ${parseBal}`)
.setFooter(`${config["altinfo"]["serverIP"]}`)
.setTimestamp(new Date())
balanceChannel.send(bal)
balanceData = undefined
balanceReady = false
balanceChannel = undefined
balPerson = undefined
}
}
if(balanceTopReady == true) {
if(chat.includes("$")) {
if(chat.includes("Server Total:")) {
} else if(chat.includes("Server Total")) {
} else {
if(chat.split(/ +/g).length > 8) return
let balReplaced = chat.split("Server Total").join("").split("Total:").join("").split("$ ").join("").split("ServerTotal").join("").replace(/\[([^\]]+)]/g, "").replace(/\(([^)]+)\)/g, "").split("*").join("").split("~").join("")
let balRaw = parseFTop(balReplaced)
if(balRaw) {
balanceTopData.push(balRaw)
timeOut = setTimeout(() => {
if(balanceTopReady == false) return
if(balanceTopChannel == undefined) return
let bTop = reload(`./Data/balancetop.json`)
let bTopUsers = []
let bTopValues = []
let bTopChange = []
balanceTopData.forEach(element => {
let balSplit = element.split(/ +/)
let ftopValueNumber = parseInt(balSplit[2].replace(/[\$€£¥₩,]+/g, ""))
if(bTop[balSplit[1]]) {
let difference = ftopValueNumber - bTop[balSplit[1]]
bTop[balSplit[1]] = ftopValueNumber
bTopUsers.push(`**${balSplit[0]} ${balSplit[1]}**`)
bTopValues.push(`${balSplit[2]} \`[${ftopValueNumber < bTop[balSplit[1]] ? `-` : `+`}$${cn(Math.abs(difference))}]\``)
} else {
let difference = `N/A`
bTop[balSplit[1]] = ftopValueNumber
bTopUsers.push(`**${balSplit[0]}** ${balSplit[1]}`)
bTopValues.push(`${balSplit[2]} \`[${difference}]\``)
}
fs.writeFile(`./Data/balancetop.json`, ``, (err) => {
fs.writeFile(`./Data/balancetop.json`, JSON.stringify(bTop, null, 4), (err) => {});
});
})
let embed = new Discord.MessageEmbed()
.setColor(maincolor)
.setTitle(`Balance Top - \`${config["altinfo"]["serverIP"]}\``)
.addField(`Users`, bTopUsers.join("\n"), true)
.addField(`Balance`, bTopValues.join("\n"), true)
.setFooter(`${config["altinfo"]["serverIP"]}`)
.setTimestamp(new Date())
balanceTopChannel.send(embed)
balanceTopData = []
balanceTopChannel = undefined
balanceTopReady = false
}, 60)
}
}
}
}
}
function botEvent(mc) {
let serverchatToSend = []
setInterval(() => {
if(serverchatToSend.length == 0) return
let cfg = reload(configpath)
if(!cfg["configuration"]) return
else if(!cfg["configuration"]["Channels"]) return
else if(!cfg["configuration"]["Channels"]["serverchatChannel"]) return
if(!client.channels.cache.get(cfg["configuration"]["Channels"]["serverchatChannel"])) return
let channel = client.channels.cache.get(cfg["configuration"]["Channels"]["serverchatChannel"])
if(config["ingame_configs"]["ingame_features_isEnabled"] != true) return
if(cfg["configuration"]["Switches"]["serverchat"] == false) return
channel.send(`**\`${serverchatToSend.join("\n")}\`**`).then(() => {
serverchatToSend = []
}).catch(err => {
})
}, 2456)
mc.on("message", async message => {
let chat = `${message}`;
let type;
if(chat.includes("to your faction") || chat.includes("has been received from") || chat.includes("from your faction")) {
if(chat.match(/(\$|€|£|¥|₩)[ ]*([1-9][0-9]*((,| )[0-9]{3})*|0)(\.[0-9]+)?[ ]*(B|b|M|m|K|k)?/g)) {
let moneyAmount = chat.match(/(\$|€|£|¥|₩)[ ]*([1-9][0-9]*((,| )[0-9]{3})*|0)(\.[0-9]+)?[ ]*(B|b|M|m|K|k)?/g)[0]
if(mc) {
if(mc.players != null) {
let players = [];
for(let i in mc.players) {players.push(i);}
let playersInMessage = [];
let msgSplit = chat.trim().split(/ +/g)
for(let i = 0; i < msgSplit.length; i++) {
for(let j = 0; j < players.length; j++) {
let currentPlayer = players[j];
if(msgSplit[i].includes(currentPlayer + ":")) return
if(msgSplit[i].includes(currentPlayer)) playersInMessage.push(currentPlayer)
}
}
if(playersInMessage.length > 1) return
let rawmoneyamount = parseInt(moneyAmount.replace(/[,$]+/g, ""))
if(config["ingame_configs"]["ingame_features_isEnabled"] != true) return
if(config["ingame_configs"]["ingame_bank"] != true) return
if(rawmoneyamount < config["ingame_configs"]["min_bank_deposit"]) return
let cfg = reload(configpath)
if(!cfg["configuration"]) return
if(!cfg["configuration"]["Channels"]) return
if(!cfg["configuration"]["Channels"]["bankChannel"]) return
let bankChannel = client.channels.cache.get(cfg["configuration"]["Channels"]["bankChannel"])
if(!bankChannel) return
if(chat.includes("to your faction") || chat.includes("has been received from")) type = "deposited"; else type = "withdrew"
let embed = new Discord.MessageEmbed()
.setColor(maincolor)
.setDescription(`:moneybag: **${playersInMessage[0]}** has ${type} $${cn(rawmoneyamount)}`)
bankChannel.send(embed)
let cgg = config["ingame_configs"]
if(cgg["ingame_features_isEnabled"] == true) {
if(cgg["bank_msgIngame"] == true) {
if(bot) {
if(cfg["configuration"]) {
if(cfg["configuration"]["Messages"]) {
let msg = cfg["configuration"]["Messages"]["bankMsg"].replace(/\[type]/, type).replace(/\[ign]/, playersInMessage[0]).replace(/\[money]/, cn(rawmoneyamount))
bot.chat(msg)
}
}
}
}
}
if(!chat.includes(chat.includes("from your faction"))) {
let pi = reload(userStatsPath)
let verified = reload(verifiedPath)
if(verified[playersInMessage[0]]) {
console.log(verified[playersInMessage[0]])
if(verified[playersInMessage[0]]["isVerified"] == false) return
if(pi[playersInMessage[0]]) {
pi[playersInMessage[0]]["totalDeposited"] = pi[playersInMessage[0]]["totalDeposited"]+rawmoneyamount
}else pi[playersInMessage[0]] = {
totalDeposited : rawmoneyamount
}
fs.writeFile(userStatsPath, ``, (err) => {
fs.writeFile(userStatsPath, JSON.stringify(pi, null, 2), (err) => {});
});
}}
}
}
}
}
})
mc.on("respawn", async b =>{
mc.chat(config["altinfo"]["joinCMD"])
})
mc.on("message", async message => {
let chat = `${message}`
chat = chat.replace(/[\*\+\-\,✯\➎\➍\➌\➋\➊]+/g, "").replace(/[,***]+/, "").replace(/\*+/, "")
let cfg = reload(configpath)
if(!cfg["configuration"]) return
else if(!cfg["configuration"]["Messages"]) return
serverchatToSend.push(chat)
})
mc.on("login", () => {
mc.chat(config["altinfo"]["joinCMD"])
console.log(` \n [${mc.username}] Starting to listen to events!\n `)
setTimeout(() => {bot.chat("/f c f")}, 13000)
})
mc.on("kicked", async(reason) => {
console.log(` \n [${mc.username}] Kicked for ${reason}. Relogging in 20 seconds.\n `)
mc.end()
})
mc.on("end", async() => {
setTimeout(() => {
bot = mineflayer.createBot(botReason)
fs.writeFileSync('./bot', JSON.stringify(bot, null, 4));
botEvent(bot)
}, 20000)
})
mc.on("message", async(message) => {
let chat = `${message}`
botMsg(chat)
if(config["ingame_configs"]["consoleChat"] == true) {
let messageColor = []
let fullMessage = ``
if(message["extra"]) {
message["extra"].forEach(ee => {
messageColor.push([ee["color"], ee["text"]])
let color = ee["color"]
let text = ee["text"]
switch(color) {
case "dark_red":
fullMessage = fullMessage + chalk.hex('#AA0000')(text)
break;
case "red":
fullMessage = fullMessage + chalk.hex('#FF5555')(text)
break;
case "gold":
fullMessage = fullMessage + chalk.hex('#FFAA00')(text)
break;
case "yellow":
fullMessage = fullMessage + chalk.hex('#FFFF55')(text)
break;
case "dark_green":
fullMessage = fullMessage + chalk.hex('#00AA00')(text)
break;
case "green":
fullMessage = fullMessage + chalk.hex('#55FF55')(text)
break;
case "aqua":
fullMessage = fullMessage + chalk.hex('#55FFFF')(text)
break;
case "dark_aqua":
fullMessage = fullMessage + chalk.hex('#00AAAA')(text)
break;
case "dark_blue":
fullMessage = fullMessage + chalk.hex('#0000AA')(text)
break;
case "blue":
fullMessage = fullMessage + chalk.hex('#5555FF')(text)
break;
case "light_purple":
fullMessage = fullMessage + chalk.hex('#FF55FF')(text)
break;
case "dark_purple":
fullMessage = fullMessage + chalk.hex('#AA00AA')(text)
break;
case "white":
fullMessage = fullMessage + chalk.hex('#FFFFFF')(text)
break;
case "gray":
fullMessage = fullMessage + chalk.hex('#AAAAAA')(text)
break;
case "dark_gray":
fullMessage = fullMessage + chalk.hex('#555555')(text)
break;
case "black":
fullMessage = fullMessage + chalk.hex('#000000')(text)
break;
default:
fullMessage = fullMessage + text
}
})
console.log(fullMessage.replace(/§([0-9]|a|b|i|k|d|f|e|l|n|c|m|r|o)/gi, ""))
} else {
console.log(chat)
}
}
})
mc.on("message", async msg => {
let message = `${msg}`
let verified = reload(verifiedPath)
let cfg = reload(configpath)
let users = []
for(let i in mc.players) {users.push(i)}
let splitmsg = message.split(/ +/g)
let user
for(let i = 0; i < splitmsg.length; i++) {
if(users.includes(splitmsg[i].replace(/[:<>()+*✯-\➎\➍\➌\➋\➊]+/g, ""))) {
user = splitmsg[i].replace(/[:<>()+*✯-\➎\➍\➌\➋\➊]+/g, "")
userarg = i
splitmsg[i] = splitmsg[i].replace(/[:<>()+*✯-\➎\➍\➌\➋\➊]+/g, "")
break;
}
}
if(user) {