- ๐ Iโm currently working on technology stuff with Xplor
- ๐ฑ Iโm currently learning corporate finance ๐
- ๐ Pronouns: he/him
I enjoy Python and have published some packages on PyPI
A Python Slack bot framework using asyncio and Slack's Real Time Messaging API
License: BSD 3-Clause "New" or "Revised" License
I enjoy Python and have published some packages on PyPI
which would be neat
Nothing happens with the following code snippet:
from butterfield import Bot
bot = Bot('not-a-real-key')
bot.post("some-channel-id", 'Hi, channel!')
And if I try to "run" the bot first, it blocks on the run call:
import butterfield
from butterfield import Bot
bot = Bot('not-a-real-key')
butterfield.run(bot) # Never gets past here
bot.post("some-channel-id", 'Hi, channel!')
Posts only work from a handler, but that seems rather limiting. Am I missing something?
because it's really easy and would make deployment just so easy
The example from the docs would print an error about 'text' not existing in a message from an incoming webhook.
import asyncio
from butterfield import Bot
@asyncio.coroutine
def echo(bot, message: 'message'):
yield from bot.post(
message['channel'],
message['text']
)
b = Bot('slack-bot-key')
b.listen(echo)
butterfield.run(b)
Running the above code will result in this error:
Future/Task exception was never retrieved
Traceback (most recent call last):
File "/home/ingard/slackbot/venv33/lib/python3.3/site-packages/asyncio/tasks.py", line 238, in _step
result = next(coro)
File "bleh.py", line 22, in ping
if 'text' not in message:
KeyError: 'text'
.. when for instance our incoming nagios webhook posts. It doesnt have the 'text' key but rather 'attachment'
so you don't have to @bot
in a PM
I wrote an example handler for !ping example.com. The only way I could get it to actually return the output back to slack while still running was to add asyncio.sleep(). I'm thinking it would be better to handle the continous output from within the framework?
@asyncio.coroutine
def ping(bot, message: 'message'):
#yield from bot.post(
# message['channel'],
# message['text']
#)
if 'text' not in message:
return
if message['text'].startswith( '!ping' ):
match = re.findall(r"!ping( .*)?", message['text'])
if not match:
return
pingtarget = match[0].strip()
#yield from b.post(message['channel'], "ping "+pingtarget)
if re.search(r'\|',pingtarget):
# assuming slack did something weird with the "url"
# '<http://domain.com|domain.com>'
match = re.findall(r'\<http:\/\/(.+?)\|.*\>',pingtarget)
pingtarget = match[0]
yield from b.post(message['channel'], "Trying to ping "+pingtarget)
with subprocess.Popen(["ping", "-c1", pingtarget], stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p:
for line in p.stdout:
print(line, end='')
yield from bot.post( message['channel'], line )
yield from asyncio.sleep(0.01)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.