-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommands.js
More file actions
257 lines (250 loc) · 12.2 KB
/
Copy pathcommands.js
File metadata and controls
257 lines (250 loc) · 12.2 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
'use strict';
// use return false to show that the command didnt go through to prevent triggering false monitor moderations
exports.commands = {
say: function(target, room, user) {
if (!this.can("say")) return false;
return this.send(removeCommand(target));
},
//settings
addchar: function(target, room, user) {
if (!this.can("set") || !room) return false;
if (target.length !== 1 || toId(target) || target === " ") return this.send("The command character has to be 1 character long, and cannot be an alphanumeric character.");
if(room.commandCharacter.includes(target)) return this.send("This is already a command character in this room.");
room.addCommandCharacter(target);
this.send(target + " has been added to this room's command characters.");
},
setchar: function(target, room, user) {
if (!this.can("set") || !room) return false;
if (target.length !== 1 || toId(target) || target === " ") return this.send("The command character has to be 1 character long, and cannot be an alphanumeric character.");
room.commandCharacter = [];
room.addCommandCharacter(target);
this.send(target + " is set as this room's command character.");
},
deletechar: function(target, room, user) {
if (!this.can("set") || !room) return false;
if (target.length !== 1 || toId(target) || target === " ") return this.send("The command character has to be 1 character long, and cannot be an alphanumeric character.");
if (room.commandCharacter.length === 1) return this.send("You need at least one command character in every room!");
if (!room.commandCharacter.includes(target)) return this.send("That is not one of the room's command characters!");
room.removeCommandCharacter(target);
this.send(target + " has been removed from this room's command characters.");
},
setprivate: function(target, room, user) {
if (!this.can("set") || !room) return false;
switch (toId(target)) {
case "on":
Db("settings").set([room.id, "isPrivate"], true);
room.isPrivate = true;
break;
case "off":
Db("settings").set([room.id, "isPrivate"], false);
room.isPrivate = false;
break;
default:
return this.send("This room is currently marked as " + (Db("settings").get([room.id, "isPrivate"], false) ? "private." : "public."));
}
return this.send("This room is currently marked as " + (Db("settings").get([room.id, "isPrivate"], false) ? "private." : "public."));
},
set: function(target, room, user) {
if (!this.can("set") && !this.can("addcom")) return false;
if (!target) return this.parse("/help set");
let parts = target.replace(/\, /g, ",").split(",");
if (parts[0] === "mod") {
if (!this.can("set") || !room) return false; // roomowner only
if (!parts[1] || !parts[2]) return this.parse("/help set mod");
parts[2] = parts[2].trim().replace(/^reg$/i, " ");
if (!Config.modSettings[toId(parts[1])] || (!["on", "off"].includes(parts[2].toLowerCase()) && !(parts[2] in Config.ranks))) return this.parse("/help set mod");
let modAspect = toId(parts[1]);
let modSetting = parts[2].toLowerCase();
Db("settings").set([room.id, "moderation", modAspect], modSetting);
return this.send("Moderation for " + modAspect + " will be applied to users of rank \"" + modSetting + "\" and below.");
}
let targetCommand = toId(parts[0]);
let mainCommand;
if(Commands[targetCommand] && !Config.settableCommands[targetCommand] && typeof Commands[targetCommand] === "string"){
mainCommand = Commands[targetCommand];
}
if (Config.settableCommands[mainCommand || targetCommand]) {
if (!this.can("set") || !room) return false; // roomowner only
if(mainCommand) targetCommand = mainCommand;
if (!parts[1]) return this.parse("/help set");
let targetSetting = parts[1].toLowerCase();
if (!Config.ranks[targetSetting] && !["on", "off"].includes(targetSetting)) return this.parse("/help set");
Db("settings").set([room.id, targetCommand], targetSetting);
return this.send(room.commandCharacter[0] + targetCommand + " is now " + (toId(targetSetting) ? targetSetting.toUpperCase() : "usable by users " + targetSetting + " and above") + ".");
}
let roomCCon = Db("customcommands").get([room ? room.id : "global", targetCommand], null);
if (roomCCon) {
let customComSetting = parts[1].toLowerCase();
if (!Config.ranks[customComSetting]) return this.parse("/help set");
roomCCon.rank = customComSetting;
Db("customcommands").set([room ? room.id : "global", targetCommand], roomCCon);
return this.send("Custom command " + (room ? room.commandCharacter[0] : Config.defaultCharacter[0]) + targetCommand + " is now usable by users " + customComSetting + " and above.");
}
this.send(room.commandCharacter[0] + targetCommand + " is neither a custom command nor a regular command on the bot that can be set.")
},
bw: "banword",
regexbanword: "banword",
banword: function(target, room, user, cmd) {
if (cmd === "regexbanword" ? (!this.can("set") && user.hasBotRank("+")) : !this.can("banword") || !room) return false;
if (!target) return this.parse("/help " + (cmd === "bw" ? "banword" : cmd));
target = target.split(",");
let points = 3;
let regexBanword = target.slice(0, target.length - 1).join(",");
if (isNaN(parseInt(target[target.length - 1]))) {
regexBanword = target.join(",");
}
else if (parseInt(target[target.length - 1]) >= 1) {
points = parseInt(target[target.length - 1]);
}
if (cmd !== "regexbanword") {
regexBanword = Tools.regexify(regexBanword.trim());
} else {
// test for evil regex
if (/(?!\\)\(.*?(?:[^\\])[\*\+\?][^\)]*?(?!\\)\)([\*\+]|\{[0-9]+(\,|\,?[0-9]*?)\})/i.test(regexBanword)) return this.send("Sorry, I cannot accept that as a regexbanword as your banned phrase may contain some [[evil regex]]...");
// test if it's actually working regex
try {
let test = new RegExp(regexBanword);
} catch (e) {
return this.errorReply(e.message.substr(0, 28) === 'Invalid regular expression: ' ? e.message : 'Invalid regular expression: /' + regexBanword + '/: ' + e.message);
}
}
if (!regexBanword) return this.parse("/help " + (cmd === "bw" ? "banword" : cmd));
let banwordExists = Db("settings").get([room.id, "bannedWords", regexBanword], null);
if (banwordExists) return this.send("That already exists as a banned phrase in this room.");
Db("settings").set([room.id, "bannedWords", regexBanword], points);
this.send("The phrase /" + regexBanword + "/i is banned with a point value of " + points + ".");
},
unbanword: function(target, room, user) {
if (!this.can("banword") || !room) return false;
if (!target) return this.parse("/help unbanword");
target = target.trim();
let banwordExists = Db("settings").get([room.id, "bannedWords", target], null);
if (!banwordExists) {
target = Tools.regexify(target);
banwordExists = Db("settings").get([room.id, "bannedWords", target], null);
if (!banwordExists) {
return this.send("That's not a banned word in this room!");
}
}
delete Db("settings").object()[room.id].bannedWords[target];
Db.save();
this.send("//" + target + "/i has been removed from this room's list of banned words");
},
ab: "autoban",
autoban: function(target, room, user, cmd) {
if (!this.can("autoban") || !room) return false;
if (!target) return this.parse("/help autoban");
target = toId(target);
if (target.length > 18 || target.length < 1) return this.send("This is not a legal PS username.");
if (room.userIsBlacklisted(target)) return this.send("This user is already blacklisted.");
room.blacklistUser(target);
this.send("/roomban " + target + ", Blacklisted user.");
this.send("/modnote \"" + target + "\" was added to the blacklist by " + user.name + ".");
this.send(target + " was successfully added to the blacklist.");
},
unab: "unautoban",
unautoban: function(target, room, user) {
if (!this.can("autoban") || !room) return false;
if (!target) return this.parse("/help unautoban");
target = toId(target);
if (target.length > 18 || target.length < 1) return this.send("That is not a legal PS username.");
if (!room.userIsBlacklisted(target)) return this.send("This user is not blacklisted.");
room.unblacklistUser(target);
this.send("/roomunban " + target);
this.send("/modnote \"" + target + "\" was removed from the blacklist by " + user.name + ".");
this.send(target + " was successfully removed from the blacklist.");
},
settings: function(target, room, user) {
if (!room && !target) return user.sendTo("Please specify the room.");
let targetRoom = room;
if (target) {
if (Rooms.rooms.has(toId(target, true))) {
targetRoom = Rooms.get(target);
}
else {
if (!room || this.can("settings")) {
return user.sendTo("The bot is not in the room you specified.");
}
return false;
}
}
if (!user.can("settings", targetRoom)) {
//not leaking private rooms
if (targetRoom.isPrivate) return user.sendTo("The bot is not in the room you specified.");
return false;
}
//get list of banned words
let roomSettings = Db("settings").get(targetRoom.id);
let nonCommandValues = ["rch", "moderation", "isPrivate", "bannedWords", "roomBlacklist"];
let buildBannedWords = () => {
let buffer = "+----------------------------------+\n" +
"| BannedWords |\n" +
"+----------------------------------+\n";
if (roomSettings.bannedWords && Object.keys(roomSettings.bannedWords).length) {
buffer += Object.keys(roomSettings.bannedWords).map(w => "| (" + roomSettings.bannedWords[w] + ") " + w + " ".slice(w.length + roomSettings.bannedWords[w].toString().length) + "|").join("\n") + "\n";
}
else {
buffer += "| None! |\n";
}
buffer += "+----------------------------------+\n\n";
return buffer;
};
let buildBlacklist = () => {
let buffer = "+----------------------+\n" +
"| Blacklisted Users |\n" +
"+----------------------+\n";
if (targetRoom.blacklist && Object.keys(targetRoom.blacklist).length) {
buffer += Object.keys(targetRoom.blacklist).sort().map(w => "| - " + w + " ".slice(w.length) + "|").join("\n") + "\n";
}
else if (!targetRoom.blacklist || Object.keys(targetRoom.blacklist).length === 0) {
buffer += "| None! |\n";
}
buffer += "+----------------------+\n\n";
return buffer;
};
let getModerationSettings = () => {
let modBuffer = "Moderation Settings: \n" +
"+-------------------+-----+\n" +
"| Moderation Aspect | |\n" +
"+-------------------+-----+\n";
modBuffer += Object.keys(Config.modSettings).map(aspect => {
let tSetting = roomSettings.moderation && roomSettings.moderation[aspect] ? roomSettings.moderation[aspect].toUpperCase() : "+";
return "| " + aspect + " ".slice(aspect.length) + "| " + tSetting + " ".slice(tSetting.length) + "|\n";
}).join("+ - - - - - - - - - + - - +\n");
modBuffer += "+-------------------+-----+\n";
modBuffer += "*NOTE: the bot will moderate users of that rank and lower for each aspect.\n\n";
return modBuffer;
};
let getCommandSettings = () => {
let comBuffer = "Command Settings: \n" +
"+------------------+-----+\n" +
"| Command | |\n" +
"+------------------+-----+\n";
let collectCommands = [];
for (let aspect in roomSettings) {
if (nonCommandValues.includes(aspect)) continue;
let tSetting = roomSettings && roomSettings[aspect] ? roomSettings[aspect].toUpperCase() : Config.defaultRank;
collectCommands.push("|" + aspect + " ".slice(aspect.length) + "| " + tSetting + " ".slice(tSetting.length) + "|\n");
}
comBuffer += collectCommands.join("+ - - - - - - - - -+ - - +\n") +
"+------------------+-----+\n" +
"*NOTE: Most commands that have not been set require rank " + Config.defaultRank + " to use/broadcast.\n\n";
return comBuffer;
};
let settingsDisplay = "" +
"Room name: " + targetRoom.name + "\n" +
"Room ID: " + targetRoom.id + "\n" +
"Private Room: " + targetRoom.isPrivate + "\n" +
"Command characters for this room: " + targetRoom.commandCharacter.join(", ") + "\n\n";
if (roomSettings) {
settingsDisplay += getModerationSettings() +
buildBannedWords() +
buildBlacklist() +
getCommandSettings();
}
Tools.uploadToHastebin("Settings: \n=========\n\n" + settingsDisplay, link => {
user.sendTo("Settings for " + targetRoom.name + ": " + link);
});
},
};
/*globals Config Db Rooms Tools removeCommand toId Commands*/