-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathhpoke-exceptions.js
More file actions
68 lines (59 loc) · 1.97 KB
/
hpoke-exceptions.js
File metadata and controls
68 lines (59 loc) · 1.97 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
// Exceptions for .hpoke command
// Install as an add-on for Showdown-ChatBot
// Will add a control panel section named 'HashPoke'
'use strict';
const Text = Tools('text');
exports.setup = function (App) {
return Tools('add-on').forApp(App).install({
serverMenuOptions: {
"customhpoke": {name : "HashPoke", url: "/customhpoke/", permission: "pokemon", level: -2},
},
serverHandlers: {
"customhpoke": function (context, parts) {
if (!context.user || !context.user.can('pokemon')) {
context.endWith403();
return;
}
if (!App.config.addons) App.config.addons = {};
if (!App.config.addons.hpoke) App.config.addons.hpoke = {};
let config = App.config.addons.hpoke;
let ok = null;
if (context.post.save) {
for (let id in config) {
delete config[id];
}
let newData = (context.post.data || "").split('\n');
for (let line of newData) {
let spl = line.split(',');
if (spl.length !== 2) continue;
let id = Text.toId(spl[0]);
let poke = Text.trim(spl.slice(1).join(","));
config[id] = poke;
}
App.saveConfig();
App.logServerAction(context.user.id, "Changed hpoke exceptions.");
ok = "Hashpoke exceptions saved successfully.";
}
let exceptions = [];
for (let id in config) {
exceptions.push(id + ", " + config[id]);
}
let html = '';
html += '<h2>Exceptions for hpoke command</h2>';
html += '<p>Format: <b>Name, Custom Pokemon</b></p>';
html += '<form method="post" action="">';
html += '<textarea name="data" style="width: 100%; max-width: 100ch;" rows="30">';
html += exceptions.join('\n');
html += '</textarea>';
html += '<p><input type="submit" name="save" value="Save Changes" /></p>';
html += '</form>';
html += '<p>';
if (ok) {
html += '<span class="ok-msg">' + ok + '</span>';
}
html += '</p>';
context.endWithWebPage(html, {title: "Exceptions for hpoke command - Showdown ChatBot"});
},
},
});
};