forked from rohan-achar/RPG-Helper-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack_bot.py
executable file
·39 lines (31 loc) · 1009 Bytes
/
slack_bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'''Runs the Slack RPG Helper bot.'''
import os
import argparse
import slack
from rpg_helper import RPGHelper
@slack.RTMClient.run_on(event="message")
def respond_to_messages(**payload):
'''Responds to messages on every channel if needed.'''
if any(key not in payload
for key in ("data", "web_client")):
return
data = payload["data"]
web_client = payload["web_client"]
if any(key not in data
for key in ("text", "channel", "user")):
return
resp = RPGHELPER.handle_command(data["user"], data["text"])
if resp:
web_client.chat_postMessage(
channel=data["channel"],
text=resp
)
if __name__ == "__main__":
PARSER = argparse.ArgumentParser()
PARSER.add_argument(
"-l", "--load",
default="minatoris",
help="Load a game by default on start")
ARGS = PARSER.parse_args()
RPGHELPER = RPGHelper(ARGS.load)
slack.RTMClient(token=os.environ["slack_token"]).start()