Rep Bot
- 9 Devlogs
- 9 Total hours
A bot that tracks which person has helped the most people in #hardware!
A bot that tracks which person has helped the most people in #hardware!
I fixed a bug that let you thank yourself, fixed the leaderboard going into the negatives, and renamed “rep” to “points” because I felt like “rep” was something that signified trust. Answering more questions does not mean you’re more trustworthy.
Heh. I lied. I don’t know where the time went. But I added a register command so that the first initial “how do I thank people” can be printed. The old bot message is also deleted when a new reminder message needs to be printed.
Alright, this is the last feature before I’m deploying this bot for testing. I’m adding this feature as an explaination for how the bot works and to remind people that the bot exists. This message is only posted when two conditions are met: it has been a day or more since the last message AND 20 more messages have been posted since the last message. I created a database table that tracks the amount of messages that have been sent in a channel since the last message and I have a while loop that queries the db to check every second.
Okay, maybe I lied a little bit. There are a few more updates I want to make. I talked with Evan about adding it to #code and #hardware, and he agreed HURAYYYY YAY YOPRGLK ERL:G JRLSKJ KRLSHG KJWRHGKJ WEJHK SJ:GJK
But he also made a few suggestions which I will be implementing. These changes here, though, are my own ideas. Previously, the format for giving someone thanks/points was very strict. The message has to start with “thanks” or “ty” or “thx” and then has to mention someone and has to be exactly 2 words long (the ping counts as a word). Now, it’s more flexible and the requirements for the bot to notice that the user is trying to give thanks is just to have the word “thanks” or “thank” or “ty” or “thx” and then ping the user. There can be other words in the message now.
I also added a profile picture to the bot (suggestion by Evan). It’s stolen from Lapse’s leaderboard icon
Eyyyy! Whatcha look at that! Editing the leaderboard works now.
so, I had to switch from using respond() to client.chat.update() which makes no sense to me but okay sure whatever it works now. Then, there was an error about duplicate action IDs which I used Gemini to figure out the fix for: Slack wants a unique action to be performed by each button so you need a new event handler. But I don’t want to duplicate code so I hovered over the “app.action” function and noticed that it except RegEx so I used the RegEx “/paginate_(next|prev)/”
I’m so happy it works now though. Time to ship it!
HEY GUESS WHAT THE ISSUE WAS. GUESS WHAT. IT. WAS. FIXED. WITH. A. REBOOT. WHAT
okay, so. Here’s the context, right. The user requests a command to be ran on the bot and the command is sometimes randomly delayed until after the 3 second timeout from Slack is over so Slack thinks the bot didn’t receive it but the bot didn’t even receive the command. I have a video attached.
I thought it was my code’s fault, so I was messing around and adding logging and changing random things and googling and whatnot and nothing fixed it. And then I rebooted my computer. AND IT FIXED IT WHAT DO YOU MEAN???? IF IT WAS AN ISSUE WITH THE NETWORK CODE WHY DIDN’T WEBSITES TAKE SECONDS TO LOAD???? THEY LOADED FINE! WHYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
So, I got the leaderboard working..kind of. The leaderboard works and shows the top 10 people, but the “Next” button to show the next 10 people doesn’t work. Why? Who knows? Slack just complains of something being wrong and doesn’t give many details about what exactly is wrong.
There’s also another issue: sometimes the bot won’t receive a message from Slack that a command was ran until after the timeout period of 3 seconds is over. And I know it’s not the code taking more than 3 seconds to run because the request is immediately ack’d and the entire code block takes less than 250ms on average (I timed it with console.time). So I have no idea what’s going on. That’s why this devlog is 2.5 hours. It took me 45 minutes to add the feature, and the rest of the time is trying to fix the feature. I’ll continue debugging it.
Added the /rep-bot-profile command which queries the database for your points + the amount of people that have more points than you and then tells you.
Next up: a leaderboard command
I got the bot working! People who say “thanks” or “thank” or “thx” followed by pinging someone will give that person 1 rep point.
I setup the SQLite database with Drizzle ORM.
I had lots of trouble with getting the bot to recognize that messages were even sent, so I went to Stardance’s slack bot guide for help with setting up my bot properly. I don’t know what exactly I changed to fix it, but the bot started recognizing new messages sent in the channel after I added all the permissions the guide said to add.