-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.js
2007 lines (1956 loc) · 82.5 KB
/
script.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
/*
Client Scripts
Make sure you check ~commandslist for a list of commands
Safe Scripts are pretty much required to be off
Currently needs PO Version 2.0.10 to run correctly
Report bugs here: http://pokemon-online.eu/forums/showthread.php?15079 and read over the thread to check for anything
*/
//these things below shouldn't be touched unless you know what you're doing~
/*jshint "laxbreak":true,"shadow":true,"undef":true,"evil":true,"trailing":true,"proto":true,"withstmt":true*/
/*global sys,client */
var script_url = "https://raw.githubusercontent.com/CrystalMoogle/PO-User-Scripts/master/"; //where the script is stored
var scriptsFolder = "ClientScripts"; //replace with undefined if you don't want a folder
var global = this;
var poScript, Script_Version, initCheck, repoFolder, etext, tgreentext, flash, autoresponse, friendsflash, checkversion, clientbotname, clientbotcolour, clientbotstyle, greentext, fontcolour, fonttype, fontsize, fontstyle, commandsymbol, hilight, armessage, arstart, arend, artype, stalkwords, friends, ignore, logchannel, fchannel, auth_symbol, auth_style, src, Utilities, Commands, autoidle, nochallenge, Plugins, userplugins, weightData, playerswarn, youtube;
var pluginFiles = [];
String.prototype.format = function () {
var formatted = this;
for (var i = 0; i < arguments.length; i++) {
var regexp = new RegExp('\\{' + i + '\\}', 'gi');
formatted = formatted.replace(regexp, arguments[i]);
}
return formatted;
};
Utilities = ({
loadSettings: function loadSettings(json, defaultUsed, silent) {
cleanFile('memory.json');
try {
var settings;
if (json === undefined) {
if (sys.getFileContent('memory.json') === "") {
this.loadDefaultSettings();
this.saveSettings();
client.printHtml('<timestamp/> <b>Type ~commandslist to get started!</b>'); //first time use, or near abouts
return;
}
settings = JSON.parse(sys.getFileContent('memory.json'));
}
else {
settings = JSON.parse(json);
}
etext = settings.etext;
nochallenge = settings.nochallenge;
autoidle = settings.autoidle;
tgreentext = settings.tgreentext;
flash = settings.flash;
youtube = settings.youtube;
autoresponse = settings.autoresponse;
friendsflash = settings.friendsflash;
checkversion = settings.checkversion;
clientbotname = settings.clientbotname;
clientbotcolour = settings.clientbotcolour;
clientbotstyle = settings.clientbotstyle;
greentext = settings.greentext;
fontcolour = settings.fontcolour;
fonttype = settings.fonttype;
fontsize = settings.fontsize;
fontstyle = settings.fontstyle;
commandsymbol = settings.commandsymbol;
hilight = settings.hilight;
armessage = settings.armessage;
arstart = settings.arstart;
arend = settings.arend;
artype = settings.artype;
userplugins = settings.userplugins;
stalkwords = settings.stalkwords;
friends = settings.friends;
ignore = settings.ignore;
logchannel = settings.logchannel;
fchannel = settings.fchannel;
auth_symbol = settings.auth_symbol;
auth_style = settings.auth_style;
if (silent === false) {
sendBotMessage("Settings loaded");
}
}
catch (e) {
sendBotMessage("Error with your settings: " + e);
if (defaultUsed !== true) {
sendBotMessage("Loading default settings");
this.loadDefaultSettings();
}
}
},
loadDefaultSettings: function loadDefaultSettings() {
var json = {
"etext": false,
"autoidle": false,
"nochallenge": false,
"tgreentext": false,
"flash": true,
"autoresponse": false,
"friendsflash": false,
"checkversion": false,
"youtube": false,
"clientbotname": "+ClientBot",
"clientbotcolour": "#3DAA68",
"clientbotstyle": "<b>",
"greentext": "#789922",
"fontcolour": "#000000",
"fonttype": "",
"fontsize": 3,
"fontstyle": "",
"commandsymbol": "~",
"hilight": "BACKGROUND-COLOR: #ffcc00",
"armessage": "I am currently unavailable!",
"arstart": "",
"arend": "",
"artype": "command",
"userplugins": [],
"stalkwords": [],
"friends": [],
"ignore": [],
"logchannel": [],
"fchannel": [],
"auth_symbol": {
"0": "",
"1": "+",
"2": "+",
"3": "+",
"4": ""
},
"auth_style": {
"0": "<b>",
"1": "<b><i>",
"2": "<b><i>",
"3": "<b><i>",
"4": "<b>"
}
};
this.loadSettings(JSON.stringify(json), true);
},
saveSettings: function saveSettings() {
var settings = {};
settings.etext = etext;
settings.autoidle = autoidle;
settings.nochallenge = nochallenge;
settings.tgreentext = tgreentext;
settings.flash = flash;
settings.youtube = youtube;
settings.autoresponse = autoresponse;
settings.friendsflash = friendsflash;
settings.checkversion = checkversion;
settings.clientbotname = clientbotname;
settings.clientbotcolour = clientbotcolour;
settings.clientbotstyle = clientbotstyle;
settings.greentext = greentext;
settings.fontcolour = fontcolour;
settings.fonttype = fonttype;
settings.fontsize = fontsize;
settings.fontstyle = fontstyle;
settings.commandsymbol = commandsymbol;
settings.hilight = hilight;
settings.armessage = armessage;
settings.arstart = arstart;
settings.arend = arend;
settings.artype = artype;
settings.userplugins = userplugins;
settings.stalkwords = stalkwords;
settings.friends = friends;
settings.ignore = ignore;
settings.logchannel = logchannel;
settings.fchannel = fchannel;
settings.auth_symbol = auth_symbol;
settings.auth_style = auth_style;
if(!sys.isSafeScripts()) {
sys.writeToFile('memory.json', JSON.stringify(settings));
}
},
eliminateDuplicates: function eliminateDuplicates(arr) { //stolen from http://dreaminginjavascript.wordpress.com/2008/08/22/eliminating-duplicates/ eliminates any duplicates that are in an array
var len = arr.length;
var out = [];
var obj = {};
for (var i = 0; i < len; i++) {
obj[arr[i]] = 0;
}
for (var i in obj) {
if (obj.hasOwnProperty(i)) {
out.push(i);
}
}
return out;
},
isPunct: function isPunct(i) {
return (this.isGraph(i) && !(this.isAlnum(i)));
},
isGraph: function isGraph(i) {
var myCharCode = i.charCodeAt(0);
return (myCharCode > 32) && (myCharCode < 127);
},
isAlnum: function isAlnum(i) {
return (this.isDigit(i) || this.isAlpha(i));
},
isDigit: function isDigit(i) {
var myCharCode = i.charCodeAt(0);
return (myCharCode > 47) && (myCharCode < 58);
},
isAlpha: function isAlpha(i) {
var myCharCode = i.charCodeAt(0);
return ((myCharCode > 64) && (myCharCode < 91)) || ((myCharCode > 96) && (myCharCode < 123));
},
stripHTML: function stripHTML(string) {
var regex = /(<([^>]+)>)/ig;
string = string.replace(regex, "");
return string;
},
html_escape: function html_escape(text) { //escapes any characters that won't appear correctly in HTMLmessages
var m = String(text);
if (m.length > 0) {
var amp = "&am" + "p;";
var lt = "&l" + "t;";
var gt = "&g" + "t;";
return m.replace(/&/g, amp)
.replace(/</g, lt)
.replace(/>/g, gt);
}
else {
return "";
}
},
tagend: function tagend(string) { //automatically creates an end tag from a html tagsent to it
if (string === undefined) {
return "";
}
return string.replace(/</g, "</");
},
checkVersion: function checkVersion(version) {
var currentVersion = sys.version().replace(/\./g, "").length === 4 ? sys.version().replace(/\./g, "") : sys.version().replace(/\./g, "")*10;
return currentVersion >= version;
}
});
Commands = ({
commandHandler: function commandHandler(command, commandData, channel) {
if (command === "commandlist" || command === "commandslist") {
sys.stopEvent();
sendMessage("*** Client Commands ***");
sendMessage(commandsymbol + "commandsymbol symbol: Allows you to change the command symbol");
sendMessage(commandsymbol + "idle on/off: Allows you to turn auto-idle on/off");
sendMessage(commandsymbol + "flash on/off:channel: Allows you to turn flashes on/off. Channel is an optional parameter to turn flashes off for one channel");
sendMessage(commandsymbol + "ignorechallenges on/off: Allows you to ignore all challenges without idling");
sendMessage(commandsymbol + "ytlinks on/off: Converts Youtube links into their titles (Warning: May cause lag)");
sendMessage(commandsymbol + "goto channel: Allows you to switch to that channel (joins if you're not in that channel)");
sendMessage(commandsymbol + "reconnect: Allows you to reconnect to the server");
sendMessage(commandsymbol + "pm name: Allows you to start a PM with a user");
sendMessage(commandsymbol + "changename: Allows you to change your name");
sendMessage(commandsymbol + "stalkwords: Allows you to view your current stalkwords");
sendMessage(commandsymbol + "[add/remove]stalkword word: Allows you to add/remove stalkwords");
sendMessage(commandsymbol + "logchannels: Allows you to view your log channels");
sendMessage(commandsymbol + "[add/remove]logchannel channel: Allows you to add/remove channels from the channels you log");
sendMessage(commandsymbol + "pokedex pokemon:level:gen: Shows you details about a pokemon. Gen/level are optional parameters to view the pokemon in different gens/at different levels");
sendMessage(commandsymbol + "formatcommands: Shows the formatting comands (e.g. enriched text, auth symbols)");
sendMessage(commandsymbol + "scriptcommands: Shows commands related to the scripts (e.g. versions, updatescripts)");
sendMessage(commandsymbol + "socialcommands: Shows commands related to social aspects (e.g. friendslist, ignorelist)");
sendMessage(commandsymbol + "fontcommands: Shows you the font command details");
var pluginhelps = getPlugins("help-string");
for (var module in pluginhelps) {
if (pluginhelps.hasOwnProperty(module)) {
var help = typeof pluginhelps[module] === "string" ? [pluginhelps[module]] : pluginhelps[module];
for (var i = 0; i < help.length; ++i) {
sendMessage(commandsymbol + help[i]);
}
}
}
sendMessage(commandsymbol + "damagecalc [s]atk:move power:modifier:[s]def:HP: Basic damage calculator");
sendMessage("Explanation: [s]atk is the attacking pokémon's exact stat (not base), move power is the move's base power, modifier is any modifiers that need to be added (e.g. life orb is 1.3), HP/[s]def is the defending pokémon's exact HP/Def stats (not base)");
sendMessage("Example: " + commandsymbol + "damagecalc 100:100:1.3:100:100 will show you the result of a pokémon with 100 [s]atk, with Life Orb using a 100bp move against a pokémon with 100HP/[s]def");
sendMessage("");
sendBotMessage('If you ever forget your command symbol, type "reset symbol" (no quotes) to revert it back to "~"');
return;
}
if (command === "formatcommands") {
sys.stopEvent();
sendMessage("*** Formatting Commands ***");
sendMessage(commandsymbol + "etext on/off: Allows you to turn Enriched text on/off");
sendMessage(commandsymbol + "greentext on/off: Allows you to turn greentext on/off");
sendMessage(commandsymbol + "greentextcolo(u)r colour: Allows you to change your greentext colour");
sendMessage(commandsymbol + "highlight colour: Allows you to change the colour of the highlight when flashed");
sendMessage(commandsymbol + "changebotcolo(u)r colour: Allows you to change the bot's (client and server) colour");
sendMessage(commandsymbol + "changebotname name: Allows you to change clientbot's name");
sendMessage(commandsymbol + "changebotstyle htmltag: Allows you to change the style of the client bot (start tags only)");
sendMessage(commandsymbol + "resetbot: Allows you to reset the bot to its default values");
sendMessage(commandsymbol + "authsymbols auth:symbol: Allows you to change authsymbols. If symbol is left blank, then it removes the current auth symbol");
sendMessage(commandsymbol + "authstyle auth:htmltag: Allows you to change the name style of auth. Make sure to use start tags only. If htmltag is left blank, then it will remove the current style");
return;
}
if (command === "scriptcommands") {
sys.stopEvent();
sendMessage("*** Script Commands ***");
sendMessage(commandsymbol + "updatescripts: Allows you to updatescripts");
//sendMessage(commandsymbol + "updatetierinfo: Allows you to update the tier info used in pokedex. Use this after tier changes on the main server");
sendMessage(commandsymbol + "versions: Allows you to view the current versions");
sendMessage(commandsymbol + "changelog version: Allows you to view the changelog");
sendMessage(commandsymbol + "checkversion: Allows you to check for updates");
sendMessage(commandsymbol + "updatealert on/off: Allows you to get automatically alerted about new versions");
return;
}
if (command === "socialcommands") {
sys.stopEvent();
sendMessage("*** Social Commands ***");
sendMessage(commandsymbol + "friends: Allows you to view your current friends and their online status");
sendMessage(commandsymbol + "[add/remove]friend friend: Allows you to add/remove friends");
sendMessage(commandsymbol + "friendflash on/off: Allows you turn friend flashes on/off");
sendMessage(commandsymbol + "ignorelist: Allows you to view your autoignore list");
sendMessage(commandsymbol + "[add/remove]ignore user: Allows you to add/remove people from your ignore list");
sendMessage(commandsymbol + "armessage: Sets your autoresponse message");
sendMessage(commandsymbol + "artype [command/time]: Sets how to activate your autoresponse, time does it between certain hours, command activates it by command");
sendMessage(commandsymbol + "ar[on/off]: Turns your autoresponse on/off if type if command");
sendMessage(commandsymbol + "artime hour1:hour2: Sets your autoresponse to activate between hour1 and hour2");
return;
}
if (command === "fontcommands") {
sys.stopEvent();
sendMessage("*** Font Command Details ***");
sendMessage("Command: " + commandsymbol + "font type:modifier");
sendMessage("Type: Types are 'colo(u)r', 'style', 'type', 'size'");
sendMessage("Colour: Defines the colour of the font");
sendMessage("Style: Defines the style of the font (bold/italics/underline)");
sendMessage("Type: Defines the font face");
sendMessage("Size: Defines the font size");
sendMessage("Modifier: Modifiers vary from types. Colour modifiers are any valid colour. Style is any valid HTML start tag. Type is any type of font face. Size is any number");
sendMessage("Example: " + commandsymbol + "font color:red, will make all text red");
return;
}
if (command === "etext") {
sys.stopEvent();
if (commandData === "on") {
etext = true;
Utilities.saveSettings();
sendBotMessage("You turned Enriched text on!");
return;
}
if (commandData === "off") {
etext = false;
Utilities.saveSettings();
sendBotMessage("You turned Enriched text off!");
return;
}
etext = !etext;
sendBotMessage(etext ? "You turned Enriched text on!" : "You turned Enriched text off!");
return;
}
if (command === "greentext") {
sys.stopEvent();
if (commandData === "on") {
tgreentext = true;
Utilities.saveSettings();
sendBotMessage("You turned greentext on!");
return;
}
if (commandData === "off") {
tgreentext = false;
Utilities.saveSettings();
sendBotMessage("You turned greentext off!");
return;
}
tgreentext = !tgreentext;
sendBotMessage(tgreentext ? "You turned greentext on!" : "You turned greentext off!");
return;
}
if (command === "idle") {
sys.stopEvent();
if (commandData === "on") {
client.goAway(true);
autoidle = true;
Utilities.saveSettings();
sendBotMessage("You turned auto-idling on!");
return;
}
if (commandData === "off") {
client.goAway(false);
autoidle = false;
Utilities.saveSettings();
sendBotMessage("You turned auto-idling off!");
return;
}
autoidle = !autoidle;
client.goAway(autoidle);
sendBotMessage(autoidle ? "You turned auto-idling on!" : "You turned auto-idling off!");
return;
}
if (command === "ignorechallenges") {
sys.stopEvent();
if (commandData === "on") {
nochallenge = true;
Utilities.saveSettings();
sendBotMessage("You are ignoring all challenges");
return;
}
if (commandData === "off") {
nochallenge = false;
Utilities.saveSettings();
sendBotMessage("You are no longer ignoring challenges");
return;
}
nochallenge = !nochallenge;
sendBotMessage(nochallenge ? "You are ignoring all challenges" : "You are no longer ignoring challenges");
return;
}
if (command === "ytlinks") {
sys.stopEvent();
if (commandData === "on") {
youtube = true;
Utilities.saveSettings();
sendBotMessage("Youtube links will automatically convert to titles");
return;
}
if (commandData === "off") {
youtube = false;
Utilities.saveSettings();
sendBotMessage("Youtube links will display as links instead of titles");
return;
}
sendBotMessage("Please use on/off");
}
if (command === "checkversion") {
sys.stopEvent();
if (isSafeScripts()) {
return;
}
sendBotMessage("Checking script version please wait. (Current Version: " + Script_Version + ")");
checkScriptVersion(true);
return;
}
if (command === "updatealert") {
sys.stopEvent();
if (isSafeScripts()) {
return;
}
if (commandData === "on") {
checkversion = true;
Utilities.saveSettings();
sendBotMessage("You now get alerted about new versions");
checkScriptVersion();
return;
}
if (commandData === "off") {
checkversion = false;
Utilities.saveSettings();
sendBotMessage("You no longer get alerted about new versions");
return;
}
sendBotMessage("Please use on/off");
return;
}
if (command === "goto") {
sys.stopEvent();
var channela = commandData.toLowerCase();
var channels = client.channelNames();
for (var x in channels) {
if (channels.hasOwnProperty(x)) {
if (channela === channels[x].toLowerCase()) {
channela = channels[x];
if (!client.hasChannel(client.channelId(channela))) {
client.join(channela);
return;
}
client.activateChannel(channela);
return;
}
}
}
sendBotMessage("That is not a channel!");
return;
}
if (command === "reconnect") {
sys.stopEvent();
client.reconnect();
return;
}
if (command === "pm") {
sys.stopEvent();
var id = client.id(commandData);
if (id === client.ownId()) {
return;
}
client.startPM(id);
return;
}
if (command === "stalkwords") {
sys.stopEvent();
sendBotMessage("Your stalkwords are: " + stalkwords);
return;
}
if (command === "addstalkword") {
sys.stopEvent();
var nstalkwords = commandData;
if (nstalkwords.search(/, /g) !== -1 || nstalkwords.search(/ ,/g) !== -1) {
nstalkwords = nstalkwords.replace(/, /g, ",")
.replace(/ ,/g, ",");
}
nstalkwords = nstalkwords.split(",");
stalkwords = Utilities.eliminateDuplicates(nstalkwords.concat(stalkwords));
Utilities.saveSettings();
sendBotMessage("You added " + commandData + " to your stalkwords!");
return;
}
if (command === "removestalkword") {
sys.stopEvent();
commandData = commandData.toLowerCase();
for (var x = 0; x < stalkwords.length; x++) {
if (stalkwords[x].toLowerCase() === commandData) {
stalkwords.splice(x, 1);
Utilities.saveSettings();
sendBotMessage("You removed " + commandData + " from your stalkwords!");
return;
}
}
sendBotMessage("" + commandData + " is not a stalkword!");
return;
}
if (command === "flash" || command === "flashes") {
sys.stopEvent();
commandData = commandData.split(':');
if (commandData.length < 2 || commandData[1] === "") {
if (commandData[0] === "on") {
flash = true;
Utilities.saveSettings();
sendBotMessage("You turned flashes on!");
return;
}
else {
flash = false;
Utilities.saveSettings();
sendBotMessage("You turned flashes off!");
return;
}
}
var nfchannel = commandData[1];
if (commandData[0] === "off") {
if (nfchannel.search(/, /g) !== -1 || nfchannel.search(/ ,/g) !== -1) {
nfchannel = nfchannel.replace(/, /g, ",")
.replace(/ ,/g, ",");
}
nfchannel = nfchannel.split(",");
fchannel = Utilities.eliminateDuplicates(nfchannel.concat(fchannel));
Utilities.saveSettings();
sendBotMessage("You won't be flashed in " + commandData[1]);
}
else {
commandData[1] = commandData[1].toLowerCase();
for (var x = 0; x < fchannel.length; x++) {
if (fchannel[x].toLowerCase() === commandData[1]) {
fchannel.splice(x, 1);
Utilities.saveSettings();
sendBotMessage("You will be flashed in " + commandData[1]);
return;
}
}
}
return;
}
if (command === "friends") {
sys.stopEvent();
var check = [];
for (var x = 0; x < friends.length; x++) {
if (client.id(friends[x]) !== -1) {
check.push("<a href='po:pm/" + client.id(friends[x]) + "'>" + friends[x] + "</a> <font color='green'>(online)</font>");
continue;
}
check.push(friends[x] + " <font color='red'>(offline)</font>");
}
sendHtmlMessage("<font color = '" + Utilities.html_escape(clientbotcolour) + "'><timestamp/>" + clientbotstyle + Utilities.html_escape(clientbotname) + ":" + Utilities.tagend(clientbotstyle) + "</font> Your friends are: " + check);
return;
}
if (command === "addfriend") {
sys.stopEvent();
var nfriends = commandData;
if (nfriends.search(/, /g) !== -1 || nfriends.search(/ ,/g) !== -1) {
nfriends = nfriends.replace(/, /g, ",")
.replace(/ ,/g, ",");
}
nfriends = nfriends.split(",");
friends = Utilities.eliminateDuplicates(nfriends.concat(friends));
Utilities.saveSettings();
sendBotMessage("You added " + commandData + " to your friends!");
return;
}
if (command === "removefriend") {
sys.stopEvent();
commandData = commandData.toLowerCase();
for (var x = 0; x < friends.length; x++) {
if (friends[x].toLowerCase() === commandData) {
friends.splice(x, 1);
Utilities.saveSettings();
sendBotMessage("You removed " + commandData + " from your friends!");
return;
}
}
sendBotMessage(commandData + " is not a friend!");
return;
}
if (command === "friendflash" || command === "friendsflash") {
sys.stopEvent();
if (commandData === "on") {
friendsflash = true;
Utilities.saveSettings();
sendBotMessage("You turned friend flashes on!");
return;
}
else {
friendsflash = false;
Utilities.saveSettings();
sendBotMessage("You turned friend flashes off!");
}
return;
}
if (command === "ignorelist") {
sys.stopEvent();
sendBotMessage("Your ignorelist is: " + ignore);
return;
}
if (command === "addignore") {
sys.stopEvent();
if (commandData === client.ownName()) {
return;
}
var nignore = commandData;
if (nignore.search(/, /g) !== -1 || nignore.search(/ ,/g) !== -1) {
nignore = nignore.replace(/, /g, ",")
.replace(/ ,/g, ",");
}
nignore = nignore.split(",");
ignore = Utilities.eliminateDuplicates(nignore.concat(ignore));
Utilities.saveSettings();
if (client.id(commandData) !== -1) {
client.ignore(client.id(commandData), true);
}
sendBotMessage("You added " + commandData + " to your ignorelist!");
return;
}
if (command === "removeignore") {
sys.stopEvent();
commandData = commandData.toLowerCase();
for (var x = 0; x < ignore.length; x++) {
if (ignore[x].toLowerCase() === commandData) {
ignore.splice(x, 1);
Utilities.saveSettings();
if (client.id(commandData) !== -1) {
client.ignore(client.id(commandData), false);
}
sendBotMessage("You removed " + commandData + " from your ignorelist!");
return;
}
}
sendBotMessage(commandData + " is not on the ignorelist!");
return;
}
if (command === "changebotname") {
sys.stopEvent();
if (commandData === undefined) {
return;
}
clientbotname = commandData;
sendBotMessage(clientbotname + " is now your clientbot's name!");
Utilities.saveSettings();
return;
}
if (command === "changebotstyle") {
sys.stopEvent();
if (commandData === undefined) {
clientbotstyle = "";
sendBotMessage("You removed your client bot style!");
Utilities.saveSettings();
return;
}
clientbotstyle = commandData;
sendBotMessage(clientbotstyle + " is now your clientbot's style!");
Utilities.saveSettings();
return;
}
if (command === "changebotcolour" || command === "changebotcolor") {
sys.stopEvent();
if (commandData === undefined) {
return;
}
clientbotcolour = commandData;
sendBotMessage(clientbotcolour + " is now your clientbot's colour!");
Utilities.saveSettings();
return;
}
if (command === "greentextcolor" || command === "greentextcolour") {
sys.stopEvent();
if (commandData === undefined || commandData === "") {
greentext = '#789922';
sendBotMessage(greentext + " is now your greentext colour!");
Utilities.saveSettings();
return;
}
greentext = commandData;
sendBotMessage(greentext + " is now your greentext colour!");
Utilities.saveSettings();
return;
}
if (command === "resetbot") {
sys.stopEvent();
clientbotcolour = "#3DAA68";
clientbotname = "+ClientBot";
clientbotstyle = "<b>";
Utilities.saveSettings();
sendBotMessage("You reset your bot to default values");
return;
}
if (command === "font") {
sys.stopEvent();
if (commandData === undefined) {
return;
}
var type = commandData.split(":");
if (type.length < 1) {
sendBotMessage('Usage is ' + commandsymbol + 'font type:modifier');
return;
}
var modifier = type[1];
var types = ["colour", "color", "style", "type", "size"];
if (types.indexOf(type[0]) === -1) {
sendBotMessage('Invalid type, valid types are: colo(u)r, style, type, size');
return;
}
if (type[0] === "colour" || type[0] === "color") {
if (modifier === undefined || modifier === "") {
modifier = "#000000";
fontcolour = modifier;
Utilities.saveSettings();
sendBotMessage("You changed your font colour to the default");
return;
}
fontcolour = modifier;
Utilities.saveSettings();
sendBotMessage("You changed your font colour to: " + modifier);
return;
}
if (type[0] === "style") {
if (modifier === undefined || modifier === "") {
modifier = "";
fontstyle = modifier;
Utilities.saveSettings();
sendBotMessage("You changed your font style to the default");
return;
}
if (modifier.indexOf('</') !== -1) {
sendBotMessage("End tags are not needed, please only use start ones");
return;
}
fontstyle = modifier;
Utilities.saveSettings();
sendBotMessage("You changed your font style to: " + modifier);
return;
}
if (type[0] === "type") {
if (modifier === undefined || modifier === "") {
modifier = "";
fonttype = modifier;
Utilities.saveSettings();
sendBotMessage("You changed your font type to the default");
return;
}
fonttype = modifier;
Utilities.saveSettings();
sendBotMessage("You changed your font to: " + modifier);
return;
}
if (type[0] === "size") {
if (modifier === undefined || modifier === "" || isNaN(parseInt(modifier, 10))) {
modifier = 3;
fontsize = modifier;
Utilities.saveSettings();
sendBotMessage("You changed your font size to the default");
return;
}
fontsize = modifier;
Utilities.saveSettings();
sendBotMessage("You changed your font size to: " + modifier);
return;
}
}
if (command === "changename") {
sys.stopEvent();
try {
commandData = nameCheck(commandData);
}
catch (e) {
sendBotMessage("Invalid Name: " + e);
return;
}
try {
client.changeName(commandData);
sendBotMessage("You changed your name to " + commandData);
}
catch (e) {
if (e.toString() === "TypeError: Result of expression 'client.changeName' [undefined] is not a function.") {
sendBotMessage("You need to update your client to Version 2.0.06 or above to use this command");
}
}
return;
}
if (command === "changelog") {
sys.stopEvent();
if (isSafeScripts()) {
return;
}
var changelog = sys.synchronousWebCall(script_url + "changelog.json");
if (changelog.length < 1) {
sendBotMessage("Error retrieving file");
return;
}
changelog = JSON.parse(changelog);
if (changelog.versions[commandData] === undefined) {
sendBotMessage("Version does not exist! Use " + commandsymbol + "versions to check versions");
return;
}
var details = changelog.versions[commandData].split('\n');
sendBotMessage("Details for version: " + commandData);
for (var x = 0; x < details.length; x++) {
sendBotMessage(details[x]);
}
return;
}
if (command === "versions") {
sys.stopEvent();
var version = [];
if (isSafeScripts()) {
return;
}
var changelog = sys.synchronousWebCall(script_url + "changelog.json");
if (changelog.length < 1) {
sendBotMessage("Error retrieving file");
return;
}
changelog = JSON.parse(changelog);
for (var x in changelog.versions) {
if (changelog.versions.hasOwnProperty(x)) {
version.push(" " + x);
}
}
sendBotMessage('Versions of this script are: ' + version);
return;
}
if (command === "updatescripts") {
sys.stopEvent();
if (isSafeScripts()) {
return;
}
sendBotMessage("Fetching scripts...");
var updateURL = script_url + 'script.js';
if (commandData !== undefined && (commandData.substring(0, 7) === 'http://' || commandData.substring(0, 8) === 'https://')) {
updateURL = commandData;
}
var channel_local = channel;
sendBotMessage("Fetching scripts from (link)", channel_local, updateURL);
sys.webCall(updateURL, changeScript);
return;
}
/*if (command === "updatetierinfo") {
sys.stopEvent();
if (isSafeScripts()) {
return;
}
sendBotMessage("Fetching tier info...");
sys.webCall("https://gist.github.com/CrystalMoogle/76a72f564d7eb8c509dd/raw/tiers.json", function(resp) {sys.writeToFile('tiers.json', resp); sendBotMessage("Tier info was updated!");});
}*/
if (command === "updateplugin") {
sys.stopEvent();
if (pluginFiles.indexOf(commandData) !== -1) {
updateFile(commandData);
return;
}
sendBotMessage("This is not a valid script plugin");
return;
}
if (command === "addplugin") {
sys.stopEvent();
if (pluginFiles.indexOf(commandData.split(/\//).pop()) !== -1) {
updateFile(commandData);
return;
}
pluginFiles = pluginFiles.concat(commandData.split(/\//).pop());
addPlugin(commandData);
return;
}
if (command === "loadsettings") { //TODO Allow user defined files to be loaded in the future from web or file system
sys.stopEvent();
Utilities.loadSettings(undefined, undefined, false);
return;
}
if (command === "authsymbol" || command === "authsymbols") {
sys.stopEvent();
var symbols = commandData.split(":");
var auth = symbols[0];
var symbol = symbols[1];
if (symbols.length > 2 || symbols.length < 1) {
sendBotMessage("Command usage is: \"" + commandsymbol + "changesymbols number:symbol\"");
return;
}
if (isNaN(parseInt(auth, 10))) {
sendBotMessage("The first parameter must be a number!");
return;
}
if (auth < 0 || auth > 4) {
sendBotMessage("Auth must be between 0 and 4");
return;
}
if (symbol === undefined) {
symbol = "";
}
auth_symbol[auth] = symbol;
Utilities.saveSettings();
if (symbol === "") {
sendBotMessage("Auth " + auth + " now has no symbol");
return;
}
sendBotMessage("Auth symbol for auth " + auth + " is " + symbol);
return;
}
if (command === "authstyle") {
sys.stopEvent();
var styles = commandData.split(":");
var auth = styles[0];
var style = styles[1];
if (styles.length > 2 || styles.length < 2) {
sendBotMessage("Command usage is: \"" + commandsymbol + "changestyles number:html\"");
return;
}
if (isNaN(parseInt(auth, 10))) {
sendBotMessage("The first parameter must be a number!");
return;
}
if (auth < 0 || auth > 4) {
sendBotMessage("Auth must be between 0 and 4");
return;
}
if (style.indexOf('</') !== -1) {
sendBotMessage("End tags are not needed, please only use start ones");
return;
}
if (style === undefined) {
style = "";
}
auth_style[auth] = style;
Utilities.saveSettings();
if (style === "") {
sendBotMessage("Auth " + auth + " now has no style");
return;
}
sendBotMessage("Auth style for auth " + auth + " is " + style);
return;
}
if (command === "damagecalc") {
sys.stopEvent();
var paras = commandData.split(':');
if (paras.length !== 5) {
sendBotMessage("Format is [s]atk:movepower:boosts:[s]def:hp");
return;
}
for (var x = 0; x < paras.length; x++) {
paras[x] = parseFloat(paras[x]);
if (isNaN(paras[x])) {
sendBotMessage('Parameters must be all numbers!');
return;
}
}
if (paras[2] === 0) {
paras[2] = 1;
}
var calc = (84 * paras[0] * paras[1] * paras[2]) / (paras[3] * paras[4]);
sendBotMessage(paras[1] + "BP move coming from " + paras[0] + "[s]atk with a " + paras[2] + " modifier on " + paras[4] + "HP and " + paras[3] + "[s]def, does approxmiately " + calc + " damage");
return;
}
if (command === "pokedex") {
sys.stopEvent();
if (!Utilities.checkVersion(2008)) {
sendBotMessage("This command will only work on versions 2.0.08 and higher");
return;
}
if (commandData === undefined) {
sendBotMessage("Usage is " + commandsymbol + "pokedex pokemon:level:gen (gen/level are optional)");
return;
}
commandData = commandData.split(':');
if (commandData.length > 3) {
sendBotMessage("Usage is " + commandsymbol + "pokedex pokemon:level:gen (gen/level are optional)");
return;
}
var pokemon = sys.pokeNum(commandData[0]);
var gen = parseInt(commandData[2], 10);
var level = parseInt(commandData[1], 10);
if (isNaN(gen) || gen > 6 || gen < 1) {
gen = 6;
}