GithubHelp home page GithubHelp logo

rstms / bigslacker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nicholasamorim/bigslacker

0.0 2.0 0.0 22 KB

A slacker bot for Slack. Plugin-based.

License: GNU General Public License v3.0

Python 100.00%

bigslacker's Introduction

bigslacker - Slack big while having a bot

I would like to thank the University of Tartu and the BIIT Research Group for allowing me to publish this as an open-source library.

Overview

bigslacker tries to be faithful to its name. It is a Bot for Slack that allows you to plug plugins (!) the easiest possible way. All you have to do is define a class that inherits from BasePlugin and define methods for the events.

Supports Python 2 and 3.

Installation

Via PIP

pip install bigslacker

Manual

git clone https://github.com/nicholasamorim/bigslacker.git
python setup.py install

So far it has only one dependency, which is the official slackclient.

Example

Creating a Bot with a plugin to listen on channel_created only
from bigslacker import BigSlacker, BasePlugin

class ChannelAnnouncer(BasePlugin):
    def channel_created(self, data):
        print('I see a channel is created, gonna do something')

token = '1239182918sxxusus'
bs = BigSlacker(token)
bs.slack()

You don't have to do anything to register a plugin but inherit it from BasePlugin.

Sending a message back

We analyze every returned data from any Plugin we call. If you return None we do nothing. However, if you reply with [(channel, message)], we will automatically send that message to the specified channel.

from bigslacker import BigSlacker, BasePlugin

class ChannelAnnouncer(BasePlugin):
    def channel_created(self, data):
        print('I see a channel is created, gonna reply')
        return [('C1K4BBY8L', 'Hey guys, a channel has been created...')]

token = '1239182918sxxusus'
bs = BigSlacker(token)
bs.slack()

Of course, if you add more elements to the list, we will also send those messages.

I want every event in a single function

Sure. Just define a catch_all method.

from bigslacker import BigSlacker, BasePlugin

class ChannelAnnouncer(BasePlugin):
    def catch_all(self, data):
        print('gonna inspect that data...')

token = '1239182918sxxusus'
bs = BigSlacker(token)
bs.slack()
Can I use GEvent ?

Yes, all you have to do is monkey-patch it before on your application. Nothing else changes.

from gevent import monkey
monkey.patch_all()
Can I call the Slack API from it?

Yes, we expose the interface. So just call api_call on it as usual.

from bigslacker import BigSlacker

token = '1239182918sxxusus'
bs = BigSlacker(token)
bs.api_call("api.test")
bs.slack()

bigslacker's People

Watchers

James Cloos avatar  avatar

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.