Adding a command - BIRD-UP73/nsfw-bot GitHub Wiki

When adding a command there are a few steps you need to go through.

Creating the URL

Go to url/urls.py and add the URL there

Each URL enum entry contains

  • The short URL, used a as a key and in the database to store favorites
  • The long URL, used to make API calls (will default to https://<short_url>/index.php)
  • The cheatsheet URL, to link the user to search terms used on the image board

Creating the command class

  • Create a class that extends NsfwCommand in commands/nsfw and fill in the required attributes The name required.
  • The URL is needed if the command actually needs to fetch posts from an API

Adding the command to the bot

  • In commands/nsfw/_setup.py, add the command

Custom fetcher (optional)

The default post fetching behavior is defined in posts/json_post_fetcher.py and posts/xml_post_fetcher.py. If your command needs to fetch posts in a different way, you should create a custom class that extends PostFetcher in posts/fetcher.

This fetcher should then be added in the ``

Custom paginator

Sometimes the site API has a weird way of handling pages (does it start from 0, is it < post_count or <= post_count)?

For this you can create a custom class that extends Paginator in posts/paginator.

The custom fetcher and/or paginator should be defined in a separate method in the class PostMessageFactory in posts/post_message/factory

⚠️ **GitHub.com Fallback** ⚠️