Skip to content

Commit

Permalink
Admin command: /watchlog
Browse files Browse the repository at this point in the history
Channel Owner command: /editrule
  • Loading branch information
IceKirby committed Dec 6, 2015
1 parent 2800e35 commit f51662d
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 3 deletions.
3 changes: 2 additions & 1 deletion scripts.js
Expand Up @@ -125,7 +125,7 @@ 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", Config.dataDir + "idbans.txt", Config.dataDir+"league.json"].forEach(cleanFile);
[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+"watchNamesLog.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", Config.dataDir + "idbans.txt", Config.dataDir+"league.json"].forEach(cleanFile);

var autosmute = sys.getFileContent(Config.dataDir+"secretsmute.txt").split(':::');
var crc32 = require('crc32.js').crc32;
Expand Down Expand Up @@ -2113,6 +2113,7 @@ beforeBattleEnded : function(src, dest, desc, bid) {
if (sys.channelId("Watch")) {
sys.sendHtmlAll("<b><font color = blue>" + srcname + " and " + destname + " finished a battle with result " + (tie ? "tie" : srcname + " winning") + (desc === "forfeit" ? " (forfeit)" : "") + (tier ? " in tier " + tier: "") + (time ? " after " + getTimeString(sys.time() - time) + "." : "." ) + "</font></b>", sys.channelId("Watch"));
sys.sendAll(srcname + "'s IP: " + sys.dbIp(srcname) + " " + destname + "'s IP: " + sys.dbIp(destname), sys.channelId("Watch"));
sys.appendToFile(Config.dataDir+"watchNamesLog.txt", srcname + ":::" + destname + ":::" + (tie ? "tie" : srcname) + ":::" + (desc === "forfeit" ? "Forfeit" : "N/A") + ":::" + (tier ? tier: "N/A") + "::: " + (time ? getTimeString(sys.time() - time) : "N/A") + ":::" + sys.dbIp(srcname) + ":::" + sys.dbIp(destname) + "\n");
}
}
},
Expand Down
66 changes: 64 additions & 2 deletions scripts/admincommands.js
Expand Up @@ -236,7 +236,68 @@ exports.handleCommand = function(src, command, commandData, tar, channel) {
sys.writeToFile(Config.dataDir+"nameWarns.json", JSON.stringify(nameWarns));
return;
}

if (command == "watchlog") {
var log = sys.getFileContent(Config.dataDir+"watchNamesLog.txt");

if (log) {
log = log.split("\n");
if (!commandData) {
commandData = "";
}
var info = commandData.split(":"),
term = info.length > 1 ? info[1] : "",
e, lower = 0, upper = 10;

var range = info[0].split("-");
if (range.length > 1) {
lower = parseInt(range[0], 10);
upper = parseInt(range[1], 10);
} else {
lower = 0;
upper = parseInt(range[0], 10);
}
lower = isNaN(lower) ? 0 : lower;
upper = isNaN(upper) ? 10 : upper;

if (lower <= 0) {
log = log.slice(-(upper+1));
} else {
var len = log.length;
log = log.slice(Math.max(len - upper - 1, 0), len - lower);
}

if (term) {
var exp = new RegExp(term, "gi");
for (e = log.length - 1; e >= 0; e--) {
if (!exp.test(log[e])) {
log.splice(e, 1);
}
}
}
if (log.indexOf("") !== -1) {
log.splice(log.indexOf(""), 1);
}
if (log.length <= 0) {
normalbot.sendMessage(src, "Nothing found for this query!", channel);
} else {
sys.sendMessage(src, "", channel);
sys.sendMessage(src, "Watch Log (last " + (lower > 0 ? lower + "~" : "") + upper + " entries" + (term ? ", only including entries with the term " + term : "") + "):", channel);
for (e in log) {
if (!log[e]) {
continue;
}

var params = log[e].split(":::");
var msg = "Players: {0} and {1} -- Winner: {2} -- Forfeit: {3} -- Tier: {4} -- Time: {5} -- {0}'s IP: {6} -- {1}'s IP: {7}";
normalbot.sendMessage(src, msg.format(params[0], params[1], params[2], params[3], params[4], params[5], params[6], params[7]), channel);
}
sys.sendMessage(src, "", channel);
}
} else {
normalbot.sendMessage(src, "Log file not found!", channel);
}
return;
}

if (command == "cookieban" || command == "cookiemute") {
if (!commandData) {
Expand Down Expand Up @@ -367,5 +428,6 @@ exports.help =
"/indigodeinvite: To deinvite unwanted visitors from staff channel.",
"/cookieban: Bans an online target by cookie.",
"/cookiemute: Puts an online android target on an autosmute list by cookie.",
"/cookieunban/mute: Undos a cookieban/mute. Will take effect when they next log in"
"/cookieunban/mute: Undos a cookieban/mute. Will take effect when they next log in",
"/watchlog: Search the watch log. Accepts /watch 15 (last 15 entries), /watch 10-20 (last 10 to 20) and /watch 10:[Word] (entries that contain that word)."
];
15 changes: 15 additions & 0 deletions scripts/channelcommands.js
Expand Up @@ -422,6 +422,20 @@ exports.handleCommand = function (src, command, commandData, tar, channel) {
}
return;
}
if (command == "editrule") {
commandData = commandData.split(":");
if (commandData.length !== 3) {
channelbot.sendMessage(src, "Use /editrule index:name:description", channel);
return;
}
var returnVal = poChannel.editRule(commandData[0], commandData[1], commandData[2]);
if (returnVal) {
channelbot.sendMessage(src, returnVal, channel);
} else {
channelbot.sendMessage(src, "You edited a rule", channel);
}
return;
}

return "no command";
};
Expand Down Expand Up @@ -479,6 +493,7 @@ exports.help = function(src, channel) {
sys.sendMessage(src, "/deowner: Removes channel owner status from a user.", channel);
sys.sendMessage(src, "/addrule [name]:[description]: Adds a rule to the current channel. Numbers are added automatically and there is a limit of 10 rules.", channel);
sys.sendMessage(src, "/removerule [number]: Remove a rule [number].", channel);
sys.sendMessage(src, "/editrule [number]:[name]:[description]: Edit rule [number].", channel);
}
if (SESSION.global().permaTours.indexOf(channel) > -1) {
sys.sendMessage(src, "*** Channel Tournaments commands ***", channel);
Expand Down
10 changes: 10 additions & 0 deletions scripts/channelfunctions.js
Expand Up @@ -697,6 +697,16 @@ POChannel.prototype.removeRule = function(index) {
}
SESSION.global().channelManager.update(this.id);
};
POChannel.prototype.editRule = function(index, name, description) {
if (!(index-1 in this.rules)) {
return "Not a rule";
}
if (name.length > 200 || description.length > 600) {
return "Name/Description too long. Limit is 200 characters for name and 600 for description";
}
this.rules[index-1] = index + ":::::" + name.replace(/:::::/g, ":") + ":::::" + description.replace(/:::::/g, ":");
SESSION.global().channelManager.update(this.id);
};

POChannel.prototype.getRules = function() {
var output = [];
Expand Down

0 comments on commit f51662d

Please sign in to comment.