diff options
Diffstat (limited to 'warmachine/addons/standup.py')
| -rw-r--r-- | warmachine/addons/standup.py | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/warmachine/addons/standup.py b/warmachine/addons/standup.py index d26567b..ef873d3 100644 --- a/warmachine/addons/standup.py +++ b/warmachine/addons/standup.py | |||
| @@ -136,7 +136,7 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 136 | # If no users are provided, display the users currently being ignored | 136 | # If no users are provided, display the users currently being ignored |
| 137 | # ====================================================================== | 137 | # ====================================================================== |
| 138 | elif cmd == '!standup-ignore' and channel \ | 138 | elif cmd == '!standup-ignore' and channel \ |
| 139 | and channel in self.standup_schedules: | 139 | and channel in self.standup_schedules: # noqa - indent level |
| 140 | if parts: | 140 | if parts: |
| 141 | users_to_ignore = ''.join(parts).split(' ') | 141 | users_to_ignore = ''.join(parts).split(' ') |
| 142 | for u in users_to_ignore: | 142 | for u in users_to_ignore: |
| @@ -156,7 +156,7 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 156 | await connection.say('Currently ignoring {}'.format(ignoring), | 156 | await connection.say('Currently ignoring {}'.format(ignoring), |
| 157 | channel) | 157 | channel) |
| 158 | elif cmd == '!standup-unignore' and channel \ | 158 | elif cmd == '!standup-unignore' and channel \ |
| 159 | and channel in self.standup_schedules: | 159 | and channel in self.standup_schedules: # noqa - indent level |
| 160 | if not parts: | 160 | if not parts: |
| 161 | return | 161 | return |
| 162 | 162 | ||
| @@ -179,8 +179,8 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 179 | # ====================================================================== | 179 | # ====================================================================== |
| 180 | # !standup-waiting_replies | 180 | # !standup-waiting_replies |
| 181 | # | 181 | # |
| 182 | # Report the data struct of users we are waiting on a reply from to the | 182 | # Report the data struct of users we are waiting on a reply from to |
| 183 | # requesting user. | 183 | # the requesting user. |
| 184 | # ====================================================================== | 184 | # ====================================================================== |
| 185 | elif not channel and cmd == '!standup-waiting_replies': | 185 | elif not channel and cmd == '!standup-waiting_replies': |
| 186 | self.log.info('Reporting who we are waiting on replies for to ' | 186 | self.log.info('Reporting who we are waiting on replies for to ' |
| @@ -194,7 +194,7 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 194 | """ | 194 | """ |
| 195 | Schedules a standup by creating a Task to be run in the future. This | 195 | Schedules a standup by creating a Task to be run in the future. This |
| 196 | populates ``self.standup_schedules[channel]`` with the following keys: | 196 | populates ``self.standup_schedules[channel]`` with the following keys: |
| 197 | - ``f`` (:class:`asyncio.Task`): This is the asyncio task object. | 197 | - ``future`` (:class:`asyncio.Task`): This is the asyncio task object. |
| 198 | - ``datetime`` (:class:`datetime.datetime`): The datetime of when the | 198 | - ``datetime`` (:class:`datetime.datetime`): The datetime of when the |
| 199 | standup will run next. | 199 | standup will run next. |
| 200 | - ``time24h`` (str): 24 hour time the schedule should be executed at. | 200 | - ``time24h`` (str): 24 hour time the schedule should be executed at. |
| @@ -217,9 +217,9 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 217 | 217 | ||
| 218 | # Don't overwrite existing setting if they exist | 218 | # Don't overwrite existing setting if they exist |
| 219 | if channel in self.standup_schedules: | 219 | if channel in self.standup_schedules: |
| 220 | self.standup_schedules[channel]['f'].cancel() | 220 | self.standup_schedules[channel]['future'].cancel() |
| 221 | 221 | ||
| 222 | self.standup_schedules[channel]['f'] = f | 222 | self.standup_schedules[channel]['future'] = f |
| 223 | self.standup_schedules[channel]['datetime'] = next_standup | 223 | self.standup_schedules[channel]['datetime'] = next_standup |
| 224 | self.standup_schedules[channel]['time24h'] = time24h | 224 | self.standup_schedules[channel]['time24h'] = time24h |
| 225 | else: | 225 | else: |
| @@ -258,13 +258,14 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 258 | This function is scheduled to remove old standup messages so that the | 258 | This function is scheduled to remove old standup messages so that the |
| 259 | user is asked about standup the following day. | 259 | user is asked about standup the following day. |
| 260 | """ | 260 | """ |
| 261 | self.log.info('Clearing old standup message for {}'.format(user)) | ||
| 261 | del self.users_awaiting_reply[user]['clear_standup_msg_f'] | 262 | del self.users_awaiting_reply[user]['clear_standup_msg_f'] |
| 262 | del self.users_awaiting_reply[user]['standup_msg'] | 263 | del self.users_awaiting_reply[user]['standup_msg'] |
| 263 | 264 | ||
| 264 | async def start_standup(self, connection, channel): | 265 | async def start_standup(self, connection, channel): |
| 265 | """ | 266 | """ |
| 266 | Notify the channel that the standup is about to begin, then loop through | 267 | Notify the channel that the standup is about to begin, then loop |
| 267 | all the users in the channel asking them report their standup. | 268 | through all the users in the channel asking them report their standup. |
| 268 | """ | 269 | """ |
| 269 | users = connection.get_users_by_channel(channel) | 270 | users = connection.get_users_by_channel(channel) |
| 270 | if not users: | 271 | if not users: |
| @@ -285,7 +286,8 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 285 | else: | 286 | else: |
| 286 | await self.standup_priv_msg(connection, u, channel) | 287 | await self.standup_priv_msg(connection, u, channel) |
| 287 | 288 | ||
| 288 | async def standup_priv_msg(self, connection, user, channel, pester=600): | 289 | async def standup_priv_msg(self, connection, user, channel, pester=600, |
| 290 | pester_count=0): | ||
| 289 | """ | 291 | """ |
| 290 | Send a private message to ``user`` asking for their standup update. | 292 | Send a private message to ``user`` asking for their standup update. |
| 291 | 293 | ||
| @@ -294,8 +296,10 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 294 | to use. | 296 | to use. |
| 295 | user (str): User to send the message to. | 297 | user (str): User to send the message to. |
| 296 | channel (str): The channel the standup is for | 298 | channel (str): The channel the standup is for |
| 297 | pester (int): Number of seconds to wait until asking the user again. | 299 | pester (int): Number of seconds to wait until asking the user |
| 298 | Use 0 to disable | 300 | again. Use 0 to disable |
| 301 | pester_count (int): An internal counter to stop pestering after | ||
| 302 | awhile. | ||
| 299 | """ | 303 | """ |
| 300 | self.log.debug('Messaging user: {}'.format(user)) | 304 | self.log.debug('Messaging user: {}'.format(user)) |
| 301 | 305 | ||
| @@ -303,28 +307,25 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 303 | # Don't readd an existing channel | 307 | # Don't readd an existing channel |
| 304 | if channel not in self.users_awaiting_reply[user]['for_channels']: | 308 | if channel not in self.users_awaiting_reply[user]['for_channels']: |
| 305 | self.users_awaiting_reply[user]['for_channels'].append(channel) | 309 | self.users_awaiting_reply[user]['for_channels'].append(channel) |
| 306 | |||
| 307 | self.log.debug('Adding to list of users waiting on a reply for: ' | ||
| 308 | '{}'.format( | ||
| 309 | self.users_awaiting_reply[user])) | ||
| 310 | else: | 310 | else: |
| 311 | self.log.debug('Waiting user {} for a reply '.format(user)) | ||
| 311 | self.users_awaiting_reply[user] = { | 312 | self.users_awaiting_reply[user] = { |
| 312 | 'for_channels': [channel, ], | 313 | 'for_channels': [channel, ], |
| 313 | } | 314 | } |
| 314 | 315 | ||
| 315 | |||
| 316 | await connection.say('What did you do yesterday? What will you ' | 316 | await connection.say('What did you do yesterday? What will you ' |
| 317 | 'do today? do you have any blockers? ' | 317 | 'do today? do you have any blockers? ' |
| 318 | '(standup for:{})'.format(channel), user) | 318 | '(standup for:{})'.format(channel), user) |
| 319 | 319 | ||
| 320 | if pester > 0: | 320 | if pester > 0 and pester_count <= 6: |
| 321 | self.log.info('Scheduling pester for {} {}m from now'.format( | ||
| 322 | user, pester/60)) | ||
| 321 | f = self._loop.call_later( | 323 | f = self._loop.call_later( |
| 322 | pester, functools.partial( | 324 | pester, functools.partial( |
| 323 | self.pester_schedule_func, connection, user, channel, | 325 | self.pester_schedule_func, connection, user, channel, |
| 324 | pester)) | 326 | pester, pester_count+1)) |
| 325 | self.users_awaiting_reply[user]['pester_task'] = f | 327 | self.users_awaiting_reply[user]['pester_task'] = f |
| 326 | 328 | ||
| 327 | |||
| 328 | @classmethod | 329 | @classmethod |
| 329 | def get_next_standup_secs(cls, time24h): | 330 | def get_next_standup_secs(cls, time24h): |
| 330 | """ | 331 | """ |
| @@ -335,8 +336,8 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 335 | should run on Mon-Fri | 336 | should run on Mon-Fri |
| 336 | 337 | ||
| 337 | Returns: | 338 | Returns: |
| 338 | datetime: Datetime object representing the next datetime the standup | 339 | datetime: Datetime object representing the next datetime the |
| 339 | will begin | 340 | standup will begin |
| 340 | """ | 341 | """ |
| 341 | now = datetime.now() | 342 | now = datetime.now() |
| 342 | 343 | ||