Added proper toke and username autocompletion.
This commit is contained in:
parent
23a71a5478
commit
acbe0400c4
7 changed files with 76 additions and 20 deletions
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue