-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger_node.py
More file actions
59 lines (49 loc) · 2.3 KB
/
trigger_node.py
File metadata and controls
59 lines (49 loc) · 2.3 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
from utils import get_users, get_username_from_id, post_message_to_channel
from loggers import blog
from conversation_node import DirectMessageNode
from greetings import greetings_factory
from pub import pub_trip_factory
def trigger_conversation(bot, user, channel):
if channel[0] == "D":
return greetings_factory(bot, user, channel)
else:
user_name = get_username_from_id(user, get_users(bot.slack_client))
post_message_to_channel(bot.slack_client, channel,
f"<@{user_name}> I'll message you.")
# Talks to user who posted
dmchannel = bot.slack_client.api_call("conversations.open",
users=[user])
blog.info(f"Triggered conversation with {user_name} " \
+ f"with ID: {user}")
if dmchannel['ok']:
bot.handlers[channel] = greetings_factory(bot, user, dmchannel['channel']['id'])
return None
else:
blog.warn(f"Cannot trigger pubbot with user: {user}")
def trigger_pub(bot, user, channel):
if channel[0] == "D":
return pub_trip_factory(bot, user, channel)
else:
users = get_users(bot.slack_client)
user_name = get_username_from_id(user, users)
blog.info(f"{user_name} triggered pub")
post_message_to_channel(bot.slack_client, channel,
f"<@{get_username_from_id(user, users)}> "
"Let's move to diect messages to organise "
"this pub trip.")
dmchannel = bot.slack_client.api_call("conversations.open",
users=[user])
if dmchannel['ok']:
dmchannel = dmchannel['channel']['id']
bot.handlers[dmchannel] = pub_trip_factory(bot, user, dmchannel)
return None
else:
blog.warn(f"Cannot trigger pubbot with user: {user}")
trigger_keywords = ["pub", "pint", "thirst", "drink"]
trigger_node_factory = lambda bot, channel: DirectMessageNode(bot, channel, user_responses={
".*(" + "h(i|ello|ey)" + ").*": trigger_conversation,
".*("+"|".join(trigger_keywords)+").*": trigger_pub,
".*": (["Sorry, I don't understand you. "
"To trigger pubbot use the following keywords: "
+", ".join(trigger_keywords)], None)
})