mirror of https://github.com/calzoneman/sync.git
Add initial blocking of new users in chat
This commit is contained in:
parent
6245dc84da
commit
701d470494
|
@ -131,6 +131,21 @@ ChatModule.prototype.handleChatMsg = function (user, data) {
|
|||
|
||||
// Limit to 240 characters
|
||||
data.msg = data.msg.substring(0, 240);
|
||||
|
||||
const firstSeen = user.getFirstSeenTime();
|
||||
// TODO: configurable times
|
||||
if (firstSeen > Date.now() - 5 * 60 * 1000) {
|
||||
user.socket.emit("spamFiltered", {
|
||||
reason: "NEW_USER_CHAT"
|
||||
});
|
||||
return;
|
||||
} else if ((firstSeen > Date.now() - 24 * 60 * 60 * 1000) && data.msg.match(LINK)) {
|
||||
user.socket.emit("spamFiltered", {
|
||||
reason: "NEW_USER_CHAT_LINK"
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// If channel doesn't permit them, strip ASCII control characters
|
||||
if (!this.channel.modules.options ||
|
||||
!this.channel.modules.options.get("allow_ascii_control")) {
|
||||
|
|
|
@ -52,7 +52,8 @@ function handleAuth(socket, accept) {
|
|||
if (!err) {
|
||||
socket.user = {
|
||||
name: user.name,
|
||||
global_rank: user.global_rank
|
||||
global_rank: user.global_rank,
|
||||
registrationTime: new Date(user.time)
|
||||
};
|
||||
}
|
||||
accept(null, true);
|
||||
|
@ -235,6 +236,7 @@ function handleConnection(sock) {
|
|||
user.setFlag(Flags.U_REGISTERED);
|
||||
user.clearFlag(Flags.U_READY);
|
||||
user.account.name = sock.user.name;
|
||||
user.registrationTime = sock.user.registrationTime;
|
||||
user.refreshAccount(function (err, account) {
|
||||
if (err) {
|
||||
user.clearFlag(Flags.U_REGISTERED);
|
||||
|
|
14
src/user.js
14
src/user.js
|
@ -449,4 +449,18 @@ User.prototype.refreshAccount = function (cb) {
|
|||
});
|
||||
};
|
||||
|
||||
User.prototype.getFirstSeenTime = function getFirstSeenTime() {
|
||||
if (this.registrationTime && this.socket.ipReputation && this.socket.ipReputation.first_seen) {
|
||||
return Math.min(this.registrationTime.getTime(), this.socket.ipReputation.first_seen.getTime());
|
||||
} else if (this.registrationTime) {
|
||||
return this.registrationTime.getTime();
|
||||
} else if (this.socket.ipReputation && this.socket.ipReputation.first_seen) {
|
||||
return this.socket.ipReputation.first_seen.getTime();
|
||||
} else {
|
||||
Logger.errlog.log(`User "${this.getName()}" (IP: ${this.realip}) has neither ` +
|
||||
"an IP reputation nor a registered account.");
|
||||
return Date.now();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = User;
|
||||
|
|
|
@ -88,6 +88,22 @@ Callbacks = {
|
|||
scrollChat();
|
||||
},
|
||||
|
||||
spamFiltered: function(data) {
|
||||
var message = "Spam Filtered.";
|
||||
switch (data.reason) {
|
||||
case "NEW_USER_CHAT":
|
||||
message = "Your account is too new to chat in this channel. " +
|
||||
"Please wait a while and try again.";
|
||||
break;
|
||||
case "NEW_USER_CHAT_LINK":
|
||||
message = "Your account is too new to post links in this channel. " +
|
||||
"Please wait a while and try again.";
|
||||
break;
|
||||
}
|
||||
|
||||
errDialog(message);
|
||||
},
|
||||
|
||||
needPassword: function (wrongpw) {
|
||||
var div = $("<div/>");
|
||||
$("<strong/>").text("Channel Password")
|
||||
|
|
Loading…
Reference in New Issue