GithubHelp home page GithubHelp logo

jcarbaugh / butterfield Goto Github PK

View Code? Open in Web Editor NEW
61.0 61.0 8.0 43 KB

A Python Slack bot framework using asyncio and Slack's Real Time Messaging API

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%

butterfield's Introduction

Hey

  • ๐Ÿš€ 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

Python badge

butterfield's People

Contributors

jcarbaugh avatar paultag avatar wdoekes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

butterfield's Issues

Posts can't be done outside of a handler?

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?

Bot should recognise other bots

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'

Support continous output from a subprocess/handler

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.