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

@ -47,11 +47,9 @@ module.exports = class{
//We can take this data raw since our schema checks it against existing flairs, and mongoose sanatizes queries //We can take this data raw since our schema checks it against existing flairs, and mongoose sanatizes queries
const flairDB = await userDB.setFlair(data.flair); const flairDB = await userDB.setFlair(data.flair);
//GetConnects across all channels //Crawl through users active connections
const connections = this.server.getConnections(socket.user.user); this.server.crawlConnections(socket.user.user, (conn)=>{
//Update flair
//For each connection
connections.forEach((conn) => {
conn.updateFlair(flairDB.name); conn.updateFlair(flairDB.name);
}); });
}catch(err){ }catch(err){

View file

@ -41,6 +41,7 @@ module.exports = class{
await this.sendSiteEmotes(); await this.sendSiteEmotes();
await this.sendChanEmotes(chanDB); await this.sendChanEmotes(chanDB);
await this.sendPersonalEmotes(userDB); await this.sendPersonalEmotes(userDB);
await this.sendUsedTokes(userDB);
//Tattoo hashed IP address to user account for seven days //Tattoo hashed IP address to user account for seven days
await userDB.tattooIPRecord(socket.handshake.address); await userDB.tattooIPRecord(socket.handshake.address);
@ -126,9 +127,9 @@ module.exports = class{
} }
async sendPersonalEmotes(userDB){ async sendPersonalEmotes(userDB){
//if we wherent handed a channel document //if we wherent handed a user document
if(userDB == null){ if(userDB == null){
//Pull it based on channel name //Pull it based on user name
userDB = await userModel.findOne({user: this.user}); userDB = await userModel.findOne({user: this.user});
} }
@ -139,6 +140,19 @@ module.exports = class{
this.emit('personalEmotes', emoteList); this.emit('personalEmotes', emoteList);
} }
async sendUsedTokes(userDB){
//if we wherent handed a user document
if(userDB == null){
//Pull it based on user name
userDB = await userModel.findOne({user: this.user});
}
//Create array of used toks from toke map and send it out to the user
this.emit('usedTokes',{
tokes: Array.from(userDB.tokes.keys())
});
}
updateFlair(flair){ updateFlair(flair){
this.flair = flair; this.flair = flair;

View file

@ -152,6 +152,18 @@ module.exports = class tokebot{
this.tokeCounter--; this.tokeCounter--;
//try again in another second //try again in another second
this.tokeTimer = setTimeout(this.countdown.bind(this), 1000) this.tokeTimer = setTimeout(this.countdown.bind(this), 1000)
}
async asyncFinisher(){
//Grab a copy of the tokers map before it gets cleared out
const tokers = this.tokers;
//we need to wait for this so we don't send used tokes pre-maturely
await userModel.tattooToke(tokers);
} }
cooldown(){ cooldown(){

View file

@ -332,6 +332,13 @@ userSchema.statics.tattooToke = function(tokemap){
//Save the user doc to the database //Save the user doc to the database
await userDB.save(); await userDB.save();
//Would rather do this inside of tokebot but then our boi would have to wait for DB or pass a nasty-looking callback function
//Crawl through active connections
server.channelManager.crawlConnections(userDB.user, (conn)=>{
//Update used toke list
conn.sendUsedTokes(userDB);
});
} }
}); });
} }

View file

@ -167,7 +167,7 @@ class chatBox{
this.chatPrompt.focus(); this.chatPrompt.focus();
//Grab autocompletion match //Grab autocompletion match
const match = this.checkAutocomplete() const match = this.checkAutocomplete();
//If we have a match //If we have a match
if(match.match != ''){ if(match.match != ''){
@ -199,7 +199,7 @@ class chatBox{
//and also directly push it into a shared array :P //and also directly push it into a shared array :P
for(let cmd of dictionary[set].cmds){ for(let cmd of dictionary[set].cmds){
//Append the proper prefix/postfix to the current command //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 definition starts with the current word
if(word == '' ? false : definition.indexOf(word) == 0){ 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("siteEmotes", this.setSiteEmotes.bind(this));
this.client.socket.on("chanEmotes", this.setChanEmotes.bind(this)); this.client.socket.on("chanEmotes", this.setChanEmotes.bind(this));
this.client.socket.on("personalEmotes", this.setPersonalEmotes.bind(this)); this.client.socket.on("personalEmotes", this.setPersonalEmotes.bind(this));
this.client.socket.on("usedTokes", this.setUsedTokes.bind(this));
} }
preprocess(command){ preprocess(command){
@ -124,6 +125,10 @@ class commandPreprocessor{
this.emotes.personal = data; this.emotes.personal = data;
} }
setUsedTokes(data){
this.usedTokes = data.tokes;
}
getEmoteByLink(link){ getEmoteByLink(link){
//Create an empty variable to hold the found emote //Create an empty variable to hold the found emote
var foundEmote = null; var foundEmote = null;
@ -161,15 +166,14 @@ class commandPreprocessor{
} }
buildAutocompleteDictionary(){ buildAutocompleteDictionary(){
//This isn't complete, just a placeholder for now
let dictionary = { let dictionary = {
tokes: { tokes: {
prefix: '!', prefix: '!',
postfix: '', postfix: '',
cmds: [ cmds: this.usedTokes
"toke"
]
}, },
//Make sure to add spaces at the end for commands that take arguments
//Not necissary but definitely nice to have
serverCMD: { serverCMD: {
prefix: '!', prefix: '!',
postfix: '', postfix: '',
@ -188,6 +192,11 @@ class commandPreprocessor{
"high " "high "
] ]
}, },
usernames:{
prefix: '',
postfix: '',
cmds: Array.from(client.userList.colorMap.keys())
},
emotes:{ emotes:{
prefix:'[', prefix:'[',
postfix:']', 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; return dictionary;
} }

View file

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