This is the repo for the #trashbot that integrates with quite a few services to make dumb things more fun.
The currently supported feature set:
- Interact with Sonarr to manage TV Show collections
- Interact with Radarr to manage Movie collections
- Interact with Readarr to manage ebook & audiobook collections
You can install the required packages with:
pip install -r requirements.txt
You may need some additional system / OS packages though.
On Telegram, message the BotFather (@BotFather) (Should be searchable and verified)
Message him /newbot
and follow his instructions
Eventually, you will get a bot token.
Put that token in a .env
file
TOKEN=your_token_goes_here
In the main.py
file, find the modules
list, and replace oncall
with your module. Make sure it follows the import pattern of the other modules!
token
is the only one you need if you disable oncall
. Please disable oncall
Telegram has an API to fetch/send messages. The bot, running out of main.py
sets up a listener that constantly checks the API for new messages. This includes messages in any group/super chats its in, as well as direct messages.
Inside the bot are a set of modules. Each module is currently one of 2 types:
Command drive modules are called when a user executs a cert /<command>
and the bot sees the message. Commands execute a single handler and then usually send data back to the user
Conversational modules are designed like Wizards (not the magic missle kind). The wizard has an initial state which is invoked with a command, and it then defines a set of states it can transition into based on the messages it receives.
This module is a meme. It will listen in chat for a set of words, configured by the user(s). Once it sees those words in chat, it will respond with either Trash! or, if enabled, memes of Danny Devito
This is a premium only module designed to track and parse the oncall status that we are forced into by the overlords.
Type: Conversation & Command
Author: Jed Giblin
This modules is used to interact with Sonarr to manage TV Shows
Type: Conversation
Author: Jed Giblin
This module is used to interact with Radarr to manage movies.
Type: Conversation
Author: Jed Giblin
This module is used to interact with Readarr to manage books.
Type: Conversation
Author: Cole Aten
This module is used to configure other modules & record some user data
Type: Conversation & Command
Author: Jed Giblin
This module is used to schedule polls on a configurable basis
Type: Conversation
Author: David Hoy
The app is the actual bot code provided by the python-telegram-bot library. It's the core of the application. For the most part, you won't need to interact with it except:
This is the layer of the app that will initially load saved state data via pickle. You should never interact with this layer because data access in flight is controlled by the application, and anything you write to this layer will get overwritten by the application anyways.
In the scope of a handler, an update is an object that represents the incomming message. This is important to check things like message text/author, but also gives you helper methods to reply / delete / change messages.
Inside a handler, the context acts like a hook back to the application. This is the primary way you interact with saved state on a per user/chat basis. Context is read/write and things set will be persisted both to future messages AND to the disk (unless cleared)
This is TGUser
object that represents a user (usually in the context of a message author).
This is a TGChat
object that represents a group/super chat (usually in the context of the space a message was sent in)
updates are queued as they are received and processing of messages is performed serially (with current configuration). Do not execute long running tasks inside a handler unless needed.