mirror of https://github.com/calzoneman/sync.git
Some validation
This commit is contained in:
parent
8434d20826
commit
9cfd97088e
|
@ -20,14 +20,28 @@ EmoteList.prototype = {
|
||||||
this.emotes = Array.prototype.slice.call(emotes);
|
this.emotes = Array.prototype.slice.call(emotes);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
emoteExists: function (emote){
|
||||||
|
if(this.emotes.filter((item)=>{ return item.name === emote.name }).length){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
renameEmote: function (emote) {
|
renameEmote: function (emote) {
|
||||||
|
var found = false;
|
||||||
for (var i = 0; i < this.emotes.length; i++) {
|
for (var i = 0; i < this.emotes.length; i++) {
|
||||||
if (this.emotes[i].name === emote.old) {
|
if (this.emotes[i].name === emote.old) {
|
||||||
|
found = true;
|
||||||
this.emotes[i] = emote;
|
this.emotes[i] = emote;
|
||||||
delete this.emotes[i].old;
|
delete this.emotes[i].old;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(found){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
updateEmote: function (emote) {
|
updateEmote: function (emote) {
|
||||||
|
@ -149,17 +163,29 @@ EmoteModule.prototype.handleRenameEmote = function (user, data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** This shouldn't be able to happen,
|
||||||
|
** but we have idiots that like to send handcrafted frames to fuck with shit
|
||||||
|
*/
|
||||||
|
if (typeof data.old !== "string"){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.channel.modules.permissions.canEditEmotes(user)) {
|
if (!this.channel.modules.permissions.canEditEmotes(user)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var e = this.emotes.emoteExists(data);
|
||||||
var f = validateEmote(data);
|
var f = validateEmote(data);
|
||||||
if (!f) {
|
if (!f || e) {
|
||||||
var message = "Unable to rename emote '" + JSON.stringify(data) + "'. " +
|
var message = "Unable to rename emote '" + JSON.stringify(data) + "'. " +
|
||||||
"Please contact an administrator for assistance.";
|
"Please contact an administrator for assistance.";
|
||||||
if (!data.image || !data.name) {
|
if (!data.image || !data.name) {
|
||||||
message = "Emote names and images must not be blank.";
|
message = "Emote names and images must not be blank.";
|
||||||
}
|
}
|
||||||
|
if (e) {
|
||||||
|
message = "Emote already exists.";
|
||||||
|
}
|
||||||
|
|
||||||
user.socket.emit("errorMsg", {
|
user.socket.emit("errorMsg", {
|
||||||
msg: message,
|
msg: message,
|
||||||
|
@ -168,7 +194,9 @@ EmoteModule.prototype.handleRenameEmote = function (user, data) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emotes.renameEmote(Object.assign({}, f));
|
// See comment above
|
||||||
|
var success = this.emotes.renameEmote(Object.assign({}, f));
|
||||||
|
if(!success){ return; }
|
||||||
|
|
||||||
var chan = this.channel;
|
var chan = this.channel;
|
||||||
chan.broadcastAll("renameEmote", f);
|
chan.broadcastAll("renameEmote", f);
|
||||||
|
|
Loading…
Reference in New Issue