Utility plugins for Slack-Machine, the sexy, simple, yet powerful and extendable Slack bot
Project description
slack-machine-plugins
Utility plugins for Slack-Machine, the sexy, simple, yet powerful and extendable Slack bot.
pip install slack-machine-plugins
commander
Commander provides two classes Command
and CommandArgument
for a declarative way to define chat commands and their arguments for input validation and error feedback for the user. Features include:
- Type and length validation for chat command arguments.
- Strict choices.
- Custom validation and error messages.
- Usage and error texts for user feedback.
Example Usage
Taken from test case, realistic example.
# command definition
####################
from machine_plugins.commander import Command, CommandArgument
scale_cmd = Command(
name='scale',
description='Scale a deployment.',
arguments=[
CommandArgument(
name='namespace',
target_type=str,
choices=['default', 'dev'],
description='Namespace of the deployment.',
),
CommandArgument(
name='deployment',
validation=(lambda d: d.startswith('deployment-prefix-'),),
description='Name of the deployment.',
),
CommandArgument(
name='replicas',
target_type=int,
validation=(lambda r: 2 <= int(r) <= 10, 'You can not scale under 2 or above 10 replicas.'),
),
],
)
# command usage in slack-machine
################################
from machine.plugins.base import MachineBasePlugin
from machine.plugins.decorators import respond_to
class DeploymentPlugin(MachineBasePlugin):
@respond_to(regex=r'^scale ?(?P<args>.*)$')
def scale(self, msg, args):
errs = scale_cmd.errors(args)
if errs:
resp = '\n'.join(errs)
msg.say(f'```{resp}```')
return
# input validation complete, do your thing e.g `scale(*args.split())`
Project details
Release history Release notifications | RSS feed
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
Close
Hashes for slack-machine-plugins-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 832dd3a714415fee6de09f82ae174bf10858af7592c336c27ac0946bf8ebdf1d |
|
MD5 | 3304bd12ac2c0a18b4cee9ef6e112a5c |
|
BLAKE2b-256 | d88a7f40c09e26d5153dbed06a61ef63c33bcbeace68c5f87256ec6336ee6eea |
Close
Hashes for slack_machine_plugins-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 923b1d00d983d743d8fccae11522acc422588e23e9cb2ab684420f398aa3deca |
|
MD5 | 80ed8e20905968e485954e1754606db8 |
|
BLAKE2b-256 | 369f737042ed5e732498cb574012b2d1be489092ad0cd3e7dcae91cb07ab7d5c |