diff options
Diffstat (limited to 'warmachine/addons/standup.py')
| -rw-r--r-- | warmachine/addons/standup.py | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/warmachine/addons/standup.py b/warmachine/addons/standup.py index fd75473..6ee6378 100644 --- a/warmachine/addons/standup.py +++ b/warmachine/addons/standup.py | |||
| @@ -257,7 +257,7 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 257 | def clear_old_standup_message_schedule_func(self, user): | 257 | def clear_old_standup_message_schedule_func(self, user): |
| 258 | """ | 258 | """ |
| 259 | This function is scheduled to remove old standup messages so that the | 259 | This function is scheduled to remove old standup messages so that the |
| 260 | user is asked about standup the following day. | 260 | user is asked for updates on the next standup. |
| 261 | """ | 261 | """ |
| 262 | self.log.info('Clearing old standup message for {}'.format(user)) | 262 | self.log.info('Clearing old standup message for {}'.format(user)) |
| 263 | del self.users_awaiting_reply[user]['clear_standup_msg_f'] | 263 | del self.users_awaiting_reply[user]['clear_standup_msg_f'] |
| @@ -287,6 +287,17 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 287 | else: | 287 | else: |
| 288 | await self.standup_priv_msg(connection, u, channel) | 288 | await self.standup_priv_msg(connection, u, channel) |
| 289 | 289 | ||
| 290 | # schedule a function to run in 12 hours to clear out this channel from | ||
| 291 | # self.users_awaiting_reply for all `users`. | ||
| 292 | # This is assuming that after 12 hours, nobody cares about the report | ||
| 293 | # from people who never reported earlier. It will prevent flooding | ||
| 294 | # "tomorrow's" response to channels whose standup is scheduled for | ||
| 295 | # later. | ||
| 296 | self._loop.call_later(8*(60*60), # 8 hours | ||
| 297 | self.clean_channel_from_waiting_replies, channel, | ||
| 298 | users) | ||
| 299 | |||
| 300 | |||
| 290 | async def standup_priv_msg(self, connection, user, channel, pester=600, | 301 | async def standup_priv_msg(self, connection, user, channel, pester=600, |
| 291 | pester_count=0): | 302 | pester_count=0): |
| 292 | """ | 303 | """ |
| @@ -314,11 +325,13 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 314 | 'for_channels': [channel, ], | 325 | 'for_channels': [channel, ], |
| 315 | } | 326 | } |
| 316 | 327 | ||
| 328 | for_channels = self.users_awaiting_reply[user]['for_channels'] | ||
| 317 | await connection.say('What did you do yesterday? What will you ' | 329 | await connection.say('What did you do yesterday? What will you ' |
| 318 | 'do today? do you have any blockers? ' | 330 | 'do today? do you have any blockers? ' |
| 319 | '(standup for:{})'.format(channel), user) | 331 | '(standup for:{})'.format( |
| 332 | ', '.join(for_channels)), user) | ||
| 320 | 333 | ||
| 321 | if pester > 0 and pester_count <= 6: | 334 | if pester > 0 and pester_count <= 5: |
| 322 | self.log.info('Scheduling pester for {} {}m from now'.format( | 335 | self.log.info('Scheduling pester for {} {}m from now'.format( |
| 323 | user, pester/60)) | 336 | user, pester/60)) |
| 324 | f = self._loop.call_later( | 337 | f = self._loop.call_later( |
| @@ -366,6 +379,31 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 366 | 379 | ||
| 367 | return next_standup | 380 | return next_standup |
| 368 | 381 | ||
| 382 | def clean_channel_from_waiting_replies(self, channel, users): | ||
| 383 | """ | ||
| 384 | This clears ``channel`` from the list of interested channels for a | ||
| 385 | user's stand up, so that when the next stand up comes and they answer, | ||
| 386 | the other channels won't recieve information they are most likely not | ||
| 387 | interested in anymore | ||
| 388 | |||
| 389 | Args: | ||
| 390 | channel (str): The channel to clear out | ||
| 391 | users (list): List of users to check for | ||
| 392 | """ | ||
| 393 | for u in users: | ||
| 394 | if u in self.users_awaiting_reply: | ||
| 395 | self.log.info('Clearing channel {} from list of waiting ' | ||
| 396 | 'channels for user {}'.format(channel, u)) | ||
| 397 | self.users_awaiting_reply[u]['for_channels'].remove(channel) | ||
| 398 | |||
| 399 | # if that was the last channel, kill any pester tasks | ||
| 400 | if not self.users_awaiting_reply[u]['for_channels'] and \ | ||
| 401 | self.users_awaiting_reply[u]['pester_task']: | ||
| 402 | self.log.info('No more interested channels for {}. ' | ||
| 403 | 'Cancelling pester.'.format(u)) | ||
| 404 | self.users_awaiting_reply[u]['pester_task'].cancel() | ||
| 405 | del self.users_awaiting_reply[u]['pester_task'] | ||
| 406 | |||
| 369 | def save_schedule(self, connection): | 407 | def save_schedule(self, connection): |
| 370 | """ | 408 | """ |
| 371 | Save all channel schedules to a file. | 409 | Save all channel schedules to a file. |
| @@ -394,6 +432,9 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 394 | self.log.debug('Error loading standup schedules: {}'.format(e)) | 432 | self.log.debug('Error loading standup schedules: {}'.format(e)) |
| 395 | return | 433 | return |
| 396 | 434 | ||
| 435 | if connection.id not in data: | ||
| 436 | return | ||
| 437 | |||
| 397 | for channel in data[connection.id]: | 438 | for channel in data[connection.id]: |
| 398 | self.schedule_standup( | 439 | self.schedule_standup( |
| 399 | connection, channel, data[connection.id][channel]['time24h']) | 440 | connection, channel, data[connection.id][channel]['time24h']) |