forked from WISVCH/hubot-plusplus-improved
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add top point giver to the response * Iterate the users object * forgot the toarray bit * Adding new db field to help with functions * Updating sender db queries to only find if total exists * Adding cron * Update the cron * Update cron to configure day of week and cron timing * fixing parse int issue * Updating package.json with updated repos * Move to node 16 * adding x placeholders to node * Add npm * Bump version prep * Bump versions of node around * I'm a derp and forgot the i in a loop * Adding more stats * Finish up the cron setup
- Loading branch information
Showing
10 changed files
with
284 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
db.scores.find({ slackId: { $exists: true }}).forEach((user) => { | ||
let total = 0; | ||
for (const key in user.pointsGiven) { | ||
total += parseInt(user.pointsGiven[key], 10); | ||
} | ||
db.scores.update({ _id: user._id }, { $set: { "totalPointsGiven": total }}); | ||
}); | ||
|
||
var theDate = new Date(ISODate().getTime() - 7 * 24 * 60 * 60000) | ||
db.scoreLog.distinct("from", { date: { $gt: new ISODate().getTime() - 7 * 24 * 60 * 60000) } }).forEach((fromUser) => { | ||
print(fromUser); | ||
//print(to + ", " + value + ": " + db[collection].count({[to]: value})) | ||
}) | ||
|
||
db.scoreLog.aggregate([ | ||
{ | ||
$match: { | ||
date: { $gt: new Date(new Date().setDate(new Date().getDate()-15)).toISOString() } | ||
} | ||
}, | ||
{ | ||
$group: { "_id": "$from", "scoreChange": { "$sum": "$scoreChange" }} | ||
}]); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
const clark = require('clark'); | ||
const moment = require('moment'); | ||
const _ = require('lodash'); | ||
const { CronJob } = require('cron'); | ||
|
||
const helpers = require('./lib/helpers'); | ||
const DatabaseService = require('./lib/services/database'); | ||
|
||
module.exports = (robot) => { | ||
const procVars = helpers.getProcessVariables(process.env); | ||
const databaseService = new DatabaseService({ robot, ...procVars }); | ||
|
||
if (!procVars.notificationsRoom) { | ||
return; | ||
} | ||
|
||
const { monthlyScoreboardCron, monthlyScoreboardDayOfWeek } = procVars; | ||
const job = new CronJob(monthlyScoreboardCron, async () => { | ||
if (isScoreboardDayOfWeek()) { | ||
robot.logger.debug('running the cron job'); | ||
|
||
// Senders | ||
const topSenders = await databaseService.getTopSenderInDuration(10, 30); | ||
let message = []; | ||
if (topSenders.length > 0) { | ||
for (let i = 0, end = topSenders.length - 1, asc = end >= 0; asc ? i <= end : i >= end; asc ? i++ : i--) { | ||
const person = `<@${topSenders[i]._id}>`; | ||
const pointStr = topSenders[i].scoreChange > 1 ? 'points given' : 'point given'; | ||
message.push(`${i + 1}. ${person} (${topSenders[i].scoreChange} ${pointStr})`); | ||
} | ||
} else { | ||
message.push('No scores to keep track of yet!'); | ||
} | ||
|
||
let graphSize = Math.min(topSenders.length, Math.min(10, 20)); | ||
message.splice(0, 0, clark(_.take(_.map(topSenders, 'scoreChange'), graphSize))); | ||
message.splice(0, 0, `:tada: The top 10 ${robot.name} point senders over the last month! :tada:`); | ||
robot.messageRoom(procVars.notificationsRoom, message.join('\n')); | ||
|
||
// Recipients | ||
const topRecipient = await databaseService.getTopReceiverInDuration(10, 30); | ||
message = []; | ||
if (topRecipient.length > 0) { | ||
for (let i = 0, end = topRecipient.length - 1, asc = end >= 0; asc ? i <= end : i >= end; asc ? i++ : i--) { | ||
const person = `<@${topRecipient[i]._id}>`; | ||
const pointStr = topRecipient[i].scoreChange > 1 ? 'points given' : 'point given'; | ||
message.push(`${i + 1}. ${person} (${topRecipient[i].scoreChange} ${pointStr})`); | ||
} | ||
} else { | ||
message.push('No scores to keep track of yet!'); | ||
} | ||
|
||
graphSize = Math.min(topRecipient.length, Math.min(10, 20)); | ||
message.splice(0, 0, clark(_.take(_.map(topRecipient, 'scoreChange'), graphSize))); | ||
message.splice(0, 0, `:tada: The top 10 ${robot.name} point recipients over the last month! :tada:`); | ||
robot.messageRoom(procVars.notificationsRoom, message.join('\n')); | ||
|
||
// Room | ||
const topRoom = await databaseService.getTopRoomInDuration(3, 30); | ||
message = []; | ||
if (topRoom.length > 0) { | ||
for (let i = 0, end = topRoom.length - 1, asc = end >= 0; asc ? i <= end : i >= end; asc ? i++ : i--) { | ||
const person = `<#${topRoom[i]._id}>`; | ||
const pointStr = topRoom[i].scoreChange > 1 ? 'points given' : 'point given'; | ||
message.push(`${i + 1}. ${person} (${topRoom[i].scoreChange} ${pointStr})`); | ||
} | ||
} else { | ||
message.push('No scores to keep track of yet!'); | ||
} | ||
|
||
graphSize = Math.min(topRoom.length, Math.min(10, 20)); | ||
message.splice(0, 0, clark(_.take(_.map(topRoom, 'scoreChange'), graphSize))); | ||
message.splice(0, 0, `:tada: The top 3 rooms that sent ${robot.name} point(s) over the last month! :tada:`); | ||
robot.messageRoom(procVars.notificationsRoom, message.join('\n')); | ||
} | ||
}, null, true, 'America/Chicago'); | ||
job.start(); | ||
|
||
function isScoreboardDayOfWeek() { | ||
robot.logger.debug(`Run the cron but lets check what day it is Moment day: [${moment().day()}], Configured Day of Week: [${monthlyScoreboardDayOfWeek}], isThatDay: [${moment().day() === monthlyScoreboardDayOfWeek}]`); | ||
const isToday = moment().day() === monthlyScoreboardDayOfWeek; | ||
return isToday; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.