commandPreprocessor.js now scrapes links out of chat message before sending to server.
This commit is contained in:
parent
805387b3da
commit
4474cc4b6d
|
|
@ -9,20 +9,22 @@ class commandPreprocessor{
|
|||
this.command = command;
|
||||
this.sendFlag = true;
|
||||
|
||||
this.splitBody();
|
||||
this.processLocalCommand();
|
||||
|
||||
if(this.sendFlag){
|
||||
this.message = command;
|
||||
this.processLinks();
|
||||
this.sendRemoteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
splitBody(){
|
||||
processLocalCommand(){
|
||||
//Create an empty array to hold the command
|
||||
this.commandArray = [];
|
||||
//Split string by words
|
||||
this.commandArray = this.command.split(/\b/g);//Split by word-borders
|
||||
this.argumentArray = this.command.match(/\b\w+\b/g);//Match by words surrounded by borders
|
||||
}
|
||||
|
||||
processLocalCommand(){
|
||||
//If this is a local command
|
||||
if(this.commandArray[0] == '/'){
|
||||
//If the command exists
|
||||
|
|
@ -36,10 +38,30 @@ class commandPreprocessor{
|
|||
}
|
||||
}
|
||||
|
||||
sendRemoteCommand(){
|
||||
if(this.sendFlag){
|
||||
this.client.socket.emit("chatMessage",{msg: this.commandArray.join("")});
|
||||
processLinks(){
|
||||
//Split message by links
|
||||
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)){
|
||||
//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
|
||||
splitMessage[chunkIndex] = `␜${this.links.length}␜`
|
||||
|
||||
//push current chunk as link
|
||||
this.links.push(chunk);
|
||||
}
|
||||
});
|
||||
|
||||
//Join the message back together
|
||||
this.message = splitMessage.join('');
|
||||
}
|
||||
|
||||
sendRemoteCommand(){
|
||||
this.client.socket.emit("chatMessage",{msg: this.message, links: this.links});
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue