votebot package

Submodules

votebot.api module

The Slack Web API let you communicate with Slack.

Usage

The following example calls the api.test method which test whether your token is valid.

import os
import asyncio

from votebot.api import call


token = os.environ['SLACK_TOKEN']
loop = asyncio.get_event_loop()
response = loop.run_until_complete(call('api.test',
                                        token=token))
print(response)
loop.close()

File upload

Using the files.upload API call requires the content to be sent using multipart/form-data using file.

with open('myfile.png') as f:
    await call('files.upload',
               title='Super picture',
               filename='myfile.png',
               file=f)

Or send the raw content via content.

votebot.api.call(method, file=None, **kwargs)

Perform an API call to Slack.

Parameters:
  • file (file) – File pointer
  • **kwargs – see below
Keyword Arguments:
 

All the arguments required by the method from the Slack Web API.

Returns:

JSON response.

Return type:

dict

votebot.bot module

Slack bot.

class votebot.bot.Bot(token, *, channel=None, timeout=None)

Bases: object

Slack bot for voting.

call(method, file=None, **kwargs)

Wrap the api.call with the token.

cast_votes(title, text, timestamp, timeout)

End a vote by displaying the results and delete the original message.

Parameters:
  • title (str) – Initial question title.
  • text (str) – Initial question body.
  • timestamp (str) – message identifier
  • timeout – how many seconds before closing the votes
connect()

Launch the bot.

Returns:a future for when the bot wants to be closed.
Return type:asyncio.Future
on_message(message)

Handle a message.

usernames(*ids)

Convert the user ids into username.

Parameters:*ids – see below
Arguments:a list of user identifiers

votebot.config module

Global configuration and other magic numbers.

votebot.utils module

Utilitary functions.

votebot.utils.extract(message)

Split the message and the emojis to be voted for.

Parameters:message (str) – the message to be parsed.
Returns:the question and the emojis.
Return type:tuple
>>> extract('Hello :+1::-1:')
('Hello', [':+1:', ':-1:'])
>>> extract('Hello :+1:? :-1:')
('Hello :+1:?', [':-1:'])
>>> extract('No emoji')
('No emoji', [':+1:', ':heart:'])

Note

if no emojis are found after the question, you’ll automagically get the :+1: as well as the :heart:.

Module contents

Votebot module.

See __main__.py for more details on how to use it.