mirror of https://github.com/calzoneman/sync.git
Fix PM maxlength and throttling
This commit is contained in:
parent
2aba640ec5
commit
e2c3b2daad
|
@ -22,6 +22,12 @@ const TYPE_PM = {
|
||||||
meta: "object,optional"
|
meta: "object,optional"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const DEFAULT_ANTIFLOOD = {
|
||||||
|
burst: 4,
|
||||||
|
sustained: 1,
|
||||||
|
cooldown: 4
|
||||||
|
};
|
||||||
|
|
||||||
function ChatModule(channel) {
|
function ChatModule(channel) {
|
||||||
ChannelModule.apply(this, arguments);
|
ChannelModule.apply(this, arguments);
|
||||||
this.buffer = [];
|
this.buffer = [];
|
||||||
|
@ -192,7 +198,13 @@ ChatModule.prototype.handlePm = function (user, data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var msg = data.msg.substring(0, 240);
|
if (user.chatLimiter.throttle(DEFAULT_ANTIFLOOD)) {
|
||||||
|
user.socket.emit("cooldown", 1000 / DEFAULT_ANTIFLOOD.sustained);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
data.msg = data.msg.substring(0, 240);
|
||||||
var to = null;
|
var to = null;
|
||||||
for (var i = 0; i < this.channel.users.length; i++) {
|
for (var i = 0; i < this.channel.users.length; i++) {
|
||||||
if (this.channel.users[i].getLowerName() === data.to) {
|
if (this.channel.users[i].getLowerName() === data.to) {
|
||||||
|
@ -216,7 +228,7 @@ ChatModule.prototype.handlePm = function (user, data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.indexOf(">") === 0) {
|
if (data.msg.indexOf(">") === 0) {
|
||||||
meta.addClass = "greentext";
|
meta.addClass = "greentext";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,15 +255,16 @@ ChatModule.prototype.processChatMsg = function (user, data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var msgobj = this.formatMessage(user.getName(), data);
|
var msgobj = this.formatMessage(user.getName(), data);
|
||||||
|
var antiflood = DEFAULT_ANTIFLOOD;
|
||||||
if (this.channel.modules.options &&
|
if (this.channel.modules.options &&
|
||||||
this.channel.modules.options.get("chat_antiflood") &&
|
this.channel.modules.options.get("chat_antiflood")) {
|
||||||
user.account.effectiveRank < 2) {
|
|
||||||
|
|
||||||
var antiflood = this.channel.modules.options.get("chat_antiflood_params");
|
antiflood = this.channel.modules.options.get("chat_antiflood_params");
|
||||||
if (user.chatLimiter.throttle(antiflood)) {
|
}
|
||||||
user.socket.emit("cooldown", 1000 / antiflood.sustained);
|
|
||||||
return;
|
if (user.chatLimiter.throttle(antiflood)) {
|
||||||
}
|
user.socket.emit("cooldown", 1000 / antiflood.sustained);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.is(Flags.U_SMUTED)) {
|
if (user.is(Flags.U_SMUTED)) {
|
||||||
|
|
|
@ -124,6 +124,7 @@ Callbacks = {
|
||||||
cooldown: function (time) {
|
cooldown: function (time) {
|
||||||
time = time + 200;
|
time = time + 200;
|
||||||
$("#chatline").css("color", "#ff0000");
|
$("#chatline").css("color", "#ff0000");
|
||||||
|
$(".pm-input").css("color", "#ff0000");
|
||||||
if (CHATTHROTTLE && $("#chatline").data("throttle_timer")) {
|
if (CHATTHROTTLE && $("#chatline").data("throttle_timer")) {
|
||||||
clearTimeout($("#chatline").data("throttle_timer"));
|
clearTimeout($("#chatline").data("throttle_timer"));
|
||||||
}
|
}
|
||||||
|
@ -131,6 +132,7 @@ Callbacks = {
|
||||||
$("#chatline").data("throttle_timer", setTimeout(function () {
|
$("#chatline").data("throttle_timer", setTimeout(function () {
|
||||||
CHATTHROTTLE = false;
|
CHATTHROTTLE = false;
|
||||||
$("#chatline").css("color", "");
|
$("#chatline").css("color", "");
|
||||||
|
$(".pm-input").css("color", "");
|
||||||
}, time));
|
}, time));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -2586,10 +2586,14 @@ function initPm(user) {
|
||||||
var buffer = $("<div/>").addClass("pm-buffer linewrap").appendTo(body);
|
var buffer = $("<div/>").addClass("pm-buffer linewrap").appendTo(body);
|
||||||
$("<hr/>").appendTo(body);
|
$("<hr/>").appendTo(body);
|
||||||
var input = $("<input/>").addClass("form-control pm-input").attr("type", "text")
|
var input = $("<input/>").addClass("form-control pm-input").attr("type", "text")
|
||||||
|
.attr("maxlength", 240)
|
||||||
.appendTo(body);
|
.appendTo(body);
|
||||||
|
|
||||||
input.keydown(function (ev) {
|
input.keydown(function (ev) {
|
||||||
if (ev.keyCode === 13) {
|
if (ev.keyCode === 13) {
|
||||||
|
if (CHATTHROTTLE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var meta = {};
|
var meta = {};
|
||||||
var msg = input.val();
|
var msg = input.val();
|
||||||
if (msg.trim() === "") {
|
if (msg.trim() === "") {
|
||||||
|
|
Loading…
Reference in New Issue