]> git.cworth.org Git - turbot/blob - turbot/commands.py
2a1f3e5b3ea618574b94cb53db8cace08b46f3e9
[turbot] / turbot / commands.py
1 import requests
2 import turbot.rot
3
4 def rot(slack_client, body, args):
5     """Implementation of the /rot command
6
7     The args string should be as follows:
8
9         [count|*] String to be rotated
10
11     That is, the first word of the string is an optional number (or
12     the character '*'). If this is a number it indicates an amount to
13     rotate each character in the string. If the count is '*' or is not
14     present, then the string will be rotated through all possible 25
15     values.
16
17     The result of the rotation is returned (with Slack formatting) in
18     the body of the response so that Slack will provide it as a reply
19     to the user who submitted the slash command."""
20
21     channel_name = body['channel_name'][0]
22     response_url = body['response_url'][0]
23     channel_id = body['channel_id'][0]
24
25     result = turbot.rot.rot(args)
26
27     if (channel_name == "directmessage"):
28         requests.post(response_url,
29                       json = {"text": result},
30                       headers = {"Content-type": "application/json"})
31     else:
32         slack_client.chat_postMessage(channel=channel_id, text=result)
33
34     return {
35         'statusCode': 200,
36         'body': ""
37     }