Table of contents
pip install git+https://github.com/ntk148v/rocketbot.git
Check out the sample.
import os
from rocketbot import RocketBot
username = os.environ.get('ROCKET_USERNAME')
password = os.environ.get('ROCKET_PASSWORD')
server_url = os.environ.get('ROCKET_SERVER_URL')
rocket = RocketBot(user=username, password=password,
server_url=server_url, ssl_verify=False,
session=requests.sessions.Session(),
threading_updates=True)
You can add a new plugin to initialized bot by using decorator add_command
. add_command
requires 2 arguments:
- The regex that bot will respond if matching.
- The bot's usage.
@rocket.add_command(r'/start', usage='Start working with bot')
def start(message, *args):
rocket.send_message(
message['rid'], f"hi @{message['u']['username']}, let's start")
By default, RocketBot writes log to stderr with default level is "INFO". You can customize it by passing a configuration dict. You can refer to loguru's offical document.
rocket = RocketBot(user=username, password=password,
server_url=server_url, ssl_verify=False,
session=requests.sessions.Session(),
logger_config={
"handlers": [
{"sink": sys.stdout, "format": "{time} - {message}"},
{"sink": "/tmp/file.log", "serialize": True},
],
},
threading_updates=True)
rocket.run(sleep=10)
This library is highly inspired by: