Skip to content

Conversation

officiallyutso
Copy link
Member

@officiallyutso officiallyutso commented Jul 27, 2025

What's Added

  • Weekly leaderboard showing all active users ranked by message count

  • Announcement of the top poster every Saturday at 9 PM

  • Formatted output with Markdown for better readability in chat

  • This builds on the existing cron job by adding visibility into weekly message activity.

Testing

# Temporary test command
  robot.respond /test weekly/i, (msg) ->
    sorted = listOfUsersWithCount()

    if sorted.length > 0
      name = sorted[0][0]
      currMsgRecord = sorted[0][1]
      response = "This week's top poster is @#{name} with #{currMsgRecord} messages\n\n"
      response += "**Weekly Message Stats:**\n```"

      for user, i in sorted
        username = user[0]
        count = user[1]
        rank = i + 1
        response += "\n#{rank}. #{username} : #{count} messages"

      response += "\n```"

      msg.send response
    else
      msg.send "No messages this week!"

  # Temporary command to simulate multiple users
  robot.respond /create test users/i, (msg) ->
    # Manually add users to brain data
    robot.brain.data.users ?= {}
    
    testUsers = {
      "nawab": {id: "nawab", name: "Nawab", msgcount: 15, words: {}},
      "orange": {id: "orange", name: "Orange", msgcount: 8, words: {}},
      "ryuga": {id: "ryuga", name: "Ryuga", msgcount: 12, words: {}},
      "ronin": {id: "ronin", name: "Ronin", msgcount: 3, words: {}}
    }
    
    for userId, userData of testUsers
      robot.brain.data.users[userId] = userData
    
    msg.send "Created test users: Nawab(15), Orange(8), Ryuga(12), Ronin(3)"
  • Add this after the updated cron job.

If Issue

  1. downgrade your npm version accordingly using nvm.
  2. if 'bin/hubot' is not working try changing the following:
"scripts": {
    "start": "nodemon -e coffee --exec './bin/hubot -n $HUBOT_NAME -a slack'"
  },

to

"scripts": {
    "test": "hubot",
    "start": "nodemon -e coffee --exec './bin/hubot -n $HUBOT_NAME -a slack'"
  },

then run npm run test

  1. If you face issue with npm i, remove "libxmljs": "^0.19.10",

  2. after creating test users and messaging, input, hubot test weekly to see stats

Example Output:

Hubot> hubot test weekly
Hubot> This week's top poster is @Nawab with 15 messages

Weekly Message Stats:
1. Nawab : 15 messages
2. Ryuga : 12 messages
3. Shell : 9 messages
4. Orange : 8 messages
5. Ronin : 3 messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant