Added site-wide emote support.

This commit is contained in:
rainbow napkin 2024-12-20 01:42:48 -05:00
parent 41d0302ded
commit 97717b525c
11 changed files with 122 additions and 22 deletions

View file

@ -2,6 +2,19 @@ class commandPreprocessor{
constructor(client){
this.client = client;
this.commandProcessor = new commandProcessor(client);
this.emotes = {
site: [],
chan: [],
personal: []
}
//define listeners
this.defineListeners();
}
defineListeners(){
//When we receive site-wide emote list
this.client.socket.on("siteEmotes", this.setSiteEmotes.bind(this));
}
preprocess(command){
@ -13,6 +26,7 @@ class commandPreprocessor{
if(this.sendFlag){
this.message = command;
this.processEmotes();
this.processLinks();
this.sendRemoteCommand();
}
@ -38,6 +52,14 @@ class commandPreprocessor{
}
}
processEmotes(){
//Does checking each word for an emote use more or less cycles than running replace against each emote?
//Not sure, but it's sure as fuck easier to write it that way lmao
this.emotes.site.forEach((emote) => {
this.message = this.message.replaceAll(`[${emote.name}]`, emote.link);
});
}
processLinks(){
//Strip out file seperators in-case the user is being a smart-ass
this.message = this.message.replaceAll('␜','');
@ -66,6 +88,25 @@ class commandPreprocessor{
this.client.socket.emit("chatMessage",{msg: this.message, links: this.links});
}
setSiteEmotes(data){
this.emotes.site = data;
}
getEmoteByLink(link){
//Create an empty variable to hold the found emote
var foundEmote = null;
//For every site-wide emote
this.emotes.site.forEach((emote) => {
//if we found a match
if(emote.link == link){
//return the match
foundEmote = emote;
}
});
return foundEmote;
}
}