66 lines
1.8 KiB
JavaScript
66 lines
1.8 KiB
JavaScript
class commandPreprocessor{
|
|
constructor(client){
|
|
this.client = client;
|
|
this.commandProcessor = new commandProcessor(client);
|
|
}
|
|
|
|
preprocess(command){
|
|
//Set command and sendFlag
|
|
this.command = command;
|
|
this.sendFlag = true;
|
|
|
|
this.splitBody();
|
|
this.processLocalCommand();
|
|
this.sendRemoteCommand();
|
|
}
|
|
|
|
splitBody(){
|
|
//Create an empty array to hold the command
|
|
this.commandArray = [];
|
|
//Split string by words
|
|
const splitString = this.command.split(/\b/g); //Group words together
|
|
|
|
//for each word in the splitstring
|
|
splitString.forEach((string) => {
|
|
//Add it to our command array
|
|
this.commandArray.push(string);
|
|
});
|
|
}
|
|
|
|
processLocalCommand(){
|
|
//If this is a local command
|
|
if(this.commandArray[0] == '/'){
|
|
//If the command exists
|
|
if(this.commandProcessor[this.commandArray[1]] != null){
|
|
//Don't send it to the server
|
|
this.sendFlag = false;
|
|
|
|
this.commandProcessor[this.commandArray[1]](this.commandArray);
|
|
}
|
|
}
|
|
}
|
|
|
|
sendRemoteCommand(){
|
|
if(this.sendFlag){
|
|
this.client.socket.emit("chatMessage",{msg: this.commandArray.join("")});
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
class commandProcessor{
|
|
constructor(client){
|
|
this.client = client
|
|
}
|
|
|
|
high(commandArray){
|
|
//If we have an argument
|
|
if(commandArray[3]){
|
|
//Use it to set our high level
|
|
//Technically this is less of a local command than it would be if it where telling the select to do this
|
|
//but TTN used to treat this as a local command so fuck it
|
|
this.client.socket.emit("setHighLevel", {highLevel: commandArray[3]});
|
|
}
|
|
}
|
|
} |