Code style cleanup on user.js

This commit is contained in:
calzoneman 2013-09-26 13:29:36 -05:00
parent 379522f2df
commit 6e18e25139
2 changed files with 166 additions and 164 deletions

View file

@ -1,3 +1,6 @@
Thu Sep 26 13:29 2013 CDT
* lib/user.js: Some code style cleanup
Thu Sep 26 13:17 2013 CDT
* lib/user.js: A few minor cleanups to login functions
* lib/api.js: Pass the login failure reason to the action log

View file

@ -42,7 +42,7 @@ var User = function(socket, Server) {
this.autoAFK();
this.initCallbacks();
if(Server.announcement != null) {
if (Server.announcement !== null) {
this.socket.emit("announcement", Server.announcement);
}
};
@ -57,15 +57,13 @@ User.prototype.noflood = function(name, hz) {
if (!(name in this.throttle)) {
this.throttle[name] = [time];
return false;
}
else if(name in this.flooded && time < this.flooded[name]) {
} else if (name in this.flooded && time < this.flooded[name]) {
this.socket.emit("noflood", {
action: name,
msg: "You're still on cooldown!"
});
return true;
}
else {
} else {
this.throttle[name].push(time);
var diff = (time - this.throttle[name][0]) / 1000.0;
// Twice might be an accident, more than that is probably spam
@ -83,7 +81,7 @@ User.prototype.noflood = function(name, hz) {
return false;
}
}
}
};
User.prototype.setAFK = function (afk) {
if (!this.inChannel())
@ -103,19 +101,20 @@ User.prototype.setAFK = function (afk) {
name: this.name,
afk: afk
});
}
};
User.prototype.autoAFK = function () {
if(this.awaytimer)
clearTimeout(this.awaytimer);
var self = this;
if (self.awaytimer)
clearTimeout(self.awaytimer);
if(!this.inChannel() || this.channel.opts.afk_timeout == 0)
if (!self.inChannel() || self.channel.opts.afk_timeout === 0)
return;
this.awaytimer = setTimeout(function () {
this.setAFK(true);
}.bind(this), this.channel.opts.afk_timeout * 1000);
}
self.awaytimer = setTimeout(function () {
self.setAFK(true);
}, self.channel.opts.afk_timeout * 1000);
};
User.prototype.initCallbacks = function () {
var self = this;
@ -227,7 +226,7 @@ User.prototype.initCallbacks = function() {
self.socket.on("chatMsg", function (data) {
if (self.inChannel()) {
if(data.msg.indexOf("/afk") != 0) {
if (data.msg.indexOf("/afk") !== 0) {
self.setAFK(false);
self.autoAFK();
}
@ -322,7 +321,7 @@ User.prototype.initCallbacks = function() {
self.socket.on("searchMedia", function (data) {
if (self.inChannel()) {
if (data.source == "yt") {
var searchfn = self.server.infogetter.Getters["ytSearch"];
var searchfn = self.server.infogetter.Getters.ytSearch;
searchfn(data.query.split(" "), function (e, vids) {
if (!e) {
self.socket.emit("searchResults", {
@ -360,8 +359,7 @@ User.prototype.initCallbacks = function() {
success: false,
error: "You're not in any channel!"
});
}
else {
} else {
self.channel.tryRegister(self);
}
});
@ -454,7 +452,7 @@ User.prototype.initCallbacks = function() {
});
self.socket.on("listPlaylists", function (data) {
if(self.name == "" || self.rank < 1) {
if (self.name === "" || self.rank < 1) {
self.socket.emit("listPlaylists", {
pllist: [],
error: "You must be logged in to manage playlists"
@ -469,7 +467,7 @@ User.prototype.initCallbacks = function() {
list[i].time = $util.formatTime(list[i].time);
}
self.socket.emit("listPlaylists", {
pllist: list,
pllist: list
});
});
});
@ -518,7 +516,7 @@ User.prototype.initCallbacks = function() {
list[i].time = $util.formatTime(list[i].time);
}
self.socket.emit("listPlaylists", {
pllist: list,
pllist: list
});
});
});
@ -545,7 +543,7 @@ User.prototype.initCallbacks = function() {
list[i].time = $util.formatTime(list[i].time);
}
self.socket.emit("listPlaylists", {
pllist: list,
pllist: list
});
});
});
@ -574,7 +572,7 @@ User.prototype.initCallbacks = function() {
self.channel.broadcastUserUpdate(self);
});
}
};
var lastguestlogin = {};
User.prototype.guestLogin = function (name) {
@ -587,7 +585,7 @@ User.prototype.guestLogin = function (name) {
success: false,
error: "Guest logins are restricted to one per IP address "+
"per " + self.server.cfg["guest-login-delay"] +
" seconds.",
" seconds."
});
return false;
}
@ -650,12 +648,13 @@ User.prototype.guestLogin = function (name) {
self.channel.broadcastNewUser(self);
}
});
}
};
// Attempt to login
User.prototype.login = function (name, pw, session) {
var self = this;
// No password => try guest login
if(pw == "" && session == "") {
if (pw === "" && session === "") {
this.guestLogin(name);
} else {
self.loggingIn = true;
@ -729,6 +728,6 @@ User.prototype.login = function(name, pw, session) {
}
});
}
}
};
module.exports = User;