Skip to main content

A general purpose library for command-based iteraction made for bots

Project description

Command For Bot

PyPI PyPI - Wheel PyPI - Python Version

Run Tests codecov

Libraries.io dependency status for GitHub repo GitHub last commit PyPI - Downloads

Check Code Style pre-commit Code style: black Imports: isort

:warning: The document is still working in progress!

command4bot is a general purpose library for command-based iteraction made for bots, with command registry, command dependency (a.k.a. setup), ability to enable / disable commands, fallback functions included.

Installation

pip install command4bot

Quick Start

from command4bot import CommandsManager

mgr = CommandsManager()

@mgr.command
def greet(payload):
    return f"Hello, {payload}!"

mgr.exec('greet John')  # 'Hello, John!'

Basic Concepts and Usage

Command

Command is a function taking a positional argument (payload) and optional keyword arguments.

Setup (Command Dependency)

Command dependencies is trivial to manage if the command is always open.

For example, setup web socket connection if any command needs, and close the connection if all commands need the socket are closed.

@mgr.setup
def ws():
    ws_client = WSClient('localhost:8888')
    yield ws_client
    ws_client.close()

@mgr.command
def send(paload, ws):
    ws.send(payload)

Documentation

https://command4bot.readthedocs.io/en/latest/

Todo

  • Support for commands need interaction

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page