Redo channel logs

This commit is contained in:
calzoneman 2014-02-08 12:45:07 -06:00
parent 87b40b679a
commit 3bebc34e21
9 changed files with 140 additions and 152 deletions

View File

@ -63,7 +63,6 @@ function Channel(name) {
exceedmaxlength: 2, // Add a video longer than the maximum length set
addnontemp: 2, // Add a permanent video to the playlist
settemp: 2, // Toggle temporary status of a playlist item
playlistgeturl: 1.5, // TODO is this even used?
playlistshuffle: 2, // Shuffle the playlist
playlistclear: 2, // Clear the playlist
pollctl: 1.5, // Open/close polls
@ -224,7 +223,7 @@ Channel.prototype.loadState = function () {
}
try {
self.logger.log("*** Loading channel state");
self.logger.log("[init] Loading channel state from disk");
data = JSON.parse(data);
// Load the playlist
@ -305,6 +304,8 @@ Channel.prototype.saveState = function () {
return;
}
self.logger.log("[init] Saving channel state to disk");
var filters = self.filters.map(function (f) {
return f.pack();
});
@ -562,7 +563,7 @@ Channel.prototype.join = function (user) {
self.sendMotd([user]);
self.sendDrinkCount([user]);
self.logger.log("+++ " + user.ip + " joined");
self.logger.log("[login] " + user.ip + " joined");
Logger.syslog.log(user.ip + " joined channel " + self.name);
};
@ -620,7 +621,7 @@ Channel.prototype.part = function (user) {
self.sendUserLeave(self.users, user);
}
self.logger.log("--- " + user.ip + " (" + user.name + ") left");
self.logger.log("[login] " + user.ip + " (" + user.name + ") left");
if (self.users.length === 0) {
self.emit("empty");
return;
@ -733,7 +734,7 @@ Channel.prototype.handleNameBan = function (actor, name, reason) {
break;
}
}
self.logger.log("*** " + actor.name + " namebanned " + name);
self.logger.log("[mod] " + actor.name + " namebanned " + name);
self.sendModMessage(actor.name + " banned " + name, self.permissions.ban);
db.channels.isNameBanned(self.name, name, function (err, banned) {
@ -799,7 +800,7 @@ Channel.prototype.sendUnban = function (users, data) {
u.socket.emit("banlistRemove", data);
}
});
self.logger.log("*** " + data.actor + " unbanned " + data.name);
self.logger.log("[mod] " + data.actor + " unbanned " + data.name);
self.sendModMessage(data.actor + " unbanned " + data.name, self.permissions.ban);
};
@ -882,7 +883,7 @@ Channel.prototype.banIP = function (actor, ip, name, reason, range) {
return;
}
self.logger.log("*** " + actor.name + " banned " + ip + " (" + name + ")");
self.logger.log("[mod] " + actor.name + " banned " + ip + " (" + name + ")");
self.sendModMessage(actor.name + " banned " + ip + " (" + name + ")", self.permissions.ban);
// If in the channel already, kick the banned user
for (var i = 0; i < self.users.length; i++) {
@ -1602,7 +1603,8 @@ Channel.prototype.addMedia = function (data, callback) {
return;
}
self.logger.log("### " + data.queueby + " queued " + media.title);
self.logger.log("[playlist] " + data.queueby + " queued " + media.title + " (" +
media.type + ":" + media.id + ")");
var item = res.item;
var packet = {
@ -1772,6 +1774,7 @@ Channel.prototype.handleQueuePlaylist = function (user, data) {
for (var i = 0; i < pl.length; i++) {
pl[i].pos = pos;
pl[i].temp = temp;
pl[i].queueby = user.name;
self.addMedia(pl[i], function (err, media) {
if (err) {
user.socket.emit("queueFail", {
@ -1811,7 +1814,7 @@ Channel.prototype.handleDelete = function (user, data) {
self.deleteMedia(data, function (err) {
if (!err && plitem && plitem.media) {
self.logger.log("### " + user.name + " deleted " + plitem.media.title);
self.logger.log("[playlist] " + user.name + " deleted " + plitem.media.title);
}
});
};
@ -1929,7 +1932,7 @@ Channel.prototype.handleMove = function (user, data) {
var afterit = self.playlist.items.find(data.after);
var aftertitle = (afterit && afterit.media) ? afterit.media.title : "";
if (fromit) {
self.logger.log("### " + user.name + " moved " + fromit.media.title +
self.logger.log("[playlist] " + user.name + " moved " + fromit.media.title +
(aftertitle ? " after " + aftertitle : ""));
}
}
@ -1962,7 +1965,7 @@ Channel.prototype.handleUncache = function (user, data) {
return;
}
self.logger.log("*** " + user.name + " deleted " + data.id + " from library");
self.logger.log("[library] " + user.name + " deleted " + data.id + " from library");
});
};
@ -1974,7 +1977,11 @@ Channel.prototype.handlePlayNext = function (user) {
return;
}
this.logger.log("### " + user.name + " skipped the video");
var title = "";
if (this.playlist.current && this.playlist.current.title) {
title = " " + this.playlist.current.title;
}
this.logger.log("[playlist] " + user.name + " skipped" + title);
this.playlist.next();
};
@ -1990,7 +1997,12 @@ Channel.prototype.handleJumpTo = function (user, data) {
return;
}
this.logger.log("### " + user.name + " skipped the video");
var to = this.playlist.items.find(data);
var title = "";
if (to != null) {
title = " to " + to.media.title;
}
this.logger.log("[playlist] " + user.name + " skipped" + title);
this.playlist.jump(data);
};
@ -2012,7 +2024,7 @@ Channel.prototype.handleClear = function (user) {
return;
}
this.logger.log("### " + user.name + " cleared the playlist");
this.logger.log("[playlist] " + user.name + " cleared the playlist");
this.clear();
};
@ -2045,7 +2057,7 @@ Channel.prototype.handleShuffle = function (user) {
return;
}
this.logger.log("### " + user.name + " shuffle the playlist");
this.logger.log("[playlist] " + user.name + " shuffle the playlist");
this.shuffle();
};
@ -2102,7 +2114,7 @@ Channel.prototype.handleOpenPoll = function (user, data) {
var poll = new Poll(user.name, title, opts, obscured);
this.poll = poll;
this.sendPoll(this.users, true);
this.logger.log("*** " + user.name + " Opened Poll: '" + poll.title + "'");
this.logger.log("[poll] " + user.name + " Opened Poll: '" + poll.title + "'");
};
/**
@ -2119,7 +2131,7 @@ Channel.prototype.handleClosePoll = function (user) {
this.sendPollUpdate(this.users);
}
this.logger.log("*** " + user.name + " closed the active poll");
this.logger.log("[poll] " + user.name + " closed the active poll");
this.poll = false;
this.sendAll("closePoll");
}
@ -2161,7 +2173,14 @@ Channel.prototype.handleVoteskip = function (user) {
this.voteskip = new Poll("voteskip", "voteskip", ["yes"]);
}
this.voteskip.vote(user.ip, 0);
this.logger.log("### " + (user.name ? user.name : "anonymous") + " voteskipped");
var title = "";
if (this.playlist.current && this.playlist.current.title) {
title = " " + this.playlist.current.title;
}
this.logger.log("[playlist] " + (user.name ? user.name : "anonymous") +
" voteskipped" + title);
this.checkVoteskipPass();
};
@ -2184,7 +2203,12 @@ Channel.prototype.checkVoteskipPass = function () {
var max = this.calcVoteskipMax();
var need = Math.ceil(max * this.opts.voteskip_ratio);
if (this.voteskip.counts[0] >= need) {
this.logger.log("### Voteskip passed, skipping to next video");
var title = "";
if (this.playlist.current && this.playlist.current.title) {
title = " " + this.playlist.current.title;
}
this.logger.log("[playlist] Voteskip passed, skipping" + title);
this.playlist.next();
}
@ -2210,7 +2234,7 @@ Channel.prototype.handleSetLock = function (user, data) {
data.locked = Boolean(data.locked);
this.logger.log("*** " + user.name + " set playlist lock to " + data.locked);
this.logger.log("[playlist] " + user.name + " set playlist lock to " + data.locked);
this.setLock(data.locked);
};
@ -2320,7 +2344,9 @@ Channel.prototype.handleUpdateFilter = function (user, f) {
return;
}
this.logger.log("%%% " + user.name + " updated filter: " + f.name);
this.logger.log("[mod] " + user.name + " updated filter: " + f.name + " -> " +
"s/" + f.source + "/" + f.replace + "/" + f.flags + " active: " +
f.active);
this.updateFilter(filter);
};
@ -2356,7 +2382,7 @@ Channel.prototype.handleRemoveFilter = function (user, f) {
return;
}
this.logger.log("%%% " + user.name + " removed filter: " + f.name);
this.logger.log("[mod] " + user.name + " removed filter: " + f.name);
this.removeFilter(f);
};
@ -2408,7 +2434,7 @@ Channel.prototype.handleSetPermissions = function (user, perms) {
}
}
this.logger.log("%%% " + user.name + " updated permissions");
this.logger.log("[mod] " + user.name + " updated permissions");
this.sendAll("setPermissions", this.permissions);
};
@ -2520,7 +2546,7 @@ Channel.prototype.handleUpdateOptions = function (user, data) {
this.opts.password = pw;
}
this.logger.log("%%% " + user.name + " updated channel options");
this.logger.log("[mod] " + user.name + " updated channel options");
this.sendOpts(this.users);
};
@ -2541,7 +2567,7 @@ Channel.prototype.handleSetCSS = function (user, data) {
this.css = css;
this.sendCSSJS(this.users);
this.logger.log("%%% " + user.name + " updated the channel CSS");
this.logger.log("[mod] " + user.name + " updated the channel CSS");
};
/**
@ -2561,7 +2587,7 @@ Channel.prototype.handleSetJS = function (user, data) {
this.js = js;
this.sendCSSJS(this.users);
this.logger.log("%%% " + user.name + " updated the channel JS");
this.logger.log("[mod] " + user.name + " updated the channel JS");
};
/**
@ -2592,7 +2618,7 @@ Channel.prototype.handleSetMotd = function (user, data) {
var motd = data.motd.substring(0, 20000);
this.setMotd(motd);
this.logger.log("%%% " + user.name + " updated the MOTD");
this.logger.log("[mod] " + user.name + " updated the MOTD");
};
/**
@ -2785,7 +2811,7 @@ Channel.prototype.handleSetRank = function (user, data) {
return;
}
self.logger.log("*** " + user.name + " set " + name + "'s rank to " + rank);
self.logger.log("[mod] " + user.name + " set " + name + "'s rank to " + rank);
self.sendAll("setUserRank", {
name: name,
rank: rank
@ -2826,7 +2852,7 @@ Channel.prototype.changeLeader = function (name) {
if (!name) {
this.sendAll("setLeader", "");
this.logger.log("*** Resuming autolead");
this.logger.log("[playlist] Resuming autolead");
this.playlist.lead(true);
return;
}
@ -2834,7 +2860,7 @@ Channel.prototype.changeLeader = function (name) {
for (var i = 0; i < this.users.length; i++) {
if (this.users[i].name === name) {
this.sendAll("setLeader", name);
this.logger.log("*** Assigned leader: " + name);
this.logger.log("[playlist] Assigned leader: " + name);
this.playlist.lead(false);
this.leader = this.users[i];
if (this.users[i].rank < 1.5) {
@ -2865,7 +2891,7 @@ Channel.prototype.handleChangeLeader = function (user, data) {
}
this.changeLeader(data.name);
this.logger.log("### " + user.name + " assigned leader to " + data.name);
this.logger.log("[mod] " + user.name + " assigned leader to " + data.name);
};
/**

View File

@ -201,7 +201,7 @@ function handleShadowMute(chan, user, args) {
person.meta.smuted = person.meta.muted = true;
chan.sendUserMeta(chan.users, person, 2);
chan.mutedUsers.add("[shadow]" + person.name.toLowerCase());
chan.logger.log("*** " + user.name + " shadow muted " + args[0]);
chan.logger.log("[mod] " + user.name + " shadow muted " + args[0]);
chan.sendModMessage(user.name + " shadow muted " + args[0], 2);
}
}
@ -228,7 +228,7 @@ function handleMute(chan, user, args) {
person.meta.muted = true;
chan.sendUserMeta(chan.users, person);
chan.mutedUsers.add(person.name.toLowerCase());
chan.logger.log("*** " + user.name + " muted " + args[0]);
chan.logger.log("[mod] " + user.name + " muted " + args[0]);
chan.sendModMessage(user.name + " muted " + args[0], 2);
}
}
@ -258,7 +258,7 @@ function handleUnmute(chan, user, args) {
chan.sendUserMeta(chan.users, person, wasSmuted ? 2 : false);
chan.mutedUsers.remove(person.name.toLowerCase());
chan.mutedUsers.remove("[shadow]" + person.name.toLowerCase());
chan.logger.log("*** " + user.name + " unmuted " + args[0]);
chan.logger.log("[mod] " + user.name + " unmuted " + args[0]);
chan.sendModMessage(user.name + " unmuted " + args[0], 2);
}
}
@ -287,7 +287,7 @@ function handleKick(chan, user, args) {
}
}
if (kickee) {
chan.logger.log("*** " + user.name + " kicked " + args[0]);
chan.logger.log("[mod] " + user.name + " kicked " + args[0]);
args[0] = "";
var reason = args.join(" ");
kickee.kick(reason);
@ -319,7 +319,7 @@ function handleBan(chan, user, args) {
function handleUnban(chan, user, args) {
if (chan.hasPermission(user, "ban") && args.length > 0) {
chan.logger.log("*** " + user.name + " unbanned " + args[0]);
chan.logger.log("[mod] " + user.name + " unbanned " + args[0]);
if (args[0].match(/(\d+)\.(\d+)\.(\d+)\.(\d+)/)) {
chan.unbanIP(user, args[0]);
}
@ -337,7 +337,7 @@ function handlePoll(chan, user, msg, hidden) {
var poll = new Poll(user.name, title, args, hidden === true);
chan.poll = poll;
chan.sendPoll(chan.users);
chan.logger.log("*** " + user.name + " Opened Poll: '" + poll.title + "'");
chan.logger.log("[poll] " + user.name + " Opened Poll: '" + poll.title + "'");
}
}

View File

@ -293,7 +293,7 @@ module.exports = {
chan.name = res[0].name;
chan.canonical_name = chan.name.toLowerCase();
chan.registered = true;
chan.logger.log("*** Loaded channel from database");
chan.logger.log("[init] Loaded channel from database");
callback(null, true);
});
},

View File

@ -75,6 +75,8 @@ function Playlist(chan) {
chan.resetVideo();
chan.sendAll("setCurrent", pl.current.uid);
chan.sendAll("changeMedia", m.fullupdate());
chan.logger.log("[playlist] Now playing: " + m.title + " (" + m.type + ":" + m.id +
")");
});
this.on("remove", function(item) {
if (chan.dead) {

View File

@ -138,30 +138,9 @@ mixin chanlog
#cs-chanlog.tab-pane
h4 Channel Log
strong Filter Log:
form(role="form", action="javscript:void(0)")
.checkbox
label Everything
input#filter_all(type="checkbox", checked="checked")
.checkbox
label Chat
input#filter_chat(type="checkbox")
.checkbox
label Polls
input#filter_polls(type="checkbox")
.checkbox
label Playlist actions
input#filter_queue(type="checkbox")
.checkbox
label Bans
input#filter_bans(type="checkbox")
.checkbox
label Channel settings
input#filter_channelsettings(type="checkbox")
.checkbox
label Join/Quit messages
input#filter_joinquit(type="checkbox")
pre#chanlog_contents(style="max-height: 400px; overflow-y: scroll")
button.btn.btn-default#chanlog_refresh Refresh
select#cs-chanlog-filter.form-control(multiple="multiple")
pre#cs-chanlog-text
button.btn.btn-default#cs-chanlog-refresh Refresh
mixin permeditor
#cs-permedit.tab-pane

View File

@ -364,18 +364,16 @@ Callbacks = {
},
readChanLog: function (data) {
var log = $("#chanlog_contents");
if(log.length == 0)
var log = $("#cs-chanlog-text");
if (log.length == 0)
return;
if(data.success) {
log.data("log", data.data);
log.text(data.data);
if (data.success) {
setupChanlogFilter(data.data);
filterChannelLog();
} else {
log.text("Error reading channel log");
$("#cs-chanlog-text").text("Error reading channel log");
}
log.scrollTop(log.prop("scrollHeight"));
},
voteskip: function(data) {

View File

@ -530,18 +530,11 @@ $(".cs-textbox").keyup(function () {
}, 1000);
});
$("#chanlog_refresh").click(function () {
$("#cs-chanlog-refresh").click(function () {
socket.emit("readChanLog");
});
$("#cs-chanlog input[type='checkbox']").change(function () {
var id = $(this).attr("id");
if (id !== "filter_all" && $(this).prop("checked")) {
$("#filter_all").prop("checked", false);
}
filterChannelLog();
});
$("#cs-chanlog-filter").change(filterChannelLog);
$("#cs-motdsubmit").click(function () {
socket.emit("setMotd", {

View File

@ -1755,87 +1755,63 @@ function queueMessage(data, type) {
.appendTo($("#queuefail"));
}
function setupChanlogFilter(data) {
var getKey = function (ln) {
var left = ln.indexOf("[", 1);
var right = ln.indexOf("]", left);
if (left === -1 || right === -1) {
return "unknown";
}
return ln.substring(left+1, right);
};
data = data.split("\n").filter(function (ln) {
return ln.indexOf("[") === 0 && ln.indexOf("]") > 0;
});
var log = $("#cs-chanlog-text");
var select = $("#cs-chanlog-filter");
select.html("");
log.data("lines", data);
var keys = {};
data.forEach(function (ln) {
keys[getKey(ln)] = true;
});
Object.keys(keys).forEach(function (key) {
$("<option/>").attr("value", key).text(key).appendTo(select);
});
}
function filterChannelLog() {
var cc = $("#chanlog_contents");
if (!cc.data("log")) {
cc.data("log", cc.text());
}
var all = $("#filter_all").prop("checked");
var chat = $("#filter_chat").prop("checked");
var polls = $("#filter_polls").prop("checked");
var queue = $("#filter_queue").prop("checked");
var bans = $("#filter_bans").prop("checked");
var channelsettings = $("#filter_channelsettings").prop("checked");
var joinquit = $("#filter_joinquit").prop("checked");
var log = $("#cs-chanlog-text");
var filter = $("#cs-chanlog-filter").val();
var getKey = function (ln) {
var left = ln.indexOf("[", 1);
var right = ln.indexOf("]", left);
return ln.substring(left+1, right);
};
var lines = cc.data("log").split("\n");
var include = [];
lines.forEach(function (line) {
if (line.trim() === "") {
return;
}
if (all) {
include.push(line);
return;
}
var getTimestamp = function (ln) {
var right = ln.indexOf("]");
return ln.substring(1, right);
};
var pre = line.split(" ")[5];
if (pre === undefined) {
return;
}
var getMessage = function (ln) {
var right = ln.indexOf("]");
return ln.substring(right + 2);
};
if (chat && pre.match(/<[\w-]+(\.\w*)?>/)) {
include.push(line);
return;
}
if (polls && pre === "***" && (line.indexOf("Opened Poll") >= 0 ||
line.indexOf("closed the active poll") >= 0)) {
include.push(line);
return;
}
if (queue && pre === "###") {
include.push(line);
return;
}
if (channelsettings && pre === "%%%") {
include.push(line);
return;
}
if (joinquit) {
if (pre === "+++" || pre === "---") {
include.push(line);
return;
}
if (pre.match(/(\d{1,3}\.){3}\d{1,3}/) &&
line.indexOf("logged in as") >= 0) {
include.push(line);
return;
}
}
if (bans && pre === "***" && line.indexOf("banned") >= 0) {
include.push(line);
return;
}
if (channelsettings && pre === "***") {
if (line.indexOf("Loading") >= 0 ||
line.indexOf("Loaded") >= 0 ||
line.indexOf("unloading") >= 0 ||
line.indexOf("rank") >= 0) {
include.push(line);
return;
}
return;
var show = [];
(log.data("lines")||[]).forEach(function (ln) {
if (!filter || filter.indexOf(getKey(ln)) >= 0) {
show.push(ln);
}
});
$("#chanlog_contents").text(include.join("\n"));
log.text(show.join("\n"));
log.scrollTop(log.prop("scrollHeight"));
}
function makeModal() {

View File

@ -469,3 +469,17 @@ li.ui-sortable-helper, li.ui-sortable-placeholder + li.queue_entry {
.pagination {
margin: 0;
}
#cs-chanlog-filter {
border-bottom: 0;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
#cs-chanlog-text {
max-height: 300px;
overflow-y: scroll;
font-size: 8pt;
border-top-left-radius: 0;
border-top-right-radius: 0;
}