From 54ee7a63a487cce46b423ef51b11629c77c29f82 Mon Sep 17 00:00:00 2001 From: UTSO SARKAR <62977856+officiallyutso@users.noreply.github.com> Date: Sun, 27 Jul 2025 21:14:16 +0530 Subject: [PATCH] feat(stats): announce top poster and show weekly leaderboard to Saturday cron job --- scripts/most-spoken-words.coffee | 35 +++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/scripts/most-spoken-words.coffee b/scripts/most-spoken-words.coffee index 6dab597..7e841b3 100644 --- a/scripts/most-spoken-words.coffee +++ b/scripts/most-spoken-words.coffee @@ -128,13 +128,34 @@ module.exports = (robot) -> #This will run every Saturday at 9 pm cron.schedule '0 0 21 * * Saturday', ()-> sorted = listOfUsersWithCount() - name = sorted[0][0] - currMsgRecord = sorted[0][1] - msg = "This week's top poster is @#{name}" - msg += " with #{currMsgRecord} messages" - robot.send room: 'general', msg - if currMsgRecord >= 50 - robot.emit "plusplus", {username: name} + + if sorted.length > 0 + # Top poster announcement + name = sorted[0][0] + currMsgRecord = sorted[0][1] + msg = "This week's top poster is @#{name} with #{currMsgRecord} messages\n\n" + + # Full leaderboard (only active users) + msg += "**Weekly Message Stats:**\n```" + + for user, i in sorted + username = user[0] + count = user[1] + rank = i + 1 + msg += "\n#{rank}. #{username} : #{count} messages" + + msg += "\n```" + + robot.send room: 'general', msg + + # Optional reward + if currMsgRecord >= 50 + robot.emit "plusplus", {username: name} + + else + robot.send room: 'general', "No messages this week!" + + # Reset counts for own key, user of robot.brain.data.users if user.msgcount>0 user.msgcount = 0