forked from po-devs/po-server-goodies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
2254 lines (2043 loc) · 100 KB
/
scripts.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
// This is the official Pokemon Online Scripts
// These scripts will only work on 2.0.00 or newer.
/*jshint "laxbreak":true,"shadow":true,"undef":true,"evil":true,"trailing":true,"proto":true,"withstmt":true*/
// You may change these variables as long as you keep the same type
var Config = {
base_url: "https://raw.githubusercontent.com/po-devs/po-server-goodies/master/",
dataDir: "scriptdata/",
bot: "Dratini",
kickbot: "Blaziken",
capsbot: "Exploud",
channelbot: "Chatot",
checkbot: "Snorlax",
coinbot: "Meowth",
countbot: "CountBot",
tourneybot: "Typhlosion",
rankingbot: "Porygon",
battlebot: "Blastoise",
commandbot: "CommandBot",
querybot: "QueryBot",
hangbot: "Unown",
bfbot: "Goomy",
// suspectvoting.js available, but not in use
Plugins: ["mafia.js", "amoebagame.js", "tournaments.js", "tourstats.js", "trivia.js", "tours.js", "newtourstats.js", "auto_smute.js", "battlefactory.js", "hangman.js", "blackjack.js", "mafiastats.js", "mafiachecker.js"],
Mafia: {
bot: "Murkrow",
norepeat: 5,
stats_file: "scriptdata/mafia_stats.json",
max_name_length: 16,
notPlayingMsg: "±Game: The game is in progress. Please type /join to join the next mafia game."
},
League: [
["Laurel", "PO League Champion - View {0}'s <a href='http://pokemon-online.eu/threads/champion-laurel.27787/'>Thread!</a>"],
["ßasedVictory", "Elite Four - View {0}'s <a href='http://pokemon-online.eu/threads/27798/'>E4 Thread!</a>"],
["The Boy", "Elite Four - View {0}'s <a href='http://pokemon-online.eu/threads/27780/'>E4 Thread!</a>"],
["Luck>Skill", "Elite Four - View {0}'s <a href='http://pokemon-online.eu/threads/27794/'>E4 Thread!</a>"],
["Isa", "Elite Four - View {0}'s <a href='http://pokemon-online.eu/threads/27781/'>E4 Thread!</a>"],
["ZoroDark", "6th Generation Ubers - View {0}'s <a href='http://pokemon-online.eu/threads/27779/'>Gym Thread!</a>"],
["MetalGross", "6th Generation OverUsed - View {0}'s <a href='http://pokemon-online.eu/threads/27774/'>Gym Thread!</a>"],
["-SnowCristal", "6th Generation OverUsed - View {0}'s <a href='http://pokemon-online.eu/threads/27774/'>Gym Thread!</a>"],
["meepsvictory", "6th Generation UnderUsed - View {0}'s <a href='http://pokemon-online.eu/threads/27763/'>Gym Thread!</a> "],
["Proof", "6th Generation LittleUsed - View {0}'s <a href='http://pokemon-online.eu/threads/27775'>Gym Thread!</a>"],
["A$AP KROKOROK", "6th Generation NeverUsed - View {0}'s <a href='http://pokemon-online.eu/threads/27766/'>Gym Thread!</a>"],
["Artemisa", "6th Generation Little Cup - View {0}'s <a href='http://pokemon-online.eu/threads/27772/'>Gym Thread!</a>"],
["The Dude", "Challenge Cup - View {0}'s <a href='http://pokemon-online.eu/threads/27784/'>Gym Thread!</a>"],
["Atli", "Challenge Cup - View {0}'s <a href='http://pokemon-online.eu/threads/27784/'>Gym Thread!</a>"],
["Raducan", "Battle Factory 6v6 - View {0}'s <a href='http://pokemon-online.eu/threads/27788/'>Gym Thread!</a>"],
["Trademark", "Battle Factory 6v6 - View {0}'s <a href='http://pokemon-online.eu/threads/27788/'>Gym Thread!</a>"],
["sulcata", "Monotype - View {0}'s <a href='http://pokemon-online.eu/threads/27786/'>Gym Thread!</a>"],
["Windblown", "Inverted Battle - View {0}'s <a href='http://pokemon-online.eu/threads/27773/'>Gym Thread!</a>"],
["Finchinator", "5th Generation OverUsed - View {0}'s <a href='http://pokemon-online.eu/threads/27764/'>Gym Thread!</a>"],
["Tomahawk9", "4th Generation OverUsed - View {0}'s <a href='http://pokemon-online.eu/threads/27795/'>Gym Thread!</a>"],
["Hector's Planet", "3rd Generation OverUsed - View {0}'s <a href='http://pokemon-online.eu/threads/27771/'>Gym Thread!</a>"],
["xdevo", "2nd Generation OverUsed - View {0}'s <a href='http://pokemon-online.eu/threads/27791/'>Gym Thread!</a>"],
["marcoasd", "1st Generation OverUsed - View {0}'s <a href='http://pokemon-online.eu/threads/27778/'>Gym Thread!</a>"]
],
DreamWorldTiers: ["No Preview OU", "No Preview Ubers", "DW LC", "DW UU", "DW LU", "Gen 5 1v1 Ubers", "Gen 5 1v1", "Challenge Cup", "CC 1v1", "DW Uber Triples", "No Preview OU Triples", "No Preview Uber Doubles", "No Preview OU Doubles", "Shanai Cup", "Shanai Cup 1.5", "Shanai Cup STAT", "Original Shanai Cup TEST", "Monocolour", "Clear Skies DW"],
superAdmins: ["[LD]Jirachier", "Mahnmut"],
canJoinStaffChannel: ["Lamperi-"],
disallowStaffChannel: [],
topic_delimiter: " | ",
registeredLimit: 30
};
// Don't touch anything here if you don't know what you do.
/*global print, script, sys, SESSION*/
var require_cache = typeof require != 'undefined' ? require.cache : {};
require = function require(module_name, retry) {
if (require.cache[module_name])
return require.cache[module_name];
var module = {};
module.module = module;
module.exports = {};
module.source = module_name;
with (module) {
var content = sys.getFileContent("scripts/"+module_name);
if (content) {
try {
eval(sys.getFileContent("scripts/"+module_name));
sys.writeToFile("scripts/" + module_name + "-b", sys.getFileContent("scripts/" + module_name));
} catch(e) {
if (staffchannel)
sys.sendAll("Error loading module " + module_name + ": " + e + (e.lineNumber ? " on line: " + e.lineNumber : ""), staffchannel);
else
sys.sendAll("Error loading module " + module_name + ": " + e);
sys.writeToFile("scripts/"+module_name, sys.getFileContent("scripts/" + module_name + "-b"));
if (!retry) {
require(module_name, true); //prevent loops
}
}
}
}
require.cache[module_name] = module.exports;
return module.exports;
};
require.cache = require_cache;
var updateModule = function updateModule(module_name, callback) {
var base_url = Config.base_url;
var url;
if (/^https?:\/\//.test(module_name))
url = module_name;
else
url = base_url + "scripts/"+ module_name;
var fname = module_name.split(/\//).pop();
if (!callback) {
var resp = sys.synchronousWebCall(url);
if (resp === "") return {};
sys.writeToFile("scripts/"+fname, resp);
delete require.cache[fname];
var module = require(fname);
return module;
} else {
sys.webCall(url, function updateModule_callback(resp) {
if (resp === "") return;
sys.writeToFile("scripts/"+fname, resp);
delete require.cache[fname];
var module = require(fname);
callback(module);
});
}
};
var channel, contributors, mutes, mbans, smutes, detained, hmutes, mafiaSuperAdmins, hangmanAdmins, hangmanSuperAdmins, staffchannel, channelbot, normalbot, bot, mafiabot, kickbot, capsbot, checkbot, coinbot, countbot, tourneybot, battlebot, commandbot, querybot, rankingbot, hangbot, bfbot, scriptChecks, lastMemUpdate, bannedUrls, mafiachan, mafiarev, sachannel, tourchannel, dwpokemons, hapokemons, lcpokemons, bannedGSCSleep, bannedGSCTrap, breedingpokemons, rangebans, proxy_ips, mafiaAdmins, rules, authStats, nameBans, chanNameBans, isSuperAdmin, cmp, key, battlesStopped, lineCount, pokeNatures, pokeAbilities, maxPlayersOnline, pastebin_api_key, pastebin_user_key, getSeconds, getTimeString, sendChanMessage, sendChanAll, sendMainTour, VarsCreated, authChangingTeam, usingBannedWords, repeatingOneself, capsName, CAPSLOCKDAYALLOW, nameWarns, poScript, revchan, triviachan, watchchannel, lcmoves, hangmanchan, ipbans, battlesFought, lastCleared, blackjackchan, namesToWatch, allowedRangeNames, reverseTohjo;
var pokeDir = "db/pokes/";
var moveDir = "db/moves/6G/";
var abilityDir = "db/abilities/";
var itemDir = "db/items/";
sys.makeDir("scripts");
/* we need to make sure the scripts exist */
var commandfiles = ['commands.js', 'channelcommands.js','ownercommands.js', 'modcommands.js', 'usercommands.js', "admincommands.js"];
var deps = ['crc32.js', 'utilities.js', 'bot.js', 'memoryhash.js', 'tierchecks.js', "globalfunctions.js", "userfunctions.js", "channelfunctions.js", "channelmanager.js", "pokedex.js"].concat(commandfiles).concat(Config.Plugins);
var missing = 0;
for (var i = 0; i < deps.length; ++i) {
if (!sys.getFileContent("scripts/"+deps[i])) {
if (missing++ === 0) sys.sendAll('Server is updating its script modules, it might take a while...');
var module = updateModule(deps[i]);
module.source = deps[i];
}
}
if (missing) sys.sendAll('Done. Updated ' + missing + ' modules.');
/* To avoid a load of warning for new users of the script,
create all the files that will be read further on*/
var cleanFile = function(filename) {
if (typeof sys != 'undefined')
sys.appendToFile(filename, "");
};
[Config.dataDir+"mafia_stats.json", Config.dataDir+"suspectvoting.json", Config.dataDir+"mafiathemes/metadata.json", Config.dataDir+"channelData.json", Config.dataDir+"mutes.txt", Config.dataDir+"mbans.txt", Config.dataDir+"hmutes.txt", Config.dataDir+"smutes.txt", Config.dataDir+"rangebans.txt", Config.dataDir+"contributors.txt", Config.dataDir+"ipbans.txt", Config.dataDir+"namesToWatch.txt", Config.dataDir+"hangmanadmins.txt", Config.dataDir+"hangmansuperadmins.txt", Config.dataDir+"pastebin_user_key", Config.dataDir+"secretsmute.txt", Config.dataDir+"ipApi.txt", Config.dataDir + "notice.html", Config.dataDir + "rangewhitelist.txt"].forEach(cleanFile);
var autosmute = sys.getFileContent(Config.dataDir+"secretsmute.txt").split(':::');
var crc32 = require('crc32.js').crc32;
var MemoryHash = require('memoryhash.js').MemoryHash;
var POChannelManager = require('channelmanager.js').POChannelManager;
var POChannel = require('channelfunctions.js').POChannel;
var POUser = require('userfunctions.js').POUser;
var POGlobal = require('globalfunctions.js').POGlobal;
delete require.cache['tierchecks.js'];
var tier_checker = require('tierchecks.js');
delete require.cache['pokedex.js'];
var pokedex = require('pokedex.js');
/* stolen from here: http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format */
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;
};
String.prototype.toCorrectCase = function() {
if (isNaN(this) && sys.id(this) !== undefined) {
return sys.name(sys.id(this));
}
else {
return this;
}
};
var utilities = require('utilities.js');
var isNonNegative = utilities.is_non_negative;
var Lazy = utilities.Lazy;
var nonFlashing = utilities.non_flashing;
var getSeconds = utilities.getSeconds;
var getTimeString = utilities.getTimeString;
var commands = require('commands.js');
/* Useful for evalp purposes */
function printObject(o) {
var out = '';
for (var p in o) {
if (o.hasOwnProperty(p)) {
out += p + ': ' + o[p] + '\n';
}
}
sys.sendAll(out);
}
/* Functions using the implicit variable 'channel' set on various events */
// TODO: remove the possibility for implictit channel
// TODO: REMOVE THESE FUNCTIONS THAT LIKE BREAKING AT RANDOM TIMES
function sendChanMessage(id, message, channel) {
sys.sendMessage(id, message, channel);
}
function sendChanAll(message, chan_id, channel) {
if((chan_id === undefined && channel === undefined) || chan_id == -1)
{
sys.sendAll(message);
} else if(chan_id === undefined && channel !== undefined)
{
sys.sendAll(message, channel);
} else if(chan_id !== undefined)
{
sys.sendAll(message, chan_id);
}
}
function sendChanHtmlMessage(id, message) {
sys.sendHtmlMessage(id, message, channel);
}
function sendChanHtmlAll(message, chan_id) {
if((chan_id === undefined && channel === undefined) || chan_id == -1)
{
sys.sendHtmlAll(message);
} else if(chan_id === undefined && channel !== undefined)
{
sys.sendHtmlAll(message, channel);
} else if(chan_id !== undefined)
{
sys.sendHtmlAll(message, chan_id);
}
}
function updateNotice() {
var url = Config.base_url + "notice.html";
sys.webCall(url, function (resp){
sys.writeToFile(Config.dataDir + "notice.html", resp);
sendNotice();
});
}
function sendNotice() {
var notice = sys.getFileContent(Config.dataDir + "notice.html");
if (notice) {
["Tohjo Falls", "Trivia", "Tournaments", "Indigo Plateau", "Victory Road", "TrivReview", "Mafia", "Hangman"].forEach(function(c) {
sys.sendHtmlAll(notice, sys.channelId(c));
});
}
}
function isAndroid(id) {
if (sys.os) {
return sys.os(id) === "android";
} else {
return sys.info(id) === "Android player." && sys.avatar(id) === 72;
}
}
function clearTeamFiles() {
var files = sys.filesForDirectory("usage_stats/formatted/team");
for (var x = 0; x < files.length; x++) {
var time = files[x].split("-")[0];
if (sys.time() - time > 86400) {
sys.deleteFile("usage_stats/formatted/team/" + files[x]);
}
}
}
var POKEMON_CLEFFA = typeof sys != 'undefined' ? sys.pokeNum("Cleffa") : 173;
function callplugins() {
return SESSION.global().callplugins.apply(SESSION.global(), arguments);
}
function getplugins() {
return SESSION.global().getplugins.apply(SESSION.global(), arguments);
}
SESSION.identifyScriptAs("PO Scripts v0.991");
SESSION.registerChannelFactory(POChannel);
SESSION.registerUserFactory(POUser);
SESSION.registerGlobalFactory(POGlobal);
if (typeof SESSION.global() != 'undefined') {
SESSION.global().channelManager = new POChannelManager('scriptdata/channelHash.txt');
SESSION.global().__proto__ = POGlobal.prototype;
var plugin_files = Config.Plugins;
var plugins = [];
for (var i = 0; i < plugin_files.length; ++i) {
var plugin = require(plugin_files[i]);
plugin.source = plugin_files[i];
plugins.push(plugin);
}
SESSION.global().plugins = plugins;
// uncomment to update either Channel or User
sys.channelIds().forEach(function(id) {
if (!SESSION.channels(id))
sys.sendAll("ScriptUpdate: SESSION storage broken for channel: " + sys.channel(id), staffchannel);
else
SESSION.channels(id).__proto__ = POChannel.prototype;
});
sys.playerIds().forEach(function(id) {
if (sys.loggedIn(id)) {
var user = SESSION.users(id);
if (!user) {
sys.sendAll("ScriptUpdate: SESSION storage broken for user: " + sys.name(id), staffchannel);
} else {
user.__proto__ = POUser.prototype;
user.battles = user.battles || {};
}
}
});
}
// Bot.js binds the global variable 'channel' so we cannot re-use it
// since the binding will to the old variable.
delete require.cache['bot.js'];
var Bot = require('bot.js').Bot;
normalbot = bot = new Bot(Config.bot);
mafiabot = new Bot(Config.Mafia.bot);
channelbot = new Bot(Config.channelbot);
kickbot = new Bot(Config.kickbot);
capsbot = new Bot(Config.capsbot);
checkbot = new Bot(Config.checkbot);
coinbot = new Bot(Config.coinbot);
countbot = new Bot(Config.countbot);
tourneybot = new Bot(Config.tourneybot);
rankingbot = new Bot(Config.rankingbot);
battlebot = new Bot(Config.battlebot);
commandbot = new Bot(Config.commandbot);
querybot = new Bot(Config.querybot);
hangbot = new Bot(Config.hangbot);
bfbot = new Bot(Config.bfbot);
/* Start script-object
*
* All the events are defined here
*/
var lastStatUpdate = new Date();
poScript=({
/* Executed every second */
step: function() {
if (typeof callplugins == "function") callplugins("stepEvent");
var date = new Date();
if (date.getUTCMinutes() === 10 && date.getUTCSeconds() === 0 && sys.os() !== "windows") {
sys.get_output("nc -z server.pokemon-online.eu 10508", function callback(exit_code) {
if (exit_code !== 0) {
sys.sendAll("±NetCat: Cannot reach Webclient Proxy - it may be down.", sys.channelId("Indigo Plateau"));
}
}, function errback(error) {
sys.sendAll("±NetCat: Cannot reach Webclient Proxy - it may be down: " + error, sys.channelId("Indigo Plateau"));
});
clearTeamFiles();
}
if ([0, 6, 12, 18].indexOf(date.getUTCHours()) != -1 && date.getUTCMinutes() === 0 && date.getUTCSeconds() === 0) {
sendNotice();
}
// Reset stats monthly
var JSONP_FILE = "usage_stats/formatted/stats.jsonp";
if (lastCleared != date.getUTCMonth()) {
lastCleared = date.getUTCMonth();
battlesFought = 0;
sys.saveVal("Stats/BattlesFought", 0);
sys.saveVal("Stats/LastCleared", lastCleared);
sys.saveVal("Stats/MafiaGamesPlayed", 0);
sys.saveVal("Stats/TriviaGamesPlayed", 0);
sys.saveVal("Stats/HangmanGamesPlayed", 0);
}
if (date - lastStatUpdate > 60) {
lastStatUpdate = date;
// QtScript is able to JSON.stringify dates
var stats = {
lastUpdate: date,
usercount: sys.playerIds().filter(sys.loggedIn).length,
battlesFought: battlesFought,
mafiaPlayed: +sys.getVal("Stats/MafiaGamesPlayed"),
triviaPlayed: +sys.getVal("Stats/TriviaGamesPlayed"),
hangmanPlayed: + sys.getVal("Stats/HangmanGamesPlayed")
};
sys.writeToFile(JSONP_FILE, "setServerStats(" + JSON.stringify(stats) + ");");
}
},
serverStartUp : function() {
SESSION.global().startUpTime = +sys.time();
scriptChecks = 0;
this.init();
},
init : function() {
lastMemUpdate = 0;
bannedUrls = [];
battlesFought = +sys.getVal("Stats/BattlesFought");
lastCleared = +sys.getVal("Stats/LastCleared");
mafiachan = SESSION.global().channelManager.createPermChannel("Mafia", "Use /help to get started!");
staffchannel = SESSION.global().channelManager.createPermChannel("Indigo Plateau", "Welcome to the Staff Channel! Discuss of all what users shouldn't hear here! Or more serious stuff...");
sachannel = SESSION.global().channelManager.createPermChannel("Victory Road","Welcome MAs and SAs!");
tourchannel = SESSION.global().channelManager.createPermChannel("Tournaments", 'Useful commands are "/join" (to join a tournament), "/unjoin" (to leave a tournament), "/viewround" (to view the status of matches) and "/megausers" (for a list of users who manage tournaments). Please read the full Tournament Guidelines: http://pokemon-online.eu/forums/showthread.php?2079-Tour-Rules');
watchchannel = SESSION.global().channelManager.createPermChannel("Watch", "Alerts displayed here");
triviachan = SESSION.global().channelManager.createPermChannel("Trivia", "Play trivia here!");
revchan = SESSION.global().channelManager.createPermChannel("TrivReview", "For Trivia Admins to review questions");
mafiarev = SESSION.global().channelManager.createPermChannel("Mafia Review", "For Mafia Admins to review themes");
hangmanchan = SESSION.global().channelManager.createPermChannel("Hangman", "Type /help to see how to play!");
blackjackchan = SESSION.global().channelManager.createPermChannel("Blackjack", "Play Blackjack here!");
var dwlist = ["Timburr", "Gurdurr", "Conkeldurr", "Pansage", "Pansear", "Panpour", "Simisear", "Simisage", "Simipour", "Ekans", "Arbok", "Paras", "Parasect", "Happiny", "Chansey", "Blissey", "Munchlax", "Snorlax", "Aipom", "Ambipom", "Pineco", "Forretress", "Wurmple", "Silcoon", "Cascoon", "Beautifly", "Dustox", "Seedot", "Nuzleaf", "Shiftry", "Slakoth", "Vigoroth", "Slaking", "Nincada", "Ninjask", "Plusle", "Minun", "Budew", "Roselia", "Gulpin", "Swalot", "Kecleon", "Kricketot", "Kricketune", "Cherubi", "Cherrim", "Carnivine", "Audino", "Throh", "Sawk", "Scraggy", "Scrafty", "Rattata", "Raticate", "Nidoran-F", "Nidorina", "Nidoqueen", "Nidoran-M", "Nidorino", "Nidoking", "Oddish", "Gloom", "Vileplume", "Bellossom", "Bellsprout", "Weepinbell", "Victreebel", "Ponyta", "Rapidash", "Farfetch'd", "Doduo", "Dodrio", "Exeggcute", "Exeggutor", "Lickitung", "Lickilicky", "Tangela", "Tangrowth", "Kangaskhan", "Sentret", "Furret", "Cleffa", "Clefairy", "Clefable", "Igglybuff", "Jigglypuff", "Wigglytuff", "Mareep", "Flaaffy", "Ampharos", "Hoppip", "Skiploom", "Jumpluff", "Sunkern", "Sunflora", "Stantler", "Poochyena", "Mightyena", "Lotad", "Ludicolo", "Lombre", "Taillow", "Swellow", "Surskit", "Masquerain", "Bidoof", "Bibarel", "Shinx", "Luxio", "Luxray", "Psyduck", "Golduck", "Growlithe", "Arcanine", "Scyther", "Scizor", "Tauros", "Azurill", "Marill", "Azumarill", "Bonsly", "Sudowoodo", "Girafarig", "Miltank", "Zigzagoon", "Linoone", "Electrike", "Manectric", "Castform", "Pachirisu", "Buneary", "Lopunny", "Glameow", "Purugly", "Natu", "Xatu", "Skitty", "Delcatty", "Eevee", "Vaporeon", "Jolteon", "Flareon", "Espeon", "Umbreon", "Leafeon", "Glaceon", "Bulbasaur", "Charmander", "Squirtle", "Ivysaur", "Venusaur", "Charmeleon", "Charizard", "Wartortle", "Blastoise", "Croagunk", "Toxicroak", "Turtwig", "Grotle", "Torterra", "Chimchar", "Infernape", "Monferno", "Piplup", "Prinplup", "Empoleon", "Treecko", "Sceptile", "Grovyle", "Torchic", "Combusken", "Blaziken", "Mudkip", "Marshtomp", "Swampert", "Caterpie", "Metapod", "Butterfree", "Pidgey", "Pidgeotto", "Pidgeot", "Spearow", "Fearow", "Zubat", "Golbat", "Crobat", "Aerodactyl", "Hoothoot", "Noctowl", "Ledyba", "Ledian", "Yanma", "Yanmega", "Murkrow", "Honchkrow", "Delibird", "Wingull", "Pelipper", "Swablu", "Altaria", "Starly", "Staravia", "Staraptor", "Gligar", "Gliscor", "Drifloon", "Drifblim", "Skarmory", "Tropius", "Chatot", "Slowpoke", "Slowbro", "Slowking", "Krabby", "Kingler", "Horsea", "Seadra", "Kingdra", "Goldeen", "Seaking", "Magikarp", "Gyarados", "Omanyte", "Omastar", "Kabuto", "Kabutops", "Wooper", "Quagsire", "Qwilfish", "Corsola", "Remoraid", "Octillery", "Mantine", "Mantyke", "Carvanha", "Sharpedo", "Wailmer", "Wailord", "Barboach", "Whiscash", "Clamperl", "Gorebyss", "Huntail", "Relicanth", "Luvdisc", "Buizel", "Floatzel", "Finneon", "Lumineon", "Tentacool", "Tentacruel", "Corphish", "Crawdaunt", "Lileep", "Cradily", "Anorith", "Armaldo", "Feebas", "Milotic", "Shellos", "Gastrodon", "Lapras", "Dratini", "Dragonair", "Dragonite", "Elekid", "Electabuzz", "Electivire", "Poliwag", "Poliwrath", "Politoed", "Poliwhirl", "Vulpix", "Ninetales", "Musharna", "Munna", "Darmanitan", "Darumaka", "Mamoswine", "Togekiss", "Burmy", "Burmy-S", "Burmy-G", "Wormadam", "Wormadam-S", "Wormadam-G", "Mothim", "Pichu", "Pikachu", "Raichu","Abra","Kadabra","Alakazam","Spiritomb","Mr. Mime","Mime Jr.","Meditite","Medicham","Meowth","Persian","Shuppet","Banette","Spinarak","Ariados","Drowzee","Hypno","Wobbuffet","Wynaut","Snubbull","Granbull","Houndour","Houndoom","Smoochum","Jynx","Ralts", "Kirlia", "Gardevoir","Gallade","Sableye","Mawile","Volbeat","Illumise","Spoink","Grumpig","Stunky","Skuntank","Bronzong","Bronzor","Mankey","Primeape","Machop","Machoke","Machamp","Magnemite","Magneton","Magnezone","Koffing","Weezing","Rhyhorn","Rhydon","Rhyperior","Teddiursa","Ursaring","Slugma","Magcargo","Phanpy","Donphan","Magby","Magmar","Magmortar","Larvitar","Pupitar","Tyranitar","Makuhita","Hariyama","Numel","Camerupt","Torkoal","Spinda","Trapinch","Vibrava","Flygon","Cacnea","Cacturne","Absol","Beldum","Metang","Metagross","Hippopotas","Hippowdon","Skorupi","Drapion","Tyrogue","Hitmonlee","Hitmonchan","Hitmontop","Bagon","Shelgon","Salamence","Seel","Dewgong","Shellder","Cloyster","Chinchou","Lanturn","Smeargle","Porygon","Porygon2","Porygon-Z","Drilbur", "Excadrill", "Basculin", "Basculin-a", "Alomomola", "Stunfisk", "Druddigon", "Foongus", "Amoonguss", "Liepard", "Purrloin", "Minccino", "Cinccino", "Sandshrew", "Sandslash", "Vullaby", "Mandibuzz", "Braviary", "Frillish", "Jellicent", "Weedle", "Kakuna", "Beedrill", "Shroomish", "Breloom", "Zangoose", "Seviper", "Combee", "Vespiquen", "Patrat", "Watchog", "Blitzle", "Zebstrika", "Woobat", "Swoobat", "Mienfoo", "Mienshao", "Bouffalant", "Staryu", "Starmie", "Togepi", "Shuckle", "Togetic", "Rotom", "Sigilyph", "Riolu", "Lucario", "Lugia", "Ho-Oh", "Dialga", "Palkia", "Giratina", "Grimer", "Muk", "Ditto", "Venonat", "Venomoth", "Herdier", "Lillipup", "Stoutland", "Sewaddle", "Swadloon", "Leavanny", "Cubchoo", "Beartic", "Landorus", "Thundurus", "Tornadus","Dunsparce", "Sneasel", "Weavile", "Nosepass", "Probopass", "Karrablast", "Escavalier", "Shelmet", "Accelgor", "Snorunt", "Glalie", "Froslass", "Pinsir", "Emolga", "Heracross", "Trubbish", "Garbodor", "Snover", "Abomasnow","Diglett", "Dugtrio", "Geodude", "Graveler", "Golem", "Onix", "Steelix", "Voltorb", "Electrode", "Cubone", "Marowak", "Whismur", "Loudred", "Exploud", "Aron", "Lairon", "Aggron", "Spheal", "Sealeo", "Walrein", "Cranidos", "Rampardos", "Shieldon", "Bastiodon", "Gible", "Gabite", "Garchomp", "Pidove", "Tranquill", "Unfezant", "Tympole", "Palpitoad", "Seismitoad", "Cottonee", "Whimsicott", "Petilil", "Lilligant", "Ducklett", "Swanna", "Deerling", "Sawsbuck", "Elgyem", "Beheeyem", "Pawniard", "Bisharp", "Heatmor", "Durant","Venipede","Whirlipede", "Scolipede", "Tirtouga", "Carracosta", "Joltik", "Galvantula", "Maractus", "Dwebble", "Crustle", "Roggenrola", "Boldore", "Gigalith", "Vanillite", "Vanillish", "Vanilluxe", "Klink", "Klang", "Klinklang", "Swinub", "Piloswine", "Golett", "Golurk", "Gothitelle", "Gothorita", "Solosis", "Duosion", "Reuniclus", "Deerling-Summer", "Deerling-Autumn", "Deerling-Winter", "Sawsbuck-Summer", "Sawsbuck-Autumn", "Sawsbuck-Winter", "Roserade", "Mewtwo"];
var halist = dwlist.concat(["Gothita", "Rufflet", "Klefki", "Phantump", "Trevenant", "Axew", "Fraxure", "Haxorus", "Carbink", "Scatterbug", "Spewpa", "Vivillon", "Sandile", "Krokorok", "Krookodile", "Inkay", "Malamar", "Noibat", "Noivern", "Goomy", "Sliggoo", "Goodra", "Dedenne", "Helioptile", "Heliolisk", "Spritzee", "Aromatisse", "Swirlix", "Slurpuff", "Flabébé", "Floette", "Florges", "Pancham", "Pangoro", "Larvesta", "Volcarona", "Litleo", "Pyroar", "Fennekin", "Braixen", "Delphox", "Fletchling", "Fletchinder", "Talonflame", "Hawlucha", "Litwick", "Lampent", "Chandelure", "Pumpkaboo", "Pumpkaboo-S", "Pumpkaboo-L", "Pumpkaboo-XL", "Gourgeist", "Gourgeist-S", "Gourgeist-L", "Gourgeist-XL", "Duskull", "Dusclops", "Dusknoir", "Chespin", "Quilladin", "Chesnaught", "Skiddo", "Gogoat", "Bunnelby", "Diggersby", "Bergmite", "Avalugg", "Espurr", "Meowstic", "Meowstic-F", "Binacle", "Barbaracle", "Froakie", "Frogadier", "Greninja", "Sylveon"]);
//two lists for gen 5 and gen 6
/* use hash for faster lookup */
dwpokemons = {};
script.hapokemons = {};
var announceChan = (typeof staffchannel == "number") ? staffchannel : 0;
var dwpok;
for (dwpok = 0; dwpok < halist.length; dwpok++) {
var num = sys.pokeNum(halist[dwpok]);
if (halist[dwpok] === "Gourgeist-XL" || halist[dwpok] === "Pumpkaboo-XL") { //temporary until pokeNum is fixed
num = (halist[dwpok] === "Gourgeist-XL" ? (65536*3)+711 : (65536*3)+710);
}
if (num === undefined)
sys.sendAll("Script Check: Unknown poke in hapokemons: '" +halist[dwpok]+"'.", announceChan);
else if (script.hapokemons[num] === true)
sys.sendAll("Script Check: hapokemons contains '" +halist[dwpok]+"' multiple times.", announceChan);
else {
script.hapokemons[num] = true;
if (dwlist.indexOf(halist[dwpok]) > -1) {
dwpokemons[num] = true;
}
}
}
var lclist = ["Bulbasaur", "Charmander", "Squirtle", "Croagunk", "Turtwig", "Chimchar", "Piplup", "Treecko", "Torchic", "Mudkip", "Pansage", "Pansear", "Panpour"];
lcpokemons = lclist.map(sys.pokeNum);
lcmoves = {
"Bronzor":["Iron Defense"],
"Golett":["Rollout","Shadow Punch","Iron Defense","Mega Punch","Magnitude","DynamicPunch","Night Shade","Curse","Hammer Arm","Focus Punch"],
"Klink":["Charge","Thundershock","Gear Grind","Bind","Mirror Shot","Screech","Discharge","Metal Sound","Shift Gear","Lock-On","Zap Cannon"],
"Petilil":["Entrainment"],
"Rufflet":["Wing Attack","Scary Face","Slash","Defog","Air Slash","Crush Claw","Whirlwind","Brave Bird","Thrash"]
};
bannedGSCSleep = [sys.moveNum("Spore"), sys.moveNum("Hypnosis"), sys.moveNum("Lovely Kiss"), sys.moveNum("Sing"), sys.moveNum("Sleep Powder")].sort();
bannedGSCTrap = [sys.moveNum("Mean Look"), sys.moveNum("Spider Web")].sort();
var breedingList = ["Bulbasaur", "Ivysaur", "Venusaur", "Charmander", "Charmeleon", "Charizard", "Squirtle", "Wartortle", "Blastoise", "Croagunk", "Toxicroak", "Turtwig", "Grotle", "Torterra", "Chimchar", "Monferno", "Infernape", "Piplup", "Prinplup", "Empoleon", "Treecko", "Grovyle", "Sceptile", "Torchic", "Combusken", "Blaziken", "Mudkip", "Marshtomp", "Swampert", "Hitmonlee","Hitmonchan","Hitmontop","Tyrogue", "Porygon", "Porygon2", "Porygon-Z", "Gothorita", "Gothitelle","Pansage", "Pansear", "Panpour", "Simisear", "Simisage", "Simipour"];
breedingpokemons = breedingList.map(sys.pokeNum);
/* restore mutes, smutes, mafiabans, rangebans, megausers */
script.mutes = new MemoryHash(Config.dataDir+"mutes.txt");
script.mbans = new MemoryHash(Config.dataDir+"mbans.txt");
script.smutes = new MemoryHash(Config.dataDir+"smutes.txt");
script.rangebans = new MemoryHash(Config.dataDir+"rangebans.txt");
script.contributors = new MemoryHash(Config.dataDir+"contributors.txt");
script.mafiaAdmins = new MemoryHash(Config.dataDir+"mafiaadmins.txt");
script.mafiaSuperAdmins = new MemoryHash(Config.dataDir+"mafiasuperadmins.txt");
script.hangmanAdmins = new MemoryHash(Config.dataDir+"hangmanadmins.txt");
script.hangmanSuperAdmins = new MemoryHash(Config.dataDir+"hangmansuperadmins.txt");
script.ipbans = new MemoryHash(Config.dataDir+"ipbans.txt");
script.detained = new MemoryHash(Config.dataDir+"detained.txt");
script.hmutes = new MemoryHash(Config.dataDir+"hmutes.txt");
script.namesToWatch = new MemoryHash(Config.dataDir+"namesToWatch.txt");
script.namesToUnban = new MemoryHash(Config.dataDir+"namesToCookieUnban.txt");
proxy_ips = {};
function addProxybans(content) {
var lines = content.split(/\n/);
for (var k = 0; k < lines.length; ++k) {
var proxy_ip = lines[k].split(":")[0];
if (proxy_ip !== 0) proxy_ips[proxy_ip] = true;
}
}
var PROXY_FILE = "proxy_list.txt";
var content = sys.getFileContent(PROXY_FILE);
if (content) { addProxybans(content); }
else sys.webCall(Config.base_url + PROXY_FILE, addProxybans);
rules = [ "",
"*** Pokémon Online Server Rules ***",
"",
"1. Pokemon Online is an international server:",
"- Respect other peoples' cultures and do not demand they speak English. Everyone is welcome at Pokemon Online, as long as they follow the rules.",
"2. No advertising, excessive messages, inappropriate/obscene links, or text art:",
"- Do not post links unless they are to notable sites (Youtube, Smogon, Serebii, etc). We are not interested in your start-up community. Do not monopolize the chat with large amounts of messages, or short ones in rapid succession. Posting ASCII art is punishable with a ban, as is posting anything with any type of pornography.",
"3. Use Find Battle, or join tournaments instead of asking in the main chat:",
"- The official channels on Pokemon Online have too much activity to allow battle requests in the chat. Use Find Battle or go join the tournaments channel and participate. The only exception is if you are unable to find a battle for a low-played tier, then asking once every 5 minutes or so is acceptable.",
"4. Do not ask for authority:",
"- By asking, you may have eliminated your chances of becoming one in the future. If you are genuinely interested in becoming a staff member then a good way to get noticed is to become an active member of the community. Engaging others in intelligent chats and offering to help with graphics, programming, the wiki, or our YouTube channel (among others) is a good way to get noticed.",
"5. No trolling, flaming, or harassing other players. Do not complain about hax in the chat, beyond a one line comment:",
"- Inciting responses with inflammatory comments, using verbal abuse against other players, or spamming them via chat/PM/challenges will not be tolerated. Harassing other players by constantly aggravating them or revealing personal information will be severely punished. A one line comment regarding hax after a loss to vent is fine, but excessive bemoaning is not acceptable. Excessive vulgarity will not be tolerated. Wasting the time of the authority will also result in punishment.",
"6. Do not attempt to circumvent the rules:",
"- Ignorance of the rules is not a valid reason for breaking them. Do not attempt to find or create any loopholes in these rules, or try to adapt them in order to have a punishment overturned or to justify your actions. Doing so may incur a further punishment. Make valid appeals directly to the authority of the server."
];
if (typeof script.authStats == 'undefined')
script.authStats = {};
if (typeof nameBans == 'undefined') {
nameBans = [];
try {
var serialized = JSON.parse(sys.getFileContent("scriptdata/nameBans.json"));
for (var i = 0; i < serialized.nameBans.length; ++i) {
nameBans.push(new RegExp(serialized.nameBans[i], "i"));
}
} catch (e) {
// ignore
}
}
if (typeof nameWarns == 'undefined') {
nameWarns = [];
try {
var serialized = JSON.parse(sys.getFileContent("scriptdata/nameWarns.json"));
for (var i = 0; i < serialized.nameWarns.length; ++i) {
nameWarns.push(new RegExp(serialized.nameWarns[i], "i"));
}
} catch (e) {
// ignore
}
}
if (SESSION.global().battleinfo === undefined) {
SESSION.global().battleinfo = {};
}
if (SESSION.global().BannedUrls === undefined) {
SESSION.global().BannedUrls = [];
sys.webCall(Config.base_url + "bansites.txt", function(resp) {
SESSION.global().BannedUrls = resp.toLowerCase().split(/\n/);
});
}
isSuperAdmin = function(id) {
if (typeof Config.superAdmins != "object" || Config.superAdmins.length === undefined) return false;
if (sys.auth(id) != 2) return false;
var name = sys.name(id);
for (var i = 0; i < Config.superAdmins.length; ++i) {
if (script.cmp(name, Config.superAdmins[i]))
return true;
}
return false;
};
if (typeof VarsCreated != 'undefined')
return;
key = function(a,b) {
return a + "*" + sys.ip(b);
};
script.saveKey = function(thing, id, val) {
sys.saveVal(key(thing,id), val);
};
script.getKey = function(thing, id) {
return sys.getVal(key(thing,id));
};
script.cmp = function(a, b) {
return a.toLowerCase() == b.toLowerCase();
};
script.isMafiaAdmin = require('mafia.js').isMafiaAdmin;
script.isMafiaSuperAdmin = require('mafia.js').isMafiaSuperAdmin;
battlesStopped = false;
maxPlayersOnline = 0;
lineCount = 0;
script.pokeNatures = [];
var list = "Heatran-Eruption/Quiet=Suicune-Extreme Speed/Relaxed|Sheer Cold/Relaxed|Aqua Ring/Relaxed|Air Slash/Relaxed=Raikou-Extreme Speed/Rash|Weather Ball/Rash|Zap Cannon/Rash|Aura Sphere/Rash=Entei-Extreme Speed/Adamant|Flare Blitz/Adamant|Howl/Adamant|Crush Claw/Adamant=Snivy-Aromatherapy/Hardy|Synthesis/Hardy=Genesect-Extreme Speed/Hasty|Blaze Kick/Hasty|Shift Gear/Hasty";
//this is really awful btw :(
var sepPokes = list.split('='),
sepMovesPoke, sepMoves, movenat;
for (var x = 0; x < sepPokes.length; x++) {
sepMovesPoke = sepPokes[x].split('-');
sepMoves = sepMovesPoke[1].split('|');
var poke = sys.pokeNum(sepMovesPoke[0]);
script.pokeNatures[poke] = [];
for (var y = 0; y < sepMoves.length; ++y) {
movenat = sepMoves[y].split('/');
script.pokeNatures[poke][sys.moveNum(movenat[0])] = sys.natureNum(movenat[1]);
}
}
script.pokeAbilities = [];
var Ablist = "Bulbasaur-False Swipe/Overgrow|Block/Overgrow|Frenzy Plant/Overgrow|Weather Ball/Overgrow=Ivysaur-False Swipe/Overgrow|Block/Overgrow|Frenzy Plant/Overgrow|Weather Ball/Overgrow=Venusaur-False Swipe/Overgrow|Block/Overgrow|Weather Ball/Overgrow=Charmander-False Swipe/Blaze|Block/Blaze|Blast Burn/Blaze|Acrobatics/Blaze=Charmeleon-False Swipe/Blaze|Block/Blaze|Blast Burn/Blaze|Acrobatics/Blaze=Charizard-False Swipe/Blaze|Block/Blaze|Acrobatics/Blaze=Squirtle-False Swipe/Torrent|Block/Torrent|Hydro Cannon/Torrent|Follow Me/Torrent=Wartortle-False Swipe/Torrent|Block/Torrent|Hydro Cannon/Torrent|Follow Me/Torrent=Blastoise-False Swipe/Torrent|Block/Torrent|Follow Me/Torrent";
//Terrible, but it works!
//Bulba line: Weather Ball, Frenzy Plant, False Swipe, Block
//Charm line: Acrobatics, Blast Burn, False Swipe, Block
//Squirt line: Follow Me, Hydro Cannon, False Swipe, Block
var sepAbPokes = Ablist.split('='),
sepAbMovesPoke, sepAb, moveab;
for (var x = 0; x < sepAbPokes.length; x++) {
sepAbMovesPoke = sepAbPokes[x].split('-');
sepAb = sepAbMovesPoke[1].split('|');
var poke = sys.pokeNum(sepAbMovesPoke[0]);
script.pokeAbilities[poke] = [];
for (var y = 0; y < sepAb.length; ++y) {
moveab = sepAb[y].split('/');
script.pokeAbilities[poke][sys.moveNum(moveab[0])] = sys.abilityNum(moveab[1]);
}
}
if (typeof script.chanNameBans == 'undefined') {
script.chanNameBans = [];
try {
var serialized = JSON.parse(sys.getFileContent(Config.dataDir+"chanNameBans.json"));
for (var i = 0; i < serialized.chanNameBans.length; ++i) {
script.chanNameBans.push(new RegExp(serialized.chanNameBans[i], "i"));
}
} catch (e) {
// ignore
}
}
try {
pastebin_api_key = sys.getFileContent(Config.dataDir+"pastebin_api_key").replace("\n", "");
pastebin_user_key = sys.getFileContent(Config.dataDir+"pastebin_user_key").replace("\n", "");
} catch(e) {
normalbot.sendAll("Couldn't load api keys: " + e, staffchannel);
}
sendMainTour = function(message) {
sys.sendAll(message, 0);
sys.sendAll(message, tourchannel);
};
script.allowedRangeNames = sys.getFileContent(Config.dataDir + "rangewhitelist.txt").split("\n");
callplugins("init");
VarsCreated = true;
}, /* end of init */
issueBan : function(type, src, tar, commandData, maxTime) {
var memoryhash = {"mute": script.mutes, "mban": script.mbans, "smute": script.smutes, "hmute": script.hmutes}[type];
var banbot;
if (type == "mban") {
banbot = mafiabot;
}
else if (type == "hmute") {
banbot = hangbot;
}
else {
banbot = normalbot;
}
var verb = {"mute": "muted", "mban": "banned from mafia", "smute": "secretly muted", "hmute": "banned from hangman"}[type];
var nomi = {"mute": "mute", "mban": "ban from mafia", "smute": "secret mute", "hmute": "ban from hangman"}[type];
var sendAll = {
"smute": function(line) {
sys.dbAuths().map(sys.id).filter(function(uid) { return uid !== undefined; }).forEach(function(uid) {
banbot.sendMessage(uid, line);
});
},
"mban": function(line) {
banbot.sendAll(line, staffchannel);
banbot.sendAll(line, mafiachan);
banbot.sendAll(line, sachannel);
},
"mute": function(line) {
banbot.sendAll(line);
},
"hmute" : function(line) {
banbot.sendAll(line, staffchannel);
banbot.sendAll(line, hangmanchan);
banbot.sendAll(line, sachannel);
}
}[type];
var expires = 0;
var defaultTime = {"mute": "24h", "mban": "1d", "smute": "0", "hmute": "1d"}[type];
var reason = "";
var timeString = "";
var tindex = 10;
var data = [];
var ip;
if (tar === undefined) {
data = commandData.split(":");
if (data.length > 1) {
commandData = data[0];
tar = sys.id(commandData);
if (data.length > 2 && /http$/.test(data[1])) {
reason = data[1] + ":" + data[2];
tindex = 3;
} else {
reason = data[1];
tindex = 2;
}
if (tindex==data.length && reason.length > 0 && reason.charCodeAt(0) >= 48 && reason.charCodeAt(0) <= 57) {
tindex-=1;
reason="";
}
}
}
var secs = getSeconds(data.length > tindex ? data[tindex] : defaultTime);
// limit it!
if (typeof maxTime == "number") secs = (secs > maxTime || secs === 0 || isNaN(secs)) ? maxTime : secs;
if (secs > 0) {
timeString = getTimeString(secs);
expires = secs + parseInt(sys.time(), 10);
}
if (reason === "" && sys.auth(src) < 3) {
banbot.sendMessage(src, "You need to give a reason to the " + nomi + "!", channel);
return;
}
var tarip = tar !== undefined ? sys.ip(tar) : sys.dbIp(commandData);
if (tarip === undefined) {
banbot.sendMessage(src, "Couldn't find " + commandData, channel);
return;
}
var maxAuth = (tar ? sys.auth(tar) : sys.maxAuth(tarip));
if (maxAuth>=sys.auth(src) && maxAuth > 0) {
banbot.sendMessage(src, "You don't have sufficient auth to " + nomi + " " + commandData + ".", channel);
return;
}
var active = false;
if (memoryhash.get(tarip)) {
if (sys.time() - memoryhash.get(tarip).split(":")[0] < 15) {
banbot.sendMessage(src, "This person was recently " + verb, channel);
return;
}
active = true;
}
if (sys.loggedIn(tar)) {
if (SESSION.users(tar)[type].active) {
active = true;
}
}
sys.playerIds().forEach(function(id) {
if (sys.loggedIn(id) && sys.ip(id) === tarip)
SESSION.users(id).activate(type, sys.name(src), expires, reason, true);
});
if (!sys.loggedIn(tar)) {
memoryhash.add(tarip, sys.time() + ":" + sys.name(src) + ":" + expires + ":" + commandData + ":" + reason);
}
sendAll((active ? nonFlashing(sys.name(src)) + " changed " + commandData + "'s " + nomi + " time to " + (timeString === "" ? "forever!" : timeString + " from now!") : commandData + " was " + verb + " by " + nonFlashing(sys.name(src)) + (timeString === "" ? "" : " for ") + timeString + "!") + (reason.length > 0 ? " [Reason: " + reason + "]" : "") + " [Channel: "+sys.channel(channel) + "]");
var authority= sys.name(src).toLowerCase();
script.authStats[authority] = script.authStats[authority] || {};
script.authStats[authority]["latest" + type] = [commandData, parseInt(sys.time(), 10)];
},
unban: function(type, src, tar, commandData) {
var memoryhash = {"mute": script.mutes, "mban": script.mbans, "smute": script.smutes, "hmute": script.hmutes}[type];
var banbot;
if (type == "mban") {
banbot = mafiabot;
}
else if (type == "hmute") {
banbot = hangbot;
}
else {
banbot = normalbot;
}
var verb = {"mute": "unmuted", "mban": "unbanned from mafia", "smute": "secretly unmuted", "hmute": "unbanned from hangman"}[type];
var nomi = {"mute": "mute", "mban": "ban from mafia", "smute": "secret mute", "hmute": "ban from hangman"}[type];
var past = {"mute": "muted", "mban": "banned from mafia", "smute": "secretly muted", "hmute": "banned from hangman"}[type];
var sendAll = {
"smute": function(line) {
banbot.sendAll(line, staffchannel);
},
"mban": function(line, ip) {
if (ip) {
banbot.sendAll(line, staffchannel);
banbot.sendAll(line, sachannel);
} else {
banbot.sendAll(line, staffchannel);
banbot.sendAll(line, mafiachan);
banbot.sendAll(line, sachannel);
}
},
"mute": function(line, ip) {
if (ip) {
banbot.sendAll(line, staffchannel);
} else {
banbot.sendAll(line);
}
},
"hmute" : function(line, ip) {
if (ip) {
banbot.sendAll(line, staffchannel);
banbot.sendAll(line, sachannel);
} else {
banbot.sendAll(line, hangmanchan);
banbot.sendAll(line, sachannel);
banbot.sendAll(line, staffchannel);
}
}
}[type];
if (tar === undefined) {
if (memoryhash.get(commandData)) {
sendAll("IP address " + commandData + " was " + verb + " by " + nonFlashing(sys.name(src)) + "!", true);
memoryhash.remove(commandData);
return;
}
var ip = sys.dbIp(commandData);
if(ip !== undefined && memoryhash.get(ip)) {
sendAll("" + commandData + " was " + verb + " by " + nonFlashing(sys.name(src)) + "!");
memoryhash.remove(ip);
return;
}
banbot.sendMessage(src, "He/she's not " + past, channel);
return;
}
if (!SESSION.users(sys.id(commandData))[type].active) {
banbot.sendMessage(src, "He/she's not " + past, channel);
return;
}
if(SESSION.users(src)[type].active && tar == src) {
banbot.sendMessage(src, "You may not " + nomi + " yourself!", channel);
return;
}
SESSION.users(tar).un(type);
sendAll("" + commandData + " was " + verb + " by " + nonFlashing(sys.name(src)) + "!");
},
banList: function (src, command, commandData) {
var mh;
var name;
if (command == "mutelist") {
mh = script.mutes;
name = "Muted list";
} else if (command == "smutelist") {
mh = script.smutes;
name = "Secretly muted list";
} else if (command == "mafiabans") {
mh = script.mbans;
name = "Mafiabans";
} else if (command == "hangmanmutes" || command == "hangmanbans") {
mh = script.hmutes;
name = "Hangman Bans";
}
var width=5;
var max_message_length = 30000;
var tmp = [];
var t = parseInt(sys.time(), 10);
var toDelete = [];
for (var ip in mh.hash) {
if (mh.hash.hasOwnProperty(ip)) {
var values = mh.hash[ip].split(":");
var banTime = 0;
var by = "";
var expires = 0;
var banned_name;
var reason = "";
if (values.length >= 5) {
banTime = parseInt(values[0], 10);
by = values[1];
expires = parseInt(values[2], 10);
banned_name = values[3];
reason = values.slice(4);
if (expires !== 0 && expires < t) {
toDelete.push(ip);
continue;
}
} else if (command == "smutelist") {
var aliases = sys.aliases(ip);
if (aliases[0] !== undefined) {
banned_name = aliases[0];
} else {
banned_name = "~Unknown~";
}
} else {
banTime = parseInt(values[0], 10);
}
if(typeof commandData != 'undefined' && (!banned_name || banned_name.toLowerCase().indexOf(commandData.toLowerCase()) == -1))
continue;
tmp.push([ip, banned_name, by, (banTime === 0 ? "unknown" : getTimeString(t-banTime)), (expires === 0 ? "never" : getTimeString(expires-t)), utilities.html_escape(reason)]);
}
}
for (var k = 0; k < toDelete.length; ++k)
delete mh.hash[toDelete[k]];
if (toDelete.length > 0)
mh.save();
tmp.sort(function(a,b) { return a[3] - b[3];});
// generate HTML
var table_header = '<table border="1" cellpadding="5" cellspacing="0"><tr><td colspan="' + width + '"><center><strong>' + utilities.html_escape(name) + '</strong></center></td></tr><tr><th>IP</th><th>Name</th><th>By</th><th>Issued ago</th><th>Expires in</th><th>Reason</th>';
var table_footer = '</table>';
var table = table_header;
var line;
var send_rows = 0;
while(tmp.length > 0) {
line = '<tr><td>'+tmp[0].join('</td><td>')+'</td></tr>';
tmp.splice(0,1);
if (table.length + line.length + table_footer.length > max_message_length) {
if (send_rows === 0) continue; // Can't send this line!
table += table_footer;
sys.sendHtmlMessage(src, table, channel);
table = table_header;
send_rows = 0;
}
table += line;
++send_rows;
}
table += table_footer;
if (send_rows > 0)
sys.sendHtmlMessage(src, table, channel);
return;
},
importable : function(id, team, compactible) {
/*
Tyranitar (M) @ Choice Scarf
Lvl: 100
Trait: Sand Stream
IVs: 0 Spd
EVs: 4 HP / 252 Atk / 252 Spd
Jolly Nature (+Spd, -SAtk)
- Stone Edge
- Crunch
- Superpower
- Pursuit
*/
if (compactible === undefined) compactible = false;
var nature_effects = {"Adamant": "(+Atk, -SAtk)", "Bold": "(+Def, -Atk)"};
var genders = {0: '', 1: ' (M)', 2: ' (F)'};
var stat = {0: 'HP', 1: 'Atk', 2: 'Def', 3: 'SAtk', 4: 'SDef', 5:'Spd'};
var hpnum = sys.moveNum("Hidden Power");
var ret = [];
for (var i = 0; i < 6; ++i) {
var poke = sys.teamPoke(id, team, i);
if (poke === undefined)
continue;
// exclude missingno
if (poke === 0)
continue;
var item = sys.teamPokeItem(id, team, i);
item = item !== undefined ? sys.item(item) : "(no item)";
ret.push(sys.pokemon(poke) + genders[sys.teamPokeGender(id, team, i)] + " @ " + item );
ret.push('Trait: ' + sys.ability(sys.teamPokeAbility(id, team, i)));
var level = sys.teamPokeLevel(id, team, i);
if (!compactible && level != 100) ret.push('Lvl: ' + level);
var ivs = [];
var evs = [];
var hpinfo = [sys.gen(id, team)];
for (var j = 0; j < 6; ++j) {
var iv = sys.teamPokeDV(id, team, i, j);
if (iv != 31) ivs.push(iv + " " + stat[j]);
var ev = sys.teamPokeEV(id, team, i, j);
if (ev !== 0) evs.push(ev + " " + stat[j]);
hpinfo.push(iv);
}
if (!compactible && ivs.length > 0)
ret.push('IVs: ' + ivs.join(" / "));
if (evs.length > 0)
ret.push('EVs: ' + evs.join(" / "));
ret.push(sys.nature(sys.teamPokeNature(id, team, i)) + " Nature"); // + (+Spd, -Atk)
for (j = 0; j < 4; ++j) {
var move = sys.teamPokeMove(id, team, i, j);
if (move !== undefined) {
ret.push('- ' + sys.move(move) + (move == hpnum ? ' [' + sys.type(sys.hiddenPowerType.apply(sys, hpinfo)) + ']':''));
}
}
ret.push("");
}
return ret;
},
canJoinStaffChannel : function(src) {
var disallowedNames = Config.disallowStaffChannel;
if (disallowedNames.indexOf(sys.name(src)) > -1)
return false;
if (sys.auth(src) > 0)
return true;
if (SESSION.users(src).megauser)
return true;
if (SESSION.users(src).contributions !== undefined)
return true;
var allowedNames = Config.canJoinStaffChannel;
if (allowedNames.indexOf(sys.name(src)) > -1)
return true;
return false;
},
isOfficialChan : function (chanid) {
var officialchans = [0, tourchannel, mafiachan, triviachan, hangmanchan];
if (officialchans.indexOf(chanid) > -1)
return true;
else