Finished up with chat prompt autocomplete.

This commit is contained in:
rainbow napkin 2025-01-05 00:05:19 -05:00
parent acbe0400c4
commit 9df7f52e9e
7 changed files with 197 additions and 100 deletions

View file

@ -58,12 +58,15 @@ class channel{
}
handleClientInfo(data){
this.user = {
id: data.user.id,
name: data.user.name,
rank: data.user.rank
}
//Ingest user data
this.user = data.user;
//Re-hydrate permission maps
this.user.permMap.site = new Map(data.user.permMap.site);
this.user.permMap.chan = new Map(data.user.permMap.chan);
//Tell the chatbox to handle client info
//should it have its own event listener instead? Guess it's a stylistic choice :P
this.chatBox.handleClientInfo(data);
}
}

View file

@ -143,7 +143,10 @@ class chatBox{
send(event){
if((!event || !event.key || event.key == "Enter") && this.chatPrompt.value){
this.commandPreprocessor.preprocess(this.chatPrompt.value);
//Clear our prompt and autocomplete nodes
this.chatPrompt.value = "";
this.autocompletePlaceholder.innerHTML = '';
this.autocompleteDisplay.innerHTML = '';
}
}
@ -198,11 +201,12 @@ class chatBox{
//I went with a for loop instead of a filter beacuse I wanted to pull the processed definition with pre/postfix
//and also directly push it into a shared array :P
for(let cmd of dictionary[set].cmds){
//Append the proper prefix/postfix to the current command
const definition = (`${dictionary[set].prefix}${cmd}${dictionary[set].postfix}`);
//if definition starts with the current word
if(word == '' ? false : definition.indexOf(word) == 0){
//Append the proper prefix/postfix to the current command
const definition = (`${dictionary[set].prefix}${cmd[0]}${dictionary[set].postfix}`);
//if definition starts with the current word and the command is enabled
if((word == '' ? false : definition.indexOf(word) == 0) && cmd[1]){
//Add definition to match list
matches.push(definition);
}

View file

@ -170,7 +170,9 @@ class commandPreprocessor{
tokes: {
prefix: '!',
postfix: '',
cmds: this.usedTokes
cmds: [
['toke', true]
].concat(injectPerms(this.usedTokes))
},
//Make sure to add spaces at the end for commands that take arguments
//Not necissary but definitely nice to have
@ -178,50 +180,48 @@ class commandPreprocessor{
prefix: '!',
postfix: '',
cmds: [
"whisper ",
"announce ",
"serverannounce ",
"clear ",
"kick "
["whisper ", true],
["announce ", client.user.permMap.chan.get('announce')],
["serverannounce ", client.user.permMap.site.get('announce')],
["clear ", client.user.permMap.chan.get('clearChat')],
["kick ", client.user.permMap.chan.get('kickUser')],
]
},
localCMD:{
prefix: '/',
postfix: '',
cmds: [
"high "
["high ", true]
]
},
usernames:{
prefix: '',
postfix: '',
cmds: Array.from(client.userList.colorMap.keys())
cmds: injectPerms(Array.from(client.userList.colorMap.keys()))
},
emotes:{
prefix:'[',
postfix:']',
cmds: this.getEmoteNames()
cmds: injectPerms(this.getEmoteNames())
}
};
//Ensure default toke command
//Check if 'toke' is the first registered toke
if(dictionary.tokes.cmds[0] != 'toke'){
//Find the current place of the 'toke' command, if any
const tokeIndex = dictionary.tokes.cmds.indexOf('toke');
//If the default command is present but is out of order
if(tokeIndex != -1){
//Splice it out
dictionary.tokes.cmds.splice(tokeIndex,1);
}
//Throw it into the beggining of the array
dictionary.tokes.cmds.unshift('toke');
}
};
//return our dictionary object
return dictionary;
function injectPerms(cmds, perm = true){
//Create empty array to hold cmds
let cmdSet = [];
//For each cmd
for(let cmd of cmds){
//Add the cmd with its perm to the cmdset
cmdSet.push([cmd, perm]);
}
//return the cmd set
return cmdSet;
}
}
}