-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.py
More file actions
executable file
·84 lines (71 loc) · 3.42 KB
/
command.py
File metadata and controls
executable file
·84 lines (71 loc) · 3.42 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from utils import get_users, get_username_from_id
from loggers import blog
from greetings import greetings_factory
class Command(object):
def __init__(self, slack_client):
self.slack_client = slack_client
self.trigger_keywords = ["pub", "drink", "pint", "thirsty"]
def handle_command(self, user, command, channel):
if "hello" in command:
self.trigger_conversation(user, channel)
return
# Triggers pubbot if words in command are trigger words
for word in self.trigger_keywords:
if word in command:
self.trigger_pub_command(user, channel)
return
# If message doesn't contain key words
response = "Sorry I don't understand the command. " \
+ "To trigger pubbot use the following keywords: " \
+ ", ".join(self.trigger_keywords)
self.slack_client.api_call("chat.postMessage",
channel=channel,
text=response,
as_user=True)
return
def trigger_conversation(self, user, channel):
blog.info("Triggered conversation")
if channel[0] != "D":
response = "<@" \
+ str(get_username_from_id(user, get_users(self.slack_client)))\
+ "> I'll message you."
self.slack_client.api_call("chat.postMessage",
channel=channel,
text=response,
as_user=True)
# Talks to user who posted
blog.debug(f"Username: {user.get('name')} with ID: {user.get('id')}")
dmchannel = self.slack_client.api_call("conversations.open",
users=[user.get('id')])
if channel['ok']:
self.handlers[dmchannel['channel']['id']] = \
greetings_factory(self.slack_client, dmchannel['channel']['id'])
else:
blog.warn(f"Status is not ok for user: {user.get('id')}")
def trigger_pub_command(self, user, channel):
blog.info("Triggered pub")
users = get_users(self.slack_client)
if channel[0] != "D":
response = "<@" + str(get_username_from_id(user, users))\
+ "> Let's move to diect messages to organise this pub trip."
self.slack_client.api_call("chat.postMessage",
channel=channel,
text=response,
as_user=True)
#Talks to slackbot but no other bots
for user in users:
blog.debug(f"Username: {user.get('name')} with ID: {user.get('id')}")
channel = self.slack_client.api_call("conversations.open",
users=[user.get('id')])
if channel['ok']==True:
channelid=channel['channel']['id']
self.slack_client.api_call("chat.postMessage",
channel=channelid,
text="Fancy a pint?",
as_user=True)
else:
blog.warn(f"Status is not ok for user: {user.get('id')}")
return ""
def help(self):
response = "Currently I do xyz"
return response