Per-Channel Emotes Implemented.
This commit is contained in:
parent
163cecf9f0
commit
c3d016e1af
14 changed files with 483 additions and 20 deletions
|
|
@ -15,6 +15,7 @@ class commandPreprocessor{
|
|||
defineListeners(){
|
||||
//When we receive site-wide emote list
|
||||
this.client.socket.on("siteEmotes", this.setSiteEmotes.bind(this));
|
||||
this.client.socket.on("chanEmotes", this.setChanEmotes.bind(this));
|
||||
}
|
||||
|
||||
preprocess(command){
|
||||
|
|
@ -53,23 +54,30 @@ 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);
|
||||
});
|
||||
//inject invisible whitespace in-between emotes to prevent from mushing links together
|
||||
this.message = this.message.replaceAll('][',']ㅤ[');
|
||||
|
||||
//For each list of emotes
|
||||
Object.keys(this.emotes).forEach((key) => {
|
||||
//For each emote in the current list
|
||||
this.emotes[key].forEach((emote) => {
|
||||
//Inject emote links into the message
|
||||
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('␜','');
|
||||
//Split message by links
|
||||
var splitMessage = this.message.split(/(https?:\/\/[^\s]+)/g);
|
||||
var splitMessage = this.message.split(/(https?:\/\/[^\sㅤ]+)/g);
|
||||
//Create an empty array to hold links
|
||||
this.links = [];
|
||||
|
||||
splitMessage.forEach((chunk, chunkIndex) => {
|
||||
if(chunk.match(/(https?:\/\/[^\s]+)/g)){
|
||||
//For each chunk that is a link
|
||||
if(chunk.match(/(https?:\/\/[^\sㅤ]+)/g)){
|
||||
//I looked online for obscure characters that no one would use to prevent people from chatting embed placeholders
|
||||
//Then I found this fucker, turns out it's literally made for the job lmao (even if it was originally intended for paper/magnetic tape)
|
||||
//Replace link with indexed placeholder
|
||||
|
|
@ -92,6 +100,10 @@ class commandPreprocessor{
|
|||
this.emotes.site = data;
|
||||
}
|
||||
|
||||
setChanEmotes(data){
|
||||
this.emotes.chan = data;
|
||||
}
|
||||
|
||||
getEmoteByLink(link){
|
||||
//Create an empty variable to hold the found emote
|
||||
var foundEmote = null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue