Skip to content
게임 커뮤니티 슬랙봇
Python Dockerfile Shell
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
apps
compose
.gitignore
README.md
chromedriver
chromedriver.py
docker-compose.yml
google-chrome-stable_current_amd64.deb
logger.py
requirements.txt
restart.sh
robot.py
settings_example.py
staging.yml

README.md

irk-slackbot

haandol님의 프로젝트를 clone받아 진행하였습니다

A neat Slack bot for Pythonistas

Dependencies

Python 3.5.3+ (for async/await)

redis, slackclient.

$pip install -r requirements.txt

Usage

If you are using Python 2.x use 0.0.3

Like Django, you can config your bot by editing settings.py

set SLACK_TOKEN variable in settings.py. if REDIS_URL is not setted, all Redis relevant features, like redis_brain, will be disabled.

한국어 튜토리얼

Congiure your bot

  1. install dependencies
  2. Add your bot for your slack account at Custom Integration Page
  3. Copy API Token to clipboard.
  4. Open settings.py
  5. Set SLACK_TOKEN. You can set REDIS_URL if it's available.
  6. Run $python robot.py. Python 3.5.3+ is required.
  7. Invite your bot to the channel /invite @YOUR_BOT_NAME

Play with it on the Slack

Type command with Command Prefix (default is ! ) on the channel where the bot is on.

Honey is going to respond to your command kindly.

YOU: !help

Honey: Hello world!!

Apps

We call each function that you plugged-in to the Honey, the app.

Built-in and example apps are in the apps directory.

App and Command

Below is basic form of app. notice that the function has prefix, async. This just says Hello world!! to the channel when user typed the command, !hi.

from .decorators import on_command

@on_command(['hi', 'hello', '하이', 'ㅎㅇ'])
async def hello_world(robot, channel, user, tokens):
    '''
        Simple app just says `Hello word!!`

        @params {object} robot - Honey bot instance
        @params {str} channel - channel name where invoked this app
        @params {str} user - user id who invoked this app
        @params {list} tokens - user input tokens
        @returns {str, str} - channel name, message
    '''
    return channel, 'Hello world!!'

And Honey supports multiple commands for each function.

The above app can be invoked the command with Command Prefix (default is !) on the channel. It would be !hello, !hi, !하이 or !ㅎㅇ

Tokenizer

Honey automatically split your message into tokens by whitespaces.

Let's assume that you typed !memo remember this with blow app.

@on_command(['memo'])
async def remember(robot, channel, user, tokens):
    assert 2 == len(tokens)
    assert 'remember' == tokens[0]
    assert 'this' == tokens[1]
    return channel, tokens[1]

You may want tokens containing whitespaces. In that case, wrap your token with double quote(") like

!memo remember "kill -9 $(ps aux | grep gunicorn | grep -v 'grep' | awk '{print $2 }')"

Redis Brain

Honey supports semi-permanent storage using Redis as well as Hubot.

The full usage code is on apps/redis_brain. If you want to use the feature, just add redis_brain to APPS variable at your settings.py

Let's assume that you typed !memo whats this in your channel with below app.

after that, whenever you type !memo whats Honey will says this to the channel.

if you forgot what you memoized, just type !memo. Honey let you know what she memoized before.

Register your app

  1. Add your app and put it into apps folder
  2. open settings.py and add your app name(like hello_world) to APPS
  3. restart your bot
You can’t perform that action at this time.