diff --git a/src/app/channel/chatHandler.js b/src/app/channel/chatHandler.js index 1555e70..c9d07ef 100644 --- a/src/app/channel/chatHandler.js +++ b/src/app/channel/chatHandler.js @@ -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 const flairDB = await userDB.setFlair(data.flair); - //GetConnects across all channels - const connections = this.server.getConnections(socket.user.user); - - //For each connection - connections.forEach((conn) => { + //Crawl through users active connections + this.server.crawlConnections(socket.user.user, (conn)=>{ + //Update flair conn.updateFlair(flairDB.name); }); }catch(err){ diff --git a/src/app/channel/connectedUser.js b/src/app/channel/connectedUser.js index c26de02..157cc49 100644 --- a/src/app/channel/connectedUser.js +++ b/src/app/channel/connectedUser.js @@ -41,6 +41,7 @@ module.exports = class{ await this.sendSiteEmotes(); await this.sendChanEmotes(chanDB); await this.sendPersonalEmotes(userDB); + await this.sendUsedTokes(userDB); //Tattoo hashed IP address to user account for seven days await userDB.tattooIPRecord(socket.handshake.address); @@ -126,9 +127,9 @@ module.exports = class{ } async sendPersonalEmotes(userDB){ - //if we wherent handed a channel document + //if we wherent handed a user document if(userDB == null){ - //Pull it based on channel name + //Pull it based on user name userDB = await userModel.findOne({user: this.user}); } @@ -139,6 +140,19 @@ module.exports = class{ 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){ this.flair = flair; diff --git a/src/app/channel/tokebot.js b/src/app/channel/tokebot.js index a7d12f3..90166e1 100644 --- a/src/app/channel/tokebot.js +++ b/src/app/channel/tokebot.js @@ -152,6 +152,18 @@ module.exports = class tokebot{ this.tokeCounter--; //try again in another second 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(){ diff --git a/src/schemas/user/userSchema.js b/src/schemas/user/userSchema.js index 0e3d271..d1cc9e2 100644 --- a/src/schemas/user/userSchema.js +++ b/src/schemas/user/userSchema.js @@ -332,6 +332,13 @@ userSchema.statics.tattooToke = function(tokemap){ //Save the user doc to the database 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); + }); } }); } diff --git a/www/js/channel/chat.js b/www/js/channel/chat.js index 61c51de..7eba314 100644 --- a/www/js/channel/chat.js +++ b/www/js/channel/chat.js @@ -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){ diff --git a/www/js/channel/commandPreprocessor.js b/www/js/channel/commandPreprocessor.js index e5cdd3c..223c28e 100644 --- a/www/js/channel/commandPreprocessor.js +++ b/www/js/channel/commandPreprocessor.js @@ -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; } diff --git a/www/js/utils.js b/www/js/utils.js index e6b8019..b723215 100644 --- a/www/js/utils.js +++ b/www/js/utils.js @@ -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