Rewriting SpaceBot p-2
This is just day 1 and I feel very confident, even though it's been a little difficult. I decided to start with the bot in such a way that I can scale it almost infinitely, so I jotted down 5 things to do for the day: Complete the main file, Set up a good logging system, Decide a file structure for super clean code, Complete the fun cog WITH slash commands, and decide the database schema.
All that, while travelling from Mumbai to Deolali
Do you think I managed to do it?
I did most of this coding while in the car travelling from Mumbai to Deolali (I'm returning home as I write this blog).
Unpopular opinion: coding while travelling is super fun because no one knows what you are doing and why you are doing it
— Dhravya Shah (@DhravyaShah) January 23, 2022
By the way, follow me on twitter
A good logging system
First, I asked myself: What makes a good logging system?
These are some criteria I put for myself
- Proper log levels
- On-point log messages
- Important logs and spammy logs should be different
- Full traceback for only the errors that need it
I've set it up in such a way that all necessary information is provided for all errors. And for critical errors, the bot completely stops and spam pings me in my DM (security feature haha).
File system
I want my code to be extremely clean and organised, no compromises. I put all code in the src folder (with the env, gitignore, requirements.txt, license, etc. outside). Fun fact, I had to completely change everything about Spacebot 2.0 when I decided to make it open source, because the files werent organised at all.
So this is what I settled on, pretty happy with the result
Also, I didnt want to views to be inside the cog files itself, because it looks extremely ugly that way, so I added a views file (ignore the other utilities more on that soon)
And added buttons to a lot of stuffFun cog
I went on to rewrite every single fun command. Also added this neat button to use the command again (because most people are lazy like me lol).
VIEWS VIEWS VIEWS
I've added some kind of view/button/interaction to almost every single command that isnt a webhook or isnt too simple. I'm a madman? agreed.
If you want to see me do all this, help me test the bot etc. by joining The Coding Horizon
After doing this. I was bored. Like really really bored. I had all the stuff done (pretty much) and half of the journey was still left (remember, all this was done while i was travelling in the car)
Only slash commands and database schema was left, and it wasnt even 1pm yet
So I went on to create an amazing command corrector system:
Now, for the database
I always move away from databases because of a number of reasons, one of them being
Bruh, too much work
- Dhravya, 2022
I started writing down everything that i need to store in the database, which is a MySQL database hosted on my VPS. I went crazy and included everything I could think of.
The blog is getting too big right now and I have to set up a subscription system for it, so I'll continue tomorrow.
So, these are the things I've completed in spacebot rewrite already:
- Fun cog
- Database Connection systems
- Logging
- Views, a LOT of views
- Command hinter system
- Database Schema (IN NEXT BLOG THOUGH)
What did I learn?
- How to log errors and information efficiently
- How to organise folders for a great developer experience and clean code
- Mastered pycord interactions sytem
- Finding similar "stuff" using difflib
I'm working on an email subscription system for the blog for the 5 people who wanna get notified when i get home :)
Comments