mirror of https://github.com/calzoneman/sync.git
Implement time parsing/formatting for channel settings
This commit is contained in:
parent
8305c235eb
commit
74cb1b3efc
|
@ -125,13 +125,12 @@ ChatModule.prototype.restrictNewAccount = function restrictNewAccount(user, data
|
|||
if (user.account.effectiveRank < 2 && this.channel.modules.options) {
|
||||
const firstSeen = user.getFirstSeenTime();
|
||||
const opts = this.channel.modules.options;
|
||||
// TODO: configurable times
|
||||
if (firstSeen > Date.now() - opts.get("new_user_chat_delay")) {
|
||||
if (firstSeen > Date.now() - opts.get("new_user_chat_delay")*1000) {
|
||||
user.socket.emit("spamFiltered", {
|
||||
reason: "NEW_USER_CHAT"
|
||||
});
|
||||
return true;
|
||||
} else if ((firstSeen > Date.now() - opts.get("new_user_chat_link_delay"))
|
||||
} else if ((firstSeen > Date.now() - opts.get("new_user_chat_link_delay")*1000)
|
||||
&& data.msg.match(LINK)) {
|
||||
user.socket.emit("spamFiltered", {
|
||||
reason: "NEW_USER_CHAT_LINK"
|
||||
|
|
|
@ -26,8 +26,8 @@ function OptionsModule(channel) {
|
|||
torbanned: false, // Block connections from Tor exit nodes
|
||||
allow_ascii_control: false,// Allow ASCII control characters (\x00-\x1f)
|
||||
playlist_max_per_user: 0, // Maximum number of playlist items per user
|
||||
new_user_chat_delay: 10 * 60 * 1000, // Minimum account/IP age to chat
|
||||
new_user_chat_link_delay: 60 * 60 * 1000 // Minimum account/IP age to post links
|
||||
new_user_chat_delay: 10 * 60, // Minimum account/IP age to chat
|
||||
new_user_chat_link_delay: 60 * 60 // Minimum account/IP age to post links
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -274,14 +274,14 @@ OptionsModule.prototype.handleSetOptions = function (user, data) {
|
|||
}
|
||||
|
||||
if ("new_user_chat_delay" in data) {
|
||||
var delay = parseInt(data.new_user_chat_delay);
|
||||
var delay = data.new_user_chat_delay;
|
||||
if (!isNaN(delay) && delay >= 0) {
|
||||
this.opts.new_user_chat_delay = delay;
|
||||
}
|
||||
}
|
||||
|
||||
if ("new_user_chat_link_delay" in data) {
|
||||
var delay = parseInt(data.new_user_chat_link_delay);
|
||||
var delay = data.new_user_chat_link_delay;
|
||||
if (!isNaN(delay) && delay >= 0) {
|
||||
this.opts.new_user_chat_link_delay = delay;
|
||||
}
|
||||
|
|
30
www/js/ui.js
30
www/js/ui.js
|
@ -636,6 +636,36 @@ $(".cs-textbox").keyup(function () {
|
|||
}, 1000);
|
||||
});
|
||||
|
||||
$(".cs-textbox-timeinput").keyup(function (event) {
|
||||
var box = $(this);
|
||||
var key = box.attr("id").replace("cs-", "");
|
||||
var value = box.val();
|
||||
var lastkey = Date.now();
|
||||
box.data("lastkey", lastkey);
|
||||
|
||||
setTimeout(function () {
|
||||
if (box.data("lastkey") !== lastkey || box.val() !== value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$("#cs-textbox-timeinput-validation-error-" + key).remove();
|
||||
$(event.target).parent().removeClass("has-error");
|
||||
var data = {};
|
||||
try {
|
||||
data[key] = parseTimeout(value);
|
||||
} catch (error) {
|
||||
var msg = "Invalid timespan value '" + value + "'. Please use the format " +
|
||||
"HH:MM:SS or enter a single number for the number of seconds.";
|
||||
var validationError = $("<p/>").addClass("text-danger").text(msg)
|
||||
.attr("id", "cs-textbox-timeinput-validation-error-" + key);
|
||||
validationError.insertAfter(event.target);
|
||||
$(event.target).parent().addClass("has-error");
|
||||
return;
|
||||
}
|
||||
socket.emit("setOptions", data);
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
$("#cs-chanlog-refresh").click(function () {
|
||||
socket.emit("readChanLog");
|
||||
});
|
||||
|
|
|
@ -759,18 +759,23 @@ function applyOpts() {
|
|||
}
|
||||
}
|
||||
|
||||
function showPollMenu() {
|
||||
function parseTimeout(t) {
|
||||
var m;
|
||||
if (m = t.match(/^(\d+):(\d+)$/)) {
|
||||
return parseInt(m[1], 10) * 60 + parseInt(m[2], 10);
|
||||
} else if (m = t.match(/^(\d+)$/)) {
|
||||
return parseInt(m[1], 10);
|
||||
} else {
|
||||
throw new Error("Invalid timeout value '" + t + "'");
|
||||
}
|
||||
function parseTimeout(t) {
|
||||
var m;
|
||||
if (m = t.match(/^(\d+):(\d+):(\d+)$/)) {
|
||||
// HH:MM:SS
|
||||
return parseInt(m[1], 10) * 3600 + parseInt(m[2], 10) * 60 + parseInt(m[3], 10);
|
||||
} else if (m = t.match(/^(\d+):(\d+)$/)) {
|
||||
// MM:SS
|
||||
return parseInt(m[1], 10) * 60 + parseInt(m[2], 10);
|
||||
} else if (m = t.match(/^(\d+)$/)) {
|
||||
// Seconds
|
||||
return parseInt(m[1], 10);
|
||||
} else {
|
||||
throw new Error("Invalid timeout value '" + t + "'");
|
||||
}
|
||||
}
|
||||
|
||||
function showPollMenu() {
|
||||
$("#pollwrap .poll-menu").remove();
|
||||
var menu = $("<div/>").addClass("well poll-menu")
|
||||
.prependTo($("#pollwrap"));
|
||||
|
@ -930,8 +935,8 @@ function handleModPermissions() {
|
|||
$("#cs-torbanned").prop("checked", CHANNEL.opts.torbanned);
|
||||
$("#cs-allow_ascii_control").prop("checked", CHANNEL.opts.allow_ascii_control);
|
||||
$("#cs-playlist_max_per_user").val(CHANNEL.opts.playlist_max_per_user || 0);
|
||||
$("#cs-new_user_chat_delay").val(CHANNEL.opts.new_user_chat_delay || 0);
|
||||
$("#cs-new_user_chat_link_delay").val(CHANNEL.opts.new_user_chat_link_delay || 0);
|
||||
$("#cs-new_user_chat_delay").val(formatTime(CHANNEL.opts.new_user_chat_delay || 0));
|
||||
$("#cs-new_user_chat_link_delay").val(formatTime(CHANNEL.opts.new_user_chat_link_delay || 0));
|
||||
(function() {
|
||||
if(typeof CHANNEL.opts.maxlength != "number") {
|
||||
$("#cs-maxlength").val("");
|
||||
|
|
Loading…
Reference in New Issue