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

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)

Todo

  • Support for commands need interaction

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

command4bot-0.1.2.tar.gz (7.2 kB view hashes)

Uploaded Source

Built Distribution

command4bot-0.1.2-py3-none-any.whl (7.3 kB view hashes)

Uploaded Python 3

Supported by

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