a slack bot that i'm making to help with some stuff
No followers yet
Once you ship this you can't edit the description of the project, but you'll be able to add more devlogs and re-ship it as you add new features!
I added a simple d6 dice roll that uses the random library, with logging and options to post in channel. I also created a boilerplate template that I can use for new commands that just requires changing a single variable (which is the command name). The dice roll firsts generates a random number between 1 and 6, checks the args (show in channel or visible to the user only) and if it contains true, it posts the random number in the channel. If it is anything else, it makes it so only the sender can see it (they're called ephemeral messages)
I tried to make a script that checks if a user is a channel manager but it turns out that there isn't a way to get this using documented apis unless you have slack enterprise, which Hack Club doesn't 😭 While doing this, I also moved the logic into modular programs, with commands being separate and a single main program that loads everything at once. This program handles environment variables and reduces the need to run multiple scripts at once. Also I found a message in the Slack about a method of finding channel managers involving an admin cookie, so I will try to implement that next, but for now, it only works if the id of the user running the commands is mine or the channel is #obobs-duck or #bot-spam
I made the sticky note actually stick! Basically, it has a function that runs whenever a message is sent in a channel that it's in and the bot checks if there is a sticked message, then saves the text from it, deletes it and sends it again. The first implementation wasn't the best because it would be called multiple times on different threads so it would bug out, post the same message twice and just wasn't very efficient with a new thread for every message. To fix this, I used the threading library to implement locks for channels and a debounce of 1 second so if a channel is really busy it doesn't waste lots of resources and won't bug out! ty for reading :D
I started making the sticky notes feature which basically sticks a message to the bottom of your channel. Right now, though, it doesn't actually pin it (it just acts like a normal message and if another message is posted in the channel, it doesn't actually stick 😭), which will be what i do in the next devlog.
To actually make this feature, I created a slash command (/sticky-note
) which has 3 actions, create, edit and delete. I used the Slack Bolt library with socket mode so i don't need a https endpoint and created a script that basically listens for the slash command. Then it splits the command into 2 parts, the action (the first keyword) and the message. If the action is valid (create, edit or delete) then it will do the action and if not, it will display an ephemeral message to the user with a usage guide. I also used sqlite3 to store the messages (channel_id and timestamp to be more specific because that's how slack keeps track of messages) in a database so it still remembers messages after a restart. and uhh sorry for this long devlog lol :D
I read the slack docs and created a simple script with the slack_bolt library to respond to the message hi in my testing channel