Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ env
*.un~
0/
tests/.cache
.coverage
.cache
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ python-rtmbot
=============

[![Build Status](https://travis-ci.org/slackhq/python-rtmbot.png)](https://travis-ci.org/slackhq/python-rtmbot)
[![Coverage Status](https://coveralls.io/repos/github/slackhq/python-rtmbot/badge.svg?branch=master)](https://coveralls.io/github/slackhq/python-rtmbot?branch=master)

A Slack bot written in python that connects via the RTM API.

Expand Down
8 changes: 7 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
coveralls==1.1
ipdb==0.9.3
ipython==4.1.2
pdbpp==0.8.3
pytest>=2.8.2
pytest-cov==2.2.1
pytest-pythonpath>=0.3
tox>=1.8.0
testfixtures==4.9.1
tox>=1.8.0
2 changes: 1 addition & 1 deletion rtmbot/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from core import *
from .core import *
13 changes: 12 additions & 1 deletion rtmbot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@

class RtmBot(object):
def __init__(self, config):
'''
Params:
- config (dict):
- SLACK_TOKEN: your authentication token from Slack
- BASE_PATH (optional: defaults to execution directory) RtmBot will
look in this directory for plugins.
- LOGFILE (optional: defaults to rtmbot.log) The filename for logs, will
be stored inside the BASE_PATH directory
- DEBUG (optional: defaults to False) with debug enabled, RtmBot will
break on errors
'''
# set the config object
self.config = config

Expand All @@ -30,7 +41,7 @@ def __init__(self, config):
logging.basicConfig(filename=log_file,
level=logging.INFO,
format='%(asctime)s %(message)s')
logging.info(self.directory)
logging.info('Initialized in: {}'.format(self.directory))
self.debug = self.config.get('DEBUG', False)

# initialize stateful fields
Expand Down
20 changes: 20 additions & 0 deletions tests/test_rtmbot_core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from testfixtures import LogCapture
from rtmbot.core import RtmBot


def test_init():
with LogCapture() as l:
rtmbot = RtmBot({
'SLACK_TOKEN': 'test-12345',
'BASE_PATH': '/tmp/',
'LOGFILE': '/tmp/rtmbot.log',
'DEBUG': True
})

assert rtmbot.token == 'test-12345'
assert rtmbot.directory == '/tmp/'
assert rtmbot.debug == True

l.check(
('root', 'INFO', 'Initialized in: /tmp/')
)
14 changes: 12 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ max-line-length= 100
exclude= tests/*

[testenv]
commands=py.test {posargs:tests}
passenv = TRAVIS TRAVIS_JOB_ID TRAVIS_BRANCH
commands =
py.test --cov-report= --cov=rtmbot {posargs:tests}
coveralls

deps =
-r{toxinidir}/requirements-dev.txt
-r{toxinidir}/requirements.txt
basepython =
py27: python2.7
py34: python3.4
Expand All @@ -20,4 +25,9 @@ basepython =
[testenv:flake8]
basepython=python
deps=flake8
commands=flake8 {toxinidir}/rtmbot.py {toxinidir}/rtmbot/core.py {toxinidir}/setup.py {toxinidir}/doc/example-plugins
commands=
flake8 \
{toxinidir}/rtmbot.py \
{toxinidir}/rtmbot/core.py \
{toxinidir}/setup.py \
{toxinidir}/doc/example-plugins