项目作者: SHAKOTN

项目描述 :
Slack bot
高级语言: Python
项目地址: git://github.com/SHAKOTN/orion_bot.git
创建时间: 2017-05-25T11:35:37Z
项目社区:https://github.com/SHAKOTN/orion_bot

开源协议:

下载


This is a simple Slack Bot with plugins!

NOTE: This bot is single-threaded since I am too lazy to update the project with ThreadPoolExecutor for concurrent IO.

This bot is ready to be deployed to Heroku (Procfile and requirements.txt are created and filled).
If you want to use celery and write your own tasks for it add to Procfile:

  1. worker: celery worker --app=bot.celery.app

Available plugins right now:

  • Overwatch: Statistics, hero stats etc
  • Notes: Create, edit and share notes with your slackmates in channels
  • Weather: Ask bot to print the weather of the city
  • File storage(files): Store your files in dropbox
  • Some news plugins (IGN, etc)
  • SoundCloud: coming soon

NOTE: You can remove plugins from plugins/ directory if you don’t want to use them.

All you need to do is to specify these ENV_VARIABLES:

  • BOT_ID : Your slackbot ID
  • REGION : EU/US (for overwatch plugin: if you don’t use it - just skip this)
  • APIXU_API_KEY: Weather service token(Apixu). This is very friendly and free to use service.
    Just skip this if you don’t want to use weather plugin
  • SLACK_BOT_TOKEN : You can obtain it on web.slack.com
  • DROPBOX_TOKEN: Dropbox app token for files plugin
  • ENV : set to development if you don’t have redis and want to use local memory.
    Set to production if you want to use your redis to store data from plugins
  • REDIS_URL: Redis URL if you set ENV to production
  • CELERY_ENABLED: Set value to 1 if you want to use celery and also-
  • AMQP_URL: for celery too
  • NEWS_API_KEY: if you want to use news plugins (https://newsapi.org/)

If you want to run it locally - just clone repo, specify ENV variables and make:

  1. python bot/core.py

Writing your own task to schedule some bot jobs

NOTE Use celery with AMQP Broker for it
For example you want to post to your channel random file
from you storage using files plugin periodically:

  1. # file: bot/tasks.py
  2. @app.task
  3. def post_random_webm():
  4. files_cls = import_string(files_cls_str)
  5. files_plugins = [
  6. p for p in slack_backend.plugins
  7. if isinstance(p, files_cls)
  8. ]
  9. file_plugin = files_plugins[0]
  10. file_plugin.randomize('games')

And then you just add it to celerybeat cron jobs:

  1. # file bot/celery.py
  2. @app.on_after_configure.connect
  3. def add_periodic(**kwargs):
  4. from bot.tasks import post_random_webm
  5. app.add_periodic_task(
  6. crontab(minute=0,
  7. hour='7,8,9,10,11,12,13,14,15,16,17,18'),
  8. post_random_webm.s(),
  9. name='Post random WEBM'
  10. )

Examples of plugins

Overwatch Plugin

Alt text

Alt text

Notes plugin

Alt text

Alt text

Storage plugin

Works good with .webm, .jpeg, .png

Alt text