Botter - Simple interface for creating cross-messenger bots
Botter is a framework which allows your bots run in any available messenger. Currently, there are only one implementation for Discord, but it is easy to implement other platforms.
Okay, let's get started!
Getting Started
Creating an Application
At first, you should register a bot in the desired platform. As all messengers provide different ways to do so, we will not describe this process here.
Create Handler
Botter uses event-based architecture, with a most-common event - MessageEvent.
Events are handled by EventHandler's.
So, let's create out own:
from botter.api import *
from botter.api.handlers import *
class SimpleEchoHandler(ReplyHandler):
async def handle_message(self, message: InboundMessage) -> Message:
return Message(f"You've said:\n" + message.text)
Here we use the ReplyHandler, which:
- Nests
MessageHandler - Checks the event is
MessageEvent - Calls method
handle_message()with the message from event. - If this method returns
Messagerather than None,ReplyHandlerwould send it to server with a mention to the original message's author.
Crate a Bot
Then we need to create a Bot - object that aggregates handlers and mappings to the implementation.
Here we use discord driver as an example.
from botter.discord import DiscordBot
class EchoBot(Bot[DiscordBot]):
token = 'INSERT_YOUR_TOKEN_HERE'
event_handlers = [ SimpleEchoHandler ]
client = DiscordBot(token=token)
Okay, let's try it out!
Wow! It works!
Extending Events
Now, let's try to have some fun with the events.
Metadata
Release files for botter 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| botter-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Release files / botter-0.1.4-py3-none-any.whl
| Download URL | botter-0.1.4-py3-none-any.whl |
|---|---|
| Size | 21.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa602bca1e6b5308aa0000ddc4e27a521d9d4a521e874fedbbfccd446cd1e709
|
|
BLAKE2b-256 checksum How to use checksums |
00342a3715d89deadc7dc2a579daa88677090a7ac63ed20aca9b596d81845b36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.1 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.9
|