diff options
| -rw-r--r-- | warmachine/addons/standup.py | 71 | ||||
| -rw-r--r-- | warmachine/connections/slack.py | 6 |
2 files changed, 57 insertions, 20 deletions
diff --git a/warmachine/addons/standup.py b/warmachine/addons/standup.py index ebc4cac..24d635c 100644 --- a/warmachine/addons/standup.py +++ b/warmachine/addons/standup.py | |||
| @@ -64,11 +64,14 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 64 | 64 | ||
| 65 | self._loop = asyncio.get_event_loop() | 65 | self._loop = asyncio.get_event_loop() |
| 66 | 66 | ||
| 67 | ################ | ||
| 68 | # !standup-add # | ||
| 69 | ################ | ||
| 67 | if cmd == '!standup-add': | 70 | if cmd == '!standup-add': |
| 68 | next_standup = self.get_next_standup_secs(parts[0]) | 71 | next_standup = self.get_next_standup_secs(parts[0]) |
| 69 | 72 | ||
| 70 | pretty_next_standup = next_standup - datetime.now() | 73 | standup_td = next_standup - datetime.now() |
| 71 | next_standup_secs = pretty_next_standup.seconds | 74 | next_standup_secs = standup_td.seconds |
| 72 | 75 | ||
| 73 | ### DEBUG | 76 | ### DEBUG |
| 74 | # next_standup_secs = 5 | 77 | # next_standup_secs = 5 |
| @@ -80,11 +83,34 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 80 | self.standup_schedules[message['channel']] = { | 83 | self.standup_schedules[message['channel']] = { |
| 81 | 'future': f, | 84 | 'future': f, |
| 82 | 'datetime': next_standup, | 85 | 'datetime': next_standup, |
| 86 | 'time24h': parts[0], | ||
| 83 | } | 87 | } |
| 84 | await connection.say('Next standup in {} ({})'.format( | 88 | await connection.say('Next standup at {} ({}s)'.format( |
| 85 | pretty_next_standup, next_standup), message['channel']) | 89 | next_standup.ctime(), next_standup_secs), message['channel']) |
| 90 | |||
| 86 | await connection.say(str(self.standup_schedules), | 91 | await connection.say(str(self.standup_schedules), |
| 87 | message['channel']) | 92 | message['channel']) |
| 93 | ###################### | ||
| 94 | # !standup-schedules # | ||
| 95 | ###################### | ||
| 96 | elif cmd == '!standup-schedules': | ||
| 97 | await connection.say('Standup Schedules', message['channel']) | ||
| 98 | await connection.say('-----------------', message['channel']) | ||
| 99 | await connection.say( | ||
| 100 | 'Current Loop Time: {}'.format(self._loop.time()), | ||
| 101 | message['channel']) | ||
| 102 | await connection.say( | ||
| 103 | 'Current Time: {}'.format(datetime.now()), message['channel']) | ||
| 104 | await connection.say( | ||
| 105 | pformat(self.standup_schedules), message['channel']) | ||
| 106 | ############################ | ||
| 107 | # !standup-waiting_replies # | ||
| 108 | ############################ | ||
| 109 | elif cmd == '!standup-waiting_replies': | ||
| 110 | await connection.say('Waiting for Replies From', message['channel']) | ||
| 111 | await connection.say('------------------------', message['channel']) | ||
| 112 | await connection.say( | ||
| 113 | pformat(self.users_awaiting_reply), message['channel']) | ||
| 88 | 114 | ||
| 89 | def standup_schedule_func(self, connection, channel): | 115 | def standup_schedule_func(self, connection, channel): |
| 90 | asyncio.ensure_future(self.start_standup(connection, channel)) | 116 | asyncio.ensure_future(self.start_standup(connection, channel)) |
| @@ -145,27 +171,36 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 145 | """ | 171 | """ |
| 146 | calculate the number of seconds until the next standup time | 172 | calculate the number of seconds until the next standup time |
| 147 | 173 | ||
| 174 | Args: | ||
| 175 | time24h (str): The 24 hour version of the time that the standup | ||
| 176 | should run on Mon-Fri | ||
| 177 | |||
| 148 | Returns: | 178 | Returns: |
| 149 | datetime: Datetime object representing the next datetime the standup | 179 | datetime: Datetime object representing the next datetime the standup |
| 150 | will begin | 180 | will begin |
| 151 | """ | 181 | """ |
| 152 | now = datetime.now() | 182 | now = datetime.now() |
| 153 | 183 | ||
| 154 | # if it's friday, wait 72 hours | ||
| 155 | if now.isoweekday() == 5: | ||
| 156 | hours = 72 | ||
| 157 | # if it's saturday, wait 48 | ||
| 158 | elif now.isoweekday() == 6: | ||
| 159 | hours = 48 | ||
| 160 | # if it's sunday-thur wait 24 | ||
| 161 | else: | ||
| 162 | hours = 24 | ||
| 163 | |||
| 164 | standup_hour, standup_minute = (int(s) for s in time24h.split(':')) | 184 | standup_hour, standup_minute = (int(s) for s in time24h.split(':')) |
| 165 | 185 | ||
| 166 | future = now + timedelta(hours=hours) | 186 | next_standup = datetime(now.year, now.month, now.day, |
| 167 | next_standup = datetime(future.year, future.month, future.day, | ||
| 168 | standup_hour, standup_minute) | 187 | standup_hour, standup_minute) |
| 188 | |||
| 189 | # If we've already past the time for today, schedule it for that time on the | ||
| 190 | # next weekday | ||
| 191 | if now > next_standup: | ||
| 192 | # if it's friday, wait 72 hours | ||
| 193 | if now.isoweekday() == 5: | ||
| 194 | hours = 72 | ||
| 195 | # if it's saturday, wait 48 | ||
| 196 | elif now.isoweekday() == 6: | ||
| 197 | hours = 48 | ||
| 198 | # if it's sunday-thur wait 24 | ||
| 199 | else: | ||
| 200 | hours = 24 | ||
| 201 | |||
| 202 | future = now + timedelta(hours=hours) | ||
| 203 | next_standup = datetime(future.year, future.month, future.day, | ||
| 204 | standup_hour, standup_minute) | ||
| 205 | |||
| 169 | return next_standup | 206 | return next_standup |
| 170 | standup_in = next_standup-now | ||
| 171 | return standup_in, standup_in.seconds | ||
diff --git a/warmachine/connections/slack.py b/warmachine/connections/slack.py index 613b15c..2cb230c 100644 --- a/warmachine/connections/slack.py +++ b/warmachine/connections/slack.py | |||
| @@ -44,7 +44,6 @@ class SlackWS(Connection): | |||
| 44 | async def read(self): | 44 | async def read(self): |
| 45 | if self.ws: | 45 | if self.ws: |
| 46 | message = json.loads(await self.ws.recv()) | 46 | message = json.loads(await self.ws.recv()) |
| 47 | self.log.debug('new message parsed: {}'.format(message)) | ||
| 48 | # Slack is acknowledging a message was sent. Do nothing | 47 | # Slack is acknowledging a message was sent. Do nothing |
| 49 | if 'type' not in message and 'reply_to' in message: | 48 | if 'type' not in message and 'reply_to' in message: |
| 50 | # {'ok': True, | 49 | # {'ok': True, |
| @@ -53,8 +52,9 @@ class SlackWS(Connection): | |||
| 53 | # 'ts': '1469743355.000150'} | 52 | # 'ts': '1469743355.000150'} |
| 54 | return | 53 | return |
| 55 | 54 | ||
| 55 | self.log.debug('new message parsed: {}'.format(message)) | ||
| 56 | # Handle actual messages | 56 | # Handle actual messages |
| 57 | elif message['type'] == 'message' and 'subtype' not in message: | 57 | if message['type'] == 'message' and 'subtype' not in message: |
| 58 | return await self.process_message(message) | 58 | return await self.process_message(message) |
| 59 | else: | 59 | else: |
| 60 | if 'subtype' in message: | 60 | if 'subtype' in message: |
| @@ -163,6 +163,8 @@ class SlackWS(Connection): | |||
| 163 | await self.say(pformat(self.user_map[self.user_nick_to_id[n]]), | 163 | await self.say(pformat(self.user_map[self.user_nick_to_id[n]]), |
| 164 | msg['channel']) | 164 | msg['channel']) |
| 165 | return | 165 | return |
| 166 | elif msg['text'].startswith('!looptime'): | ||
| 167 | await self.say(self._loop.time(), msg['channel']) | ||
| 166 | 168 | ||
| 167 | retval = { | 169 | retval = { |
| 168 | 'sender': msg['user'], | 170 | 'sender': msg['user'], |