Lemmy Bot Best (Coding) Practices
Because of the increasing amount of Bots on lemmy and there is not (yet) a written Best (Coding) Practices post i want to make such Guideline.
The bot is required to follow the instances rules.
Guidelines
General Guidelines
1. Bots should stagger their calls to different endpoints to reduce the strain on the server
For example, instead of calling all three endpoints (Posts, Comments, and Reports) every 30 seconds,
you could call Posts every 30 seconds, Comments every 35 seconds, and Reports every 45 seconds. This
would spread out the load on the server and prevent it from becoming overloaded.
2. Bots should only fetch data that they really need.
For example, a spell-checking bot does not need to fetch reports.
This will help to reduce the amount of data that your bot needs to store, which will improve performance.
3. Bots should use a cache to store data that is required more often than 30 seconds.
This will improve performance and the strain to the server by reducing the number of times that your bot needs to fetch the data from the server.
4. Bots should remove unused data from their database on a regular basis.
This will free up space and improve performance.
5. Bots should be crash-safe, meaning that they should be able to recover from unexpected errors.
This can be done by using error handling techniques and by storing important data in a way that can be easily recovered and use a Backoff system to increase the retry time until it reaches a limit to stop completly.
6. Bots should add a delay to API-heavy commands and actions.
This will help to prevent the server from becoming overloaded.
7. Bots should not connect to multiple instances at a time.
This can cause conflicts and errors.
8. Bots should secure their servers.
This includes using strong passwords and keeping their software up to date.
9. If you are unsure if your bot is working properly, you should contact your local instance
admin. They can help you to troubleshoot any problems.
10. Bots should ignore other bots for commands or DMs.
This helps to prevent loops.
11. Bots should only fetch the communities that they should interact with.
This helps to reduce load on the server.
12. Global bots should be opt-in or have an opt-out feature.
This gives users control over whether or not they want to interact with your bot.
13. Bots should have the Bot flag activated AND include the word "bot" or other bot-related words in their name.
This helps users to identify your bot and understand its purpose.
For Improvment ideas leave a comment!