Implement emotes
This commit is contained in:
parent
53138fe1f0
commit
002888a0de
8 changed files with 185 additions and 15 deletions
|
|
@ -75,6 +75,8 @@ function Channel(name) {
|
|||
motdedit: 3, // Edit the MOTD
|
||||
filteredit: 3, // Control chat filters
|
||||
filterimport: 3, // Import chat filter list
|
||||
emoteedit: 3, // Control emotes
|
||||
emoteimport: 3, // Import emote list
|
||||
playlistlock: 2, // Lock/unlock the playlist
|
||||
leaderctl: 2, // Give/take leader
|
||||
drink: 1.5, // Use the /d command
|
||||
|
|
@ -270,8 +272,6 @@ Channel.prototype.loadState = function () {
|
|||
data.emotes.forEach(function (e) {
|
||||
self.emotes.push(e);
|
||||
});
|
||||
|
||||
self.updateEmote({ name: ":test:", source: ":test:", image: "http://imgs.xkcd.com/comics/mobile_marketing.png" });
|
||||
}
|
||||
|
||||
// MOTD
|
||||
|
|
@ -2496,17 +2496,18 @@ Channel.prototype.handleImportEmotes = function (user, data) {
|
|||
* Validates data for an emote
|
||||
*/
|
||||
Channel.prototype.validateEmote = function (f) {
|
||||
if (typeof f.source !== "string" || typeof f.image !== "string") {
|
||||
if (typeof f.name !== "string" || typeof f.image !== "string") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof f.name !== "string") {
|
||||
f.name = f.source;
|
||||
}
|
||||
|
||||
f.image = f.image.substring(0, 1000);
|
||||
f.image = XSS.sanitizeText(f.image);
|
||||
|
||||
var s = f.name.replace(/\\\.\?\+\*\$\^\(\)\[\]\{\}/g, "\\$1");
|
||||
s = s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||
s = "(^|\\b)" + s + "($|\\b)";
|
||||
f.source = s;
|
||||
|
||||
try {
|
||||
new RegExp(f.regex, "gi");
|
||||
} catch (e) {
|
||||
|
|
@ -2522,8 +2523,9 @@ Channel.prototype.validateEmote = function (f) {
|
|||
Channel.prototype.updateEmote = function (emote) {
|
||||
var self = this;
|
||||
|
||||
if (!emote.name) {
|
||||
emote.name = emote.source;
|
||||
emote = this.validateEmote(emote);
|
||||
if (!emote) {
|
||||
return;
|
||||
}
|
||||
|
||||
var found = false;
|
||||
|
|
@ -2573,7 +2575,7 @@ Channel.prototype.removeEmote = function (emote) {
|
|||
if (self.emotes[i].name === emote.name) {
|
||||
self.emotes.splice(i, 1);
|
||||
self.users.forEach(function (u) {
|
||||
u.socket.emit("deleteEmote", emote);
|
||||
u.socket.emit("removeEmote", emote);
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
|
@ -2594,7 +2596,7 @@ Channel.prototype.handleRemoveEmote = function (user, f) {
|
|||
}
|
||||
|
||||
this.logger.log("[mod] " + user.name + " removed emote: " + f.name);
|
||||
this.removeFilter(f);
|
||||
this.removeEmote(f);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
12
lib/user.js
12
lib/user.js
|
|
@ -397,6 +397,18 @@ User.prototype.initChannelCallbacks = function () {
|
|||
self.channel.handleMoveFilter(self, data);
|
||||
});
|
||||
|
||||
wrapTypecheck("updateEmote", function (data) {
|
||||
self.channel.handleUpdateEmote(self, data);
|
||||
});
|
||||
|
||||
wrap("importEmotes", function (data) {
|
||||
self.channel.handleImportEmotes(self, data);
|
||||
});
|
||||
|
||||
wrapTypecheck("removeEmote", function (data) {
|
||||
self.channel.handleRemoveEmote(self, data);
|
||||
});
|
||||
|
||||
wrap("requestBanlist", function () {
|
||||
self.channel.sendBanlist([self]);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue