Compare commits

..

No commits in common. "42ad17072f81641180e8b541e78b7ed3e68c43d1" and "a231c8fc4c8b2848f196235a397e389fe6e63d0e" have entirely different histories.

4 changed files with 48 additions and 42 deletions

View file

@ -152,6 +152,50 @@ statSchema.statics.tattooToke = async function(toke){
await stats.save(); await stats.save();
} }
/**
* Gets toke count from statistics document
* @returns {Number} Number of tokes across the entire site
*/
statSchema.statics.getTokeCount = async function(){
//get stats doc
const stats = await this.getStats();
//return toke count
return stats.tokes.length;
}
/**
* Gets toke counts for each individual callout in a map
* @returns {Map} Map of toke counts for each individual callout registered to the server
*/
statSchema.statics.getTokeCommandCounts = async function(){
//get stats doc
const stats = await this.getStats()
//Create empty map to hold toke command counts
const count = new Map();
//for each toke
stats.tokes.forEach((toke) => {
//For each toke command called in the current toke
toke.toke.forEach((command) => {
//Get the current count for the current command
var curCount = count.get(command);
//if the current count is null
if(curCount == null){
//Set it to one
count.set(command, 1);
}else{
//Set it to ++curCount
count.set(command, curCount + 1);
}
});
});
//return the toke command count
return count;
}
/** /**
* Ingests legacy tokes handed over by the migration model * Ingests legacy tokes handed over by the migration model
* @param {Array} rawLegacyTokes - List of strings containing contents of legacy cytube/fore.st toke logs * @param {Array} rawLegacyTokes - List of strings containing contents of legacy cytube/fore.st toke logs
@ -238,7 +282,7 @@ statSchema.statics.dropLegacyTokes = async function(){
statDB.tokes = tokes; statDB.tokes = tokes;
//Save the stat document //Save the stat document
await statDB.save(); statDB.save();
//Tell of our success //Tell of our success
console.log("Removed migration tokes!"); console.log("Removed migration tokes!");
@ -248,36 +292,4 @@ statSchema.statics.dropLegacyTokes = async function(){
} }
//Methods
/**
* Gets toke counts for each individual callout in a map
* @returns {Map} Map of toke counts for each individual callout registered to the server
*/
statSchema.methods.calculateTokeCommandCounts = async function(){
//Create empty map to hold toke command counts
const count = new Map();
//for each toke
this.tokes.forEach((toke) => {
//For each toke command called in the current toke
toke.toke.forEach((command) => {
//Get the current count for the current command
var curCount = count.get(command);
//if the current count is null
if(curCount == null){
//Set it to one
count.set(command, 1);
}else{
//Set it to ++curCount
count.set(command, curCount + 1);
}
});
});
//return the toke command count
return count;
}
module.exports = mongoose.model("statistics", statSchema); module.exports = mongoose.model("statistics", statSchema);

View file

@ -146,8 +146,6 @@ migrationSchema.statics.ingestLegacyDump = async function(){
//Pass toke logs over to the stat model for further ingestion //Pass toke logs over to the stat model for further ingestion
await statModel.ingestLegacyTokes(tokeLogs); await statModel.ingestLegacyTokes(tokeLogs);
loggerUtils.consoleWarn(`Legacy Server Migration Completed at: ${new Date().toLocaleString()}`);
}catch(err){ }catch(err){
return loggerUtils.localExceptionHandler(err); return loggerUtils.localExceptionHandler(err);
} }

View file

@ -311,16 +311,13 @@ userSchema.statics.findProfile = async function(user, includeEmail = false){
return null; return null;
//If someone's looking for tokebot //If someone's looking for tokebot
}else if(user.user.toLowerCase() == "tokebot"){ }else if(user.user.toLowerCase() == "tokebot"){
//Pull statistics document from the database
const statDB = await statModel.getStats();
//fake a profile hashtable for tokebot //fake a profile hashtable for tokebot
const profile = { const profile = {
id: -420, id: -420,
user: "Tokebot", user: "Tokebot",
date: statDB.firstLaunch, date: (await statModel.getStats()).firstLaunch,
tokes: await statDB.calculateTokeCommandCounts(), tokes: await statModel.getTokeCommandCounts(),
tokeCount: statDB.tokes.length, tokeCount: await statModel.getTokeCount(),
img: "/nonfree/johnny.png", img: "/nonfree/johnny.png",
signature: "!TOKE", signature: "!TOKE",
bio: "!TOKE OR DIE!" bio: "!TOKE OR DIE!"

@ -1 +0,0 @@
Subproject commit 8f3f78be454a156aa7b6a9a811cd656cf4bd80b2