A Python framework for easily creating Mastodon bots with pluggable content generation and filtering capabilities
Project description
RoboTooter
A Python framework for easily creating Mastodon bots with pluggable content generation and filtering capabilities.
Features
- Multiple Bot Types: Currently supports Markov chain-based text generation
- Plugin Architecture: Extensible plugin system for adding new bot types and functionality
- Flexible Filtering: Extensible filter system for processing input text (Gutenberg, blank line removal, paragraph combining)
- Mastodon Integration: Built-in support for posting to Mastodon instances
- CLI Interface: Comprehensive command line interface for bot and plugin management
- Configuration Management: Simple bot configuration and data management
Why?
I've built a few bots over the years, for fun. Recently I was reminded of a Twitter bot I wrote back in 2019 that generated sentences from a Markov chain generator trained on the text of Conan the Barbarian stories. I decided to reimplement it, this time for Mastodon.
I also wanted to be able to easily create other bots to do other things, and so built a simple plugin architecture.
Examples
- Conan-o-matic The original reason for this project. Yes, it's silly. I still find it funny.
- Chapter By Chapter] Posts a chapter a day from Public Domain litereature. Victorian-era Netflix.
- Storm Bot Sends out hurricane and tropical storm information, as well as daily updates of the tropical basin outlook.
Installation
As a Package
# Create a virtual environment
$ python3 -m venv .venv
# Activtate it
$ . .venv/bin/activate
# Install via pip
$ pip install robotooter
From Source
This project uses Poetry for dependency management. To install:
git clone ssh://git@codeberg.org/bfordham/robotooter.git
cd robotooter
poetry install
Quick Start
-
Configure the framework:
robotooter configure -
Create a new bot:
robotooter create -
Set up your bot's data (for Markov bots, add a
sources.txtfile to the bot directory):robotooter --bot <bot-name> setup
-
Authorize your bot with Mastodon:
robotooter --bot <bot-name> authorize
-
Generate content locally:
robotooter --bot <bot-name> speak
-
Post to Mastodon:
robotooter --bot <bot-name> toot
Bot Types
Markov Bot
The Markov bot generates text using Markov chains trained on source material.
Setup Requirements:
- Create a
sources.txtfile in your bot's working directory - Each line should contain a URL to a text file to use as training data
- Run
robotooter --bot <bot-name> setupto download and process the sources
Plugin Architecture
RoboTooter now supports a plugin system that allows you to extend the framework with custom bot types and functionality. Plugins inherit from the BasePlugin class and can define their own filters and bot implementations.
Plugin Development:
- Extend the
BasePluginclass to create custom bot types - Register plugins using
robotooter plugins register <plugin-name> - Remove plugins with
robotooter plugins remove <plugin-name>
CLI Commands
General Commands
robotooter info- Display information about the local setuprobotooter configure- Initialize configurationrobotooter create- Create a new botrobotooter list- List all configured botsrobotooter version- Display the current versionrobotooter help- Display help information
Bot-Specific Commands
robotooter --bot <name> setup- Download and process bot training datarobotooter --bot <name> authorize [--force]- Authorize bot with Mastodonrobotooter --bot <name> speak [--count N]- Generate content locallyrobotooter --bot <name> toot- Generate and post content to Mastodon
Plugin Management
robotooter plugins register <plugin-name>- Register a new pluginrobotooter plugins remove <plugin-name>- Remove a pluginrobotooter plugins help- Display plugin management help
Project Structure
src/robotooter/
bots/ # Bot implementations
base_bot.py # Base bot class
markov/ # Markov chain bot
cli/ # Command line interface
filters/ # Text processing filters
mastodon_manager.py # Mastodon API integration
models.py # Data models
util.py # Utility functions
Development
Requirements
- Python 3.12+
- Poetry for dependency management
Development Setup
poetry install --with dev
Running Tests
poetry run pytest
Code Quality
The project uses Ruff for linting and MyPy for type checking:
# Linting
./scripts/lint
# Type checking
./scripts/type
Dependencies
- requests: HTTP client for downloading source material
- markovify: Markov chain text generation
- mastodon.py: Mastodon API client
- pydantic: Data validation and settings management
- jinja2: Template engine
Contributing
If you would like to add features, please feel free. If you use this yourself, please let me know!
License
This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0). See the LICENSE file for details.
The AGPL-3.0 is a copyleft license that requires anyone who distributes the code or runs it on a server to make the source code available under the same license terms.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file robotooter-0.4.0.tar.gz.
File metadata
- Download URL: robotooter-0.4.0.tar.gz
- Upload date:
- Size: 36.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed3439d97325bb7b74265e9e4844158ee9ea6ffa2a06f67a50ca8271607c4c61
|
|
| MD5 |
7250e2ea6be23ba8a6dede97e88e0ed4
|
|
| BLAKE2b-256 |
a7f2f8d9988925de0e4cd90e334da99589db48d0cf49379584a29813e2b96dd8
|
File details
Details for the file robotooter-0.4.0-py3-none-any.whl.
File metadata
- Download URL: robotooter-0.4.0-py3-none-any.whl
- Upload date:
- Size: 54.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8951eeff547e81ee86448ac7546fc10124c12c683f31f01ed0b4f7f0c8c1175e
|
|
| MD5 |
0c82b554b378d471f909d57a37c8665b
|
|
| BLAKE2b-256 |
7de0dab106f516eec25bb2f41da0fdb0a54793b6203462fa479d02ad30295602
|