-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathpastebin-es.js
More file actions
617 lines (470 loc) · 17.1 KB
/
pastebin-es.js
File metadata and controls
617 lines (470 loc) · 17.1 KB
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
// Pastebin add-on
// ----------------
// Includes a set of commands to configure things in bulk with a pastebin link
// Note: The GET commands require you to set up the 'Control panel Url' option (Admin section of the control panel)
// ----------------
//
// - setrand: Sets all the options for a random command.
// The pastebin link must have each option in each line.
//
// -----------------------------------------------------------------
//
// - getkuncdata: Exports the data for the Kunc game.
// - setkuncdata: Imports the data for the Kunc game
//
// The Kunc data has the following format (one each line):
// - Species||move1,move2...
// Example:
// - Pikachu||Thunderbolt,Fake Out,Iron Tail,Extreme Speed
//
// -----------------------------------------------------------------
//
// - gettriviadata: Exports the data for the Trivia game.
// - settriviadata: Imports the data for the Trivia game
//
// The Trivia data has the following format (one each line):
// - Clue||answer,answer...
// Example:
// - Which is the fastest Pokemon?||Regieleki
//
// -----------------------------------------------------------------
//
// - gethangmandata: Exports the data for the Hangman game.
// - sethangmandata: Imports the data for the Hangman game
//
// The Hangman data has the following format (one each line):
// - Clue||word,word...
// Example:
// - Fruit||Apple,Orange,Strawberry,Pear
//
// -----------------------------------------------------------------
//
// - getanagramsdata: Exports the data for the Anagrams game.
// - setanagramsdata: Imports the data for the Anagrams game
//
// The Anagrams data has the following format (one each line):
// - Clue||word,word...
// Example:
// - Fruit||Apple,Orange,Strawberry,Pear
//
// ------------------------------------------------------------------
'use strict';
// Name of the permission required for the commands
const PERMISSION_REQUIRED = 'randadmin';
const Text = Tools('text');
const Chat = Tools('chat');
const HTTPS = require('https');
const Url = require('url');
function wget(url, callback) {
url = Url.parse(url);
HTTPS.get(url.href, response => {
if (response.statusCode !== 200) {
if (response.statusCode === 404) {
return callback(null, new Error("404 - Not found"));
} else {
return callback(null, new Error("" + response.statusCode));
}
}
let data = '';
response.on('data', chunk => {
data += chunk;
});
response.on('end', () => {
callback(data);
});
response.on('error', err => {
callback(null, err);
});
}).on('error', err => {
callback(null, err);
});
}
exports.setup = function (App) {
return Tools('add-on').forApp(App).install({
/* Add-on Commands */
commandsOverwrite: true,
commands: {
setrand: function () {
if (!this.can(PERMISSION_REQUIRED, this.room)) return this.replyAccessDenied(PERMISSION_REQUIRED);
let Mod = App.modules.randcmd.system;
if (this.args.length !== 2) {
return this.errorReply(this.usage({ desc: "Comando" }, { desc: "Link a Pastebin - Tendrá cada opción del comando en una línea" }));
}
const cmd = Text.toId(this.args[0]);
let link = (this.args[1] + "").trim();
let linkRegex = /^https:\/\/pastebin\.com\/([A-Za-z0-9]+)/;
let linkRes = linkRegex.exec(link);
if (!linkRes) {
return this.errorReply("El enlace a Pastebin no es correcto.");
}
wget("https://pastebin.com/raw/" + linkRes[1] + "", function (data, err) {
if (err) {
return this.errorReply("No se pudo obtener el Pastebin desde el enlace. Error: " + err.message);
}
let discardCount = 0;
let lines = data.split("\n");
if (lines.length > 2048) {
return this.errorReply("La lista de opciones no puede contener más de 2048 elementos.");
}
lines = lines.map(d => {
return d.trim();
}).filter(d => {
if (!d) {
return false;
}
if (d.startsWith("/addhtmlbox")) {
if (d.length <= (16 * 1000)) {
return true;
} else {
discardCount++;
return false;
}
} else {
if (d.length <= 300) {
return true;
} else {
discardCount++;
return false;
}
}
});
if (lines.length === 0) {
return this.errorReply("La lista de opciones no puede estar vacía." + (discardCount > 0 ? (" (Se descartaron " + discardCount + " " + (discardCount === 1 ? "opción" : "opciones") + " con longitud no válida)") : ""));
}
Mod.data.commands[cmd] = lines.join("\n");
Mod.db.write();
this.addToSecurityLog();
this.reply("Se ha configurado el comando aleatorio: " + Chat.italics(this.token + cmd) + (discardCount > 0 ? (" (Se descartaron " + discardCount + " " + (discardCount === 1 ? "opción" : "opciones") + " con longitud no válida)") : ""));
}.bind(this));
},
getkuncdata: function () {
if (!this.can(PERMISSION_REQUIRED, this.room)) return this.replyAccessDenied(PERMISSION_REQUIRED);
const data = App.modules.games.system.templates.kunc.data;
let text = "";
for (let set of data.sets) {
text += set.species + "||" + (set.moves || []).join(", ") + "\n";
}
let key = App.data.temp.createTempFile(
"<html>" +
"<body><p>" +
Text.escapeHTML(text).replace(/\n/g, "<br>") +
"</p></body>" +
"</html>"
);
this.reply("Sets para el juego Kunc: " + App.server.getControlPanelLink('/temp/' + key));
},
setkuncdata: function () {
if (!this.can(PERMISSION_REQUIRED, this.room)) return this.replyAccessDenied(PERMISSION_REQUIRED);
if (this.args.length !== 1 || !this.args[0]) {
return this.errorReply(this.usage({ desc: "Link a Pastebin - Tendrá un set en cada linea, con formato: Pokemon || Movimiento, Movimiento, Movimiento, Movimiento" }));
}
const modData = App.modules.games.system.templates.kunc.data;
const db = App.modules.games.system.templates.kunc.db;
let link = (this.args[0] + "").trim();
let linkRegex = /^https:\/\/pastebin\.com\/([A-Za-z0-9]+)/;
let linkRes = linkRegex.exec(link);
if (!linkRes) {
return this.errorReply("El enlace a Pastebin no es correcto.");
}
const pokedex = App.data.getPokedex();
const movedex = App.data.getMoves();
wget("https://pastebin.com/raw/" + linkRes[1] + "", function (data, err) {
if (err) {
return this.errorReply("No se pudo obtener el Pastebin desde el enlace. Error: " + err.message);
}
let sets = [];
let lines = data.split("\n");
if (lines.length > 5000) {
return this.errorReply("Error: No se admiten más de 5000 sets.");
}
let lineCount = 0;
for (let line of lines) {
line = line.trim();
lineCount++;
if (!line) {
continue;
}
let spl = line.split("||");
if (spl.length !== 2) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin no tiene el formato correcto.");
}
const poke = pokedex[Text.toId(spl[0])];
if (!poke) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin especifica un Pokemon inexistente: " + spl[0].substr(0, 80));
}
let moves = [];
spl = spl[1].split(",");
for (let s of spl) {
if (!Text.toId(s)) {
continue;
}
const move = movedex[Text.toId(s)];
if (!move) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin especifica un movimiento inexistente: " + s.substr(0, 80));
}
moves.push(move);
}
if (moves.length === 0) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin contiene un set sin movimientos válidos.");
}
if (moves.length > 4) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin contiene más de 4 movimientos.");
}
sets.push({
species: poke.name,
moves: moves.map(m => {
return m.name;
}),
});
}
if (sets.length === 0) {
return this.errorReply("Error: La lista de sets no puede estar vacía");
}
modData.sets = sets;
db.write();
this.addToSecurityLog();
this.reply("Los sets para el juego Kunc han sido modificados correctamente.");
}.bind(this));
},
gettriviadata: function () {
if (!this.can(PERMISSION_REQUIRED, this.room)) return this.replyAccessDenied(PERMISSION_REQUIRED);
const data = App.modules.games.system.templates.trivia.data;
let text = "";
for (let id of Object.keys(data)) {
text += data[id].clue + "||" + (data[id].answers || []).join(", ") + "\n";
}
let key = App.data.temp.createTempFile(
"<html>" +
"<body><p>" +
Text.escapeHTML(text).replace(/\n/g, "<br>") +
"</p></body>" +
"</html>"
);
this.reply("Preguntas para el juego de Trivia: " + App.server.getControlPanelLink('/temp/' + key));
},
settriviadata: function () {
if (!this.can(PERMISSION_REQUIRED, this.room)) return this.replyAccessDenied(PERMISSION_REQUIRED);
if (this.args.length !== 1 || !this.args[0]) {
return this.errorReply(this.usage({ desc: "Link a Pastebin - Tendrá una pregunta en cada línea, con formato: Pregunta || Respuesta, Respuesta..." }));
}
let mod = App.modules.games.system.templates.trivia;
let link = (this.args[0] + "").trim();
let linkRegex = /^https:\/\/pastebin\.com\/([A-Za-z0-9]+)/;
let linkRes = linkRegex.exec(link);
if (!linkRes) {
return this.errorReply("El enlace a Pastebin no es correcto.");
}
wget("https://pastebin.com/raw/" + linkRes[1] + "", function (data, err) {
if (err) {
return this.errorReply("No se pudo obtener el Pastebin desde el enlace. Error: " + err.message);
}
let questions = [];
let lines = data.split("\n");
if (lines.length > 5000) {
return this.errorReply("Error: No se admiten más de 5000 preguntas.");
}
let lineCount = 0;
for (let line of lines) {
line = line.trim();
lineCount++;
if (!line) {
continue;
}
let spl = line.split("||");
if (spl.length !== 2) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin no tiene el formato correcto.");
}
const clue = spl[0].trim();
if (!clue || clue.length > 200) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin contiene una pregunta no válida.");
}
const answers = spl[1].split(",").map(a => {
return a.trim();
}).filter(a => {
return !!a && a.length < 100;
});
if (answers.length === 0) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin contiene una pregunta sin respuestas.");
}
questions.push({
clue: clue,
answers: answers,
});
}
if (questions.length === 0) {
return this.errorReply("Error: La lista de preguntas no puede estar vacía");
}
for (let id in Object.keys(mod.data)) {
delete mod.data[id];
}
for (let q of questions) {
mod.addQuestion(q.clue, q.answers);
}
mod.db.write();
this.addToSecurityLog();
this.reply("Las preguntas del juego de Trivia han sido modificadas correctamente.");
}.bind(this));
},
gethangmandata: function () {
if (!this.can(PERMISSION_REQUIRED, this.room)) return this.replyAccessDenied(PERMISSION_REQUIRED);
const data = App.modules.games.system.templates.wordgames.data;
let text = "";
for (let group of Object.keys(data)) {
text += group + "||" + (data[group] || []).join(", ") + "\n";
}
let key = App.data.temp.createTempFile(
"<html>" +
"<body><p>" +
Text.escapeHTML(text).replace(/\n/g, "<br>") +
"</p></body>" +
"</html>"
);
this.reply("Palabras para el juego Hangman: " + App.server.getControlPanelLink('/temp/' + key));
},
sethangmandata: function () {
if (!this.can(PERMISSION_REQUIRED, this.room)) return this.replyAccessDenied(PERMISSION_REQUIRED);
if (this.args.length !== 1 || !this.args[0]) {
return this.errorReply(this.usage({ desc: "Link a Pastebin - Tendrá un grupo de palabras en cada línea, con formato: Pista del Grupo || Palabra, Palabra..." }));
}
let mod = App.modules.games.system.templates.wordgames;
let link = (this.args[0] + "").trim();
let linkRegex = /^https:\/\/pastebin\.com\/([A-Za-z0-9]+)/;
let linkRes = linkRegex.exec(link);
if (!linkRes) {
return this.errorReply("El enlace a Pastebin no es correcto.");
}
wget("https://pastebin.com/raw/" + linkRes[1] + "", function (data, err) {
if (err) {
return this.errorReply("No se pudo obtener el Pastebin desde el enlace. Error: " + err.message);
}
let groups = [];
let lines = data.split("\n");
if (lines.length > 5000) {
return this.errorReply("Error: No se admiten más de 5000 grupos.");
}
let lineCount = 0;
for (let line of lines) {
line = line.trim();
lineCount++;
if (!line) {
continue;
}
let spl = line.split("||");
if (spl.length !== 2) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin no tiene el formato correcto.");
}
const group = spl[0].trim();
if (!group || group.length > 200) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin contiene un grupo válido.");
}
const words = spl[1].split(",").map(a => {
return a.trim();
}).filter(a => {
return !!a && a.length < 100;
});
if (words.length === 0) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin contiene un grupo vacío.");
}
groups.push({
group: group,
words: words,
});
}
if (groups.length === 0) {
return this.errorReply("Error: La lista de palabras no puede estar vacía");
}
for (let id in Object.keys(mod.data)) {
delete mod.data[id];
}
for (let g of groups) {
mod.data[g.group] = g.words;
}
mod.db.write();
this.addToSecurityLog();
this.reply("Las palabras del juego Hangman han sido modificadas correctamente.");
}.bind(this));
},
// Anagrams
getanagramsdata: function () {
if (!this.can(PERMISSION_REQUIRED, this.room)) return this.replyAccessDenied(PERMISSION_REQUIRED);
const data = App.modules.games.system.templates.wordgames.data;
let text = "";
for (let group of Object.keys(data)) {
text += group + "||" + (data[group] || []).join(", ") + "\n";
}
let key = App.data.temp.createTempFile(
"<html>" +
"<body><p>" +
Text.escapeHTML(text).replace(/\n/g, "<br>") +
"</p></body>" +
"</html>"
);
this.reply("Palabras para el juego Anagrams: " + App.server.getControlPanelLink('/temp/' + key));
},
setanagramsdata: function () {
if (!this.can(PERMISSION_REQUIRED, this.room)) return this.replyAccessDenied(PERMISSION_REQUIRED);
if (this.args.length !== 1 || !this.args[0]) {
return this.errorReply(this.usage({ desc: "Link a Pastebin - Tendrá un grupo de palabras en cada línea, con formato: Pista del Grupo || Palabra, Palabra..." }));
}
let mod = App.modules.games.system.templates.wordgames;
let link = (this.args[0] + "").trim();
let linkRegex = /^https:\/\/pastebin\.com\/([A-Za-z0-9]+)/;
let linkRes = linkRegex.exec(link);
if (!linkRes) {
return this.errorReply("El enlace a Pastebin no es correcto.");
}
wget("https://pastebin.com/raw/" + linkRes[1] + "", function (data, err) {
if (err) {
return this.errorReply("No se pudo obtener el Pastebin desde el enlace. Error: " + err.message);
}
let groups = [];
let lines = data.split("\n");
if (lines.length > 5000) {
return this.errorReply("Error: No se admiten más de 5000 grupos.");
}
let lineCount = 0;
for (let line of lines) {
line = line.trim();
lineCount++;
if (!line) {
continue;
}
let spl = line.split("||");
if (spl.length !== 2) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin no tiene el formato correcto.");
}
const group = spl[0].trim();
if (!group || group.length > 200) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin contiene un grupo válido.");
}
const words = spl[1].split(",").map(a => {
return a.trim();
}).filter(a => {
return !!a && a.length < 100;
});
if (words.length === 0) {
return this.errorReply("Error: La línea " + lineCount + " del Pastebin contiene un grupo vacío.");
}
groups.push({
group: group,
words: words,
});
}
if (groups.length === 0) {
return this.errorReply("Error: La lista de palabras no puede estar vacía");
}
for (let id in Object.keys(mod.data)) {
delete mod.data[id];
}
for (let g of groups) {
mod.data[g.group] = g.words;
}
mod.db.write();
this.addToSecurityLog();
this.reply("Las palabras del juego Anagrams han sido modificadas correctamente.");
}.bind(this));
},
// End
},
});
};