March 3rd, 2022
In a couple of days, I will be releasing the source code for my Twitter and Mastodon automated accounts, "What Pokémon Day is it today?", which you will find here on Gitlab in the coming days! I've also set it up for use as a Discord bot you can host yourself, maybe some time later I'll figure out how to host the Discord bot myself so you can easily invite it to your server or something.
Within this I've written up how the code works already, so, I won't go over it here, instead I'll talk about the process of making it, and the trials and errors I've had to go through along the way!
The process of creating a bot
So, I barely knew anything about Python before jumping into this. In fact I don't have much programming experience at all, I only started doing serious stuff with Lua 2 years ago! Well, as serious as Sonic Robo Blast 2 and Super Mario Bros. X2 can be with coding. So I dived in with only like, maybe 25 lines of Python being previously written by me.
My first task was just trying to wrangle with the Twitter's API, since for some reason they decided recently to make a new version of the API that:
- Has less features than the original version (like the ability to attach images???)
- Worked a lot slower after some tests
- And most damning of all is that they arbitrarily make you wait for permission just to use the last version!
So, I ended up having to email Twitter why I needed the previous version of the API, which they call Elevated Access, because I guess they just want to be confusing. Eventually I got access to it on the main account I want to use this on, but I also wanted to use it on my main account, since I needed to do tests. You don't just do tests on an account with 1,600+ followers, of whom many will have notifications turned on and will see every single test you do.
Annoyingly the email exchange with Twitter took 6 tries just to get through! They kept asking me "what's the purpose of you needing this API" over and over again, even though they understood my intent the first time around for my other account! But eventually I finally got approval to work on my bot.
Once all of that was done and over with I decided I want to host this on a git repository because I knew I'd eventually release the source code for this. That and it gave me a good excuse to learn how to do this if I ever want to get more serious about my coding later down the line! I debated on using either GitHub or Gitlab, I eventually settled on the latter because uh... GitHub doesn't have the best reputation, and in a world with choices, I'll take the better one. Also I really hate Microsoft, there's a reason I abandoned Windows in favor of Linux. Oh, and I've technically had more experience wtih Gitlab since I've had to wrangle with Sonic Robo Blast 2's source code while making my lua scripts!
And now with the repo choice out of the way, I finally started coding.
The troubles of making a bot for an actively ran account
Do you want to experience what it's like having an elevated level of anxiety, compounded ontop of the need to stay awake to see if something works? No? Then don't make a Python bot that you're continously updating, on an account with thousands of followers! (or do, i'm not ur mom)
By this point my bot has had to go down 3-4 times since I'm constantly updating the script, in which because it's hard to test my bot in real-time, I'm unsure if the code actually worked or not. The reasons this happens is complicated, but in essence when I'm testing my script, I have some features disabled to prevent my script from posting, and to facilitate faster testing. And sometimes I just... forget to check for the other stuff when I'm done with an update to my code!
The most recent time I've had it go down at the time of writing, I was actually asleep! I just assumed it would work, come to find out 3 hours later when I woke up, I didn't see a Discord message indicating it even posted. Sure enough, it didn't friggin post! So I had to temporarily enable my script to go into "post immediately" mode, run it, see it post, then disable the mode, run the script again, and... I fell back asleep. Thankfully I didn't have to reach for my computer, since my phone has a terminal emulator on there that can let me SSH into my Raspberry Pi, which is where I'm running my python script.
Debugging why the script doesn't work often isn't fun since half the time I'm not even sure why it isn't working, since by all means it just... should work. Then I find out later that it isn't running because I forgot something that would very obviously prevent it from running properly! The joys of coding come with this stuff, I guess.
I don't know how to conclude this so I guess we stop here
Yeah, basically. Anyways, it's been really fun working with Python, despite all the headaches it's caused. Here's to hoping when I release my source code, it doesn't magically break down when people try to use it for their Discord servers n stuff!