aquelemiguel / parrot

🦜 A hassle-free, highly performant, self-hosted Discord music bot with YouTube and Spotify support. Powered by yt-dlp.
MIT License
136 stars 44 forks source link

refactor: parrot message types #198

Closed joao-conde closed 2 years ago

joao-conde commented 2 years ago
- -
Issue https://github.com/aquelemiguel/parrot/issues/123
Dependencies --
Decisions In the world of rust and typed languages, we should make more usage of types. Sending ad-hoc strings as messages (mythical strings.rs) worked fine but we can do better. It becomes a bigger problem now due to https://github.com/aquelemiguel/parrot/issues/123 where we want to have mappings of translations. This means if I want to send the HelloWorld message I can do so in fr, en, or pt. If all I use is a string, I have no way of knowing which message it is and how to translate it. This PR preps the translations PR.
Here we introduce the concept of message types. These types are then displayed. A future message translation implementation will take into account the server's set language and return a different string to display.
Another important topic is error handling. I did it in a way where every error was bubbled up. While intended at the time, I see now its a bit weird for the user to receive messages like "invalid token" or something of the sorts. A next PR will make the automatic conversion from ParrotError -> ParrotMessage -> sent to user. This way, we can filter specific error messages we want to display and convert those into a specific ParrotMessage and for the other errors, we just throw a generic error message.