Added proper toke and username autocompletion.

This commit is contained in:
rainbow napkin 2025-01-04 11:19:24 -05:00
parent 23a71a5478
commit acbe0400c4
7 changed files with 76 additions and 20 deletions

View file

@ -167,7 +167,7 @@ class chatBox{
this.chatPrompt.focus();
//Grab autocompletion match
const match = this.checkAutocomplete()
const match = this.checkAutocomplete();
//If we have a match
if(match.match != ''){
@ -199,7 +199,7 @@ class chatBox{
//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}`)
const definition = (`${dictionary[set].prefix}${cmd}${dictionary[set].postfix}`);
//if definition starts with the current word
if(word == '' ? false : definition.indexOf(word) == 0){

View file

@ -32,6 +32,7 @@ class commandPreprocessor{
this.client.socket.on("siteEmotes", this.setSiteEmotes.bind(this));
this.client.socket.on("chanEmotes", this.setChanEmotes.bind(this));
this.client.socket.on("personalEmotes", this.setPersonalEmotes.bind(this));
this.client.socket.on("usedTokes", this.setUsedTokes.bind(this));
}
preprocess(command){
@ -124,6 +125,10 @@ class commandPreprocessor{
this.emotes.personal = data;
}
setUsedTokes(data){
this.usedTokes = data.tokes;
}
getEmoteByLink(link){
//Create an empty variable to hold the found emote
var foundEmote = null;
@ -161,33 +166,37 @@ class commandPreprocessor{
}
buildAutocompleteDictionary(){
//This isn't complete, just a placeholder for now
let dictionary = {
tokes: {
prefix: '!',
postfix: '',
cmds: [
"toke"
]
cmds: this.usedTokes
},
//Make sure to add spaces at the end for commands that take arguments
//Not necissary but definitely nice to have
serverCMD: {
prefix: '!',
postfix: '',
cmds: [
"whisper",
"announce",
"serverannounce",
"clear",
"kick"
"whisper ",
"announce ",
"serverannounce ",
"clear ",
"kick "
]
},
localCMD:{
prefix: '/',
postfix: '',
cmds: [
"high"
"high "
]
},
usernames:{
prefix: '',
postfix: '',
cmds: Array.from(client.userList.colorMap.keys())
},
emotes:{
prefix:'[',
postfix:']',
@ -195,6 +204,23 @@ class commandPreprocessor{
}
};
//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;
}

View file

@ -57,7 +57,6 @@ class canopyUXUtils{
//add single items
addContent(content);
}else{
console.log(content);
//Crawl through content array
content.forEach((item)=>{
//add each item