Added proper toke and username autocompletion.
This commit is contained in:
parent
23a71a5478
commit
acbe0400c4
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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(){
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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){
|
||||
|
|
|
|||
|
|
@ -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,15 +166,14 @@ 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: '',
|
||||
|
|
@ -188,6 +192,11 @@ class commandPreprocessor{
|
|||
"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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue