Simple framwork for executing python functions via Slack
Project description
# Yasuf — Yet Another Slack, Ummm, Framework
Very simple way of controlling your Python application via Slack.
Yasuf consist of a single, simple decorator that allows you to execute the decorated function via Slack and get it's output back, without modifying the function in any way.
Let's say you have a function `say_hello` that takes a single integer argument, prints out "Hello!" that many times and returns string describing how many times it has done so:
```
def say_hello(count):
for i in range(count):
print("Hello!")
return "I've just said Hello! {} times!".format(count)
```
Controlling this function is as simple as decorating it with the `yasuf.handle` decorator:
```
from yasuf import Yasuf
yasuf = Yasuf('slack-token')
```
You can get your token [here](https://api.slack.com/docs/oauth-test-tokens).
```
@yasuf.handle('Say hello ([0-9]+) times!', channel='#general', types=[int])
def say_hello(count):
(...)
```
The first argument of `handle` specifies the regexp that the function should respond to, where each capture group corresponds to one argument of the decorated function, `channel` specifies which channel it should be listening to and `types` is a list of functions that will be applied to the captured arguments to convert them from string to whatever the decorated function expects.
Now you can run (or run_async).
```
yasuf.run()
```
From now on whenever you type `Say hello 3 times!` Yasuf will response with a couple hellos. Or you can ask Yasuf what he knows with the built-in function 'help'.
## Installation
```python3 -m pip install --user yasuf```
Very simple way of controlling your Python application via Slack.
Yasuf consist of a single, simple decorator that allows you to execute the decorated function via Slack and get it's output back, without modifying the function in any way.
Let's say you have a function `say_hello` that takes a single integer argument, prints out "Hello!" that many times and returns string describing how many times it has done so:
```
def say_hello(count):
for i in range(count):
print("Hello!")
return "I've just said Hello! {} times!".format(count)
```
Controlling this function is as simple as decorating it with the `yasuf.handle` decorator:
```
from yasuf import Yasuf
yasuf = Yasuf('slack-token')
```
You can get your token [here](https://api.slack.com/docs/oauth-test-tokens).
```
@yasuf.handle('Say hello ([0-9]+) times!', channel='#general', types=[int])
def say_hello(count):
(...)
```
The first argument of `handle` specifies the regexp that the function should respond to, where each capture group corresponds to one argument of the decorated function, `channel` specifies which channel it should be listening to and `types` is a list of functions that will be applied to the captured arguments to convert them from string to whatever the decorated function expects.
Now you can run (or run_async).
```
yasuf.run()
```
From now on whenever you type `Say hello 3 times!` Yasuf will response with a couple hellos. Or you can ask Yasuf what he knows with the built-in function 'help'.
## Installation
```python3 -m pip install --user yasuf```
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
Yasuf-0.5.dev0.tar.gz
(3.7 kB
view details)
File details
Details for the file Yasuf-0.5.dev0.tar.gz
.
File metadata
- Download URL: Yasuf-0.5.dev0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0fd67638236dec05fa3b8e3f127b10df95e3dd9ee358a3dbdee7461732fd8e7 |
|
MD5 | b976da15cd8deaf8d43a088631b21518 |
|
BLAKE2b-256 | 186ddaad601eff1db12fd9f46b9cc5d8aad88142fe670bacdb1eb519c013048a |