aboutsummaryrefslogtreecommitdiffstats
path: root/warmachine/addons/standup.py
diff options
context:
space:
mode:
Diffstat (limited to 'warmachine/addons/standup.py')
-rw-r--r--warmachine/addons/standup.py68
1 files changed, 56 insertions, 12 deletions
diff --git a/warmachine/addons/standup.py b/warmachine/addons/standup.py
index 24d635c..ac2afea 100644
--- a/warmachine/addons/standup.py
+++ b/warmachine/addons/standup.py
@@ -1,6 +1,7 @@
1import asyncio 1import asyncio
2from datetime import datetime, timedelta 2from datetime import datetime, timedelta
3import functools 3import functools
4import json
4from pprint import pformat 5from pprint import pformat
5 6
6from .base import WarMachinePlugin 7from .base import WarMachinePlugin
@@ -11,8 +12,12 @@ class StandUpPlugin(WarMachinePlugin):
11 WarMachine stand up plugin. 12 WarMachine stand up plugin.
12 13
13 Commands: 14 Commands:
14 !standup-add <24 hr time to kick off> <SunMTWThFSat> [channel] 15 In a channel:
15 !standup-remove [channel] 16 !standup-add <24 hr time to kick off>
17 !standup-remove
18 Direct Message:
19 !standup-schedules
20 !standup-waiting_replies
16 """ 21 """
17 def __init__(self, *args, **kwargs): 22 def __init__(self, *args, **kwargs):
18 super().__init__(*args, **kwargs) 23 super().__init__(*args, **kwargs)
@@ -26,6 +31,14 @@ class StandUpPlugin(WarMachinePlugin):
26 self.users_awaiting_reply = {} 31 self.users_awaiting_reply = {}
27 32
28 async def recv_msg(self, connection, message): 33 async def recv_msg(self, connection, message):
34 """
35 When the connection receives a message this method is called. We parse
36 the message for commands we want to listen for.
37
38 Args:
39 connection (Connection): the warmachine connection object
40 message (dict): the warmachine formatted message
41 """
29 if not message['message'].startswith('!standup'): 42 if not message['message'].startswith('!standup'):
30 if message['channel'] in self.users_awaiting_reply: 43 if message['channel'] in self.users_awaiting_reply:
31 self.log.debug("Probable reply recvd from {}: {}".format( 44 self.log.debug("Probable reply recvd from {}: {}".format(
@@ -57,8 +70,6 @@ class StandUpPlugin(WarMachinePlugin):
57 del self.users_awaiting_reply[message['channel']] 70 del self.users_awaiting_reply[message['channel']]
58 return 71 return
59 72
60 self.log.debug('standup recv: {}'.format(message))
61
62 cmd = message['message'].split(' ')[0] 73 cmd = message['message'].split(' ')[0]
63 parts = message['message'].split(' ')[1:] 74 parts = message['message'].split(' ')[1:]
64 75
@@ -73,9 +84,6 @@ class StandUpPlugin(WarMachinePlugin):
73 standup_td = next_standup - datetime.now() 84 standup_td = next_standup - datetime.now()
74 next_standup_secs = standup_td.seconds 85 next_standup_secs = standup_td.seconds
75 86
76 ### DEBUG
77 # next_standup_secs = 5
78 ###
79 f = self._loop.call_later( 87 f = self._loop.call_later(
80 next_standup_secs, functools.partial( 88 next_standup_secs, functools.partial(
81 self.standup_schedule_func, connection, message['channel'])) 89 self.standup_schedule_func, connection, message['channel']))
@@ -85,15 +93,26 @@ class StandUpPlugin(WarMachinePlugin):
85 'datetime': next_standup, 93 'datetime': next_standup,
86 'time24h': parts[0], 94 'time24h': parts[0],
87 } 95 }
96
97 self.log.info('New schedule added to channel {} for {}'.format(
98 connection.channel_map[message['channel']]['name'],
99 parts[0]
100 ))
101
88 await connection.say('Next standup at {} ({}s)'.format( 102 await connection.say('Next standup at {} ({}s)'.format(
89 next_standup.ctime(), next_standup_secs), message['channel']) 103 next_standup.ctime(), next_standup_secs), message['channel'])
90 104
91 await connection.say(str(self.standup_schedules), 105 # d = json.dumps(self.standup_schedules)
92 message['channel']) 106 # with open('~/.warmachine/standup_schedules.json', 'w') as f:
107 # f.write(d)
108
109
93 ###################### 110 ######################
94 # !standup-schedules # 111 # !standup-schedules #
95 ###################### 112 ######################
96 elif cmd == '!standup-schedules': 113 elif message['channel'].startswith('D') and cmd == '!standup-schedules':
114 self.log.info('Reporting standup schedules to DM {}'.format(
115 message['channel']))
97 await connection.say('Standup Schedules', message['channel']) 116 await connection.say('Standup Schedules', message['channel'])
98 await connection.say('-----------------', message['channel']) 117 await connection.say('-----------------', message['channel'])
99 await connection.say( 118 await connection.say(
@@ -106,20 +125,45 @@ class StandUpPlugin(WarMachinePlugin):
106 ############################ 125 ############################
107 # !standup-waiting_replies # 126 # !standup-waiting_replies #
108 ############################ 127 ############################
109 elif cmd == '!standup-waiting_replies': 128 elif messages['channel'].startswith('D') and \
129 cmd == '!standup-waiting_replies':
130 self.log.info('Reporting who we are waiting on replies for to DM '
131 ' {}'.format(message['channel']))
110 await connection.say('Waiting for Replies From', message['channel']) 132 await connection.say('Waiting for Replies From', message['channel'])
111 await connection.say('------------------------', message['channel']) 133 await connection.say('------------------------', message['channel'])
112 await connection.say( 134 await connection.say(
113 pformat(self.users_awaiting_reply), message['channel']) 135 pformat(self.users_awaiting_reply), message['channel'])
114 136
115 def standup_schedule_func(self, connection, channel): 137 def standup_schedule_func(self, connection, channel):
116 asyncio.ensure_future(self.start_standup(connection, channel)) 138 """
139 Non-async function used to schedule the standup for a channel.
140
141 See :meth:`start_standup`
142 """
143 self.log.info('Executing standup for channel {}'.format(
144 connection.channel_map[channel]['name']
145 ))
146 asyncio.ensure_future(self.start_standup(connection, channel))
117 147
118 def pester_schedule_func(self, connection, user_id, channel, pester): 148 def pester_schedule_func(self, connection, user_id, channel, pester):
149 """
150 Non-async function used to schedule pesters for a user.
151
152 See :meth:`standup_priv_msg`
153 """
154 self.log.info('Pestering user {} to give a standup for channel '
155 '{} (interval: {}s)'.format(
156 connection.user_map[user_id],
157 connection.channel_map[channel]['name'],
158 pester))
119 asyncio.ensure_future(self.standup_priv_msg( 159 asyncio.ensure_future(self.standup_priv_msg(
120 connection, user_id, channel, pester)) 160 connection, user_id, channel, pester))
121 161
122 async def start_standup(self, connection, channel): 162 async def start_standup(self, connection, channel):
163 """
164 Notify the channel that the standup is about to begin, then loop through
165 all the users in the channel asking them report their standup.
166 """
123 await connection.say('@channel Time for standup', channel) 167 await connection.say('@channel Time for standup', channel)
124 users = connection.get_users_by_channel(channel) 168 users = connection.get_users_by_channel(channel)
125 169