diff options
Diffstat (limited to 'warmachine')
| -rw-r--r-- | warmachine/addons/standup.py | 68 | ||||
| -rw-r--r-- | warmachine/connections/slack.py | 4 |
2 files changed, 59 insertions, 13 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 @@ | |||
| 1 | import asyncio | 1 | import asyncio |
| 2 | from datetime import datetime, timedelta | 2 | from datetime import datetime, timedelta |
| 3 | import functools | 3 | import functools |
| 4 | import json | ||
| 4 | from pprint import pformat | 5 | from pprint import pformat |
| 5 | 6 | ||
| 6 | from .base import WarMachinePlugin | 7 | from .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 | ||
diff --git a/warmachine/connections/slack.py b/warmachine/connections/slack.py index 2cb230c..0cc69d4 100644 --- a/warmachine/connections/slack.py +++ b/warmachine/connections/slack.py | |||
| @@ -153,6 +153,9 @@ class SlackWS(Connection): | |||
| 153 | for c in self._info.get('channels', []): | 153 | for c in self._info.get('channels', []): |
| 154 | self.channel_map[c['id']] = c | 154 | self.channel_map[c['id']] = c |
| 155 | 155 | ||
| 156 | for g in self._info.get('groups', []): | ||
| 157 | self.channel_map[g['id']] = g | ||
| 158 | |||
| 156 | async def process_message(self, msg): | 159 | async def process_message(self, msg): |
| 157 | # Built-in !whois action | 160 | # Built-in !whois action |
| 158 | if 'text' not in msg: | 161 | if 'text' not in msg: |
| @@ -357,7 +360,6 @@ class SlackWS(Connection): | |||
| 357 | # } | 360 | # } |
| 358 | # } | 361 | # } |
| 359 | 362 | ||
| 360 | |||
| 361 | # Invited to a public channel | 363 | # Invited to a public channel |
| 362 | # 2016-07-29 16:23:24,817 [DEBUG] SlackWS: on_channel_joined does not exist for message: {'type': 'channel_joined', 'chan | 364 | # 2016-07-29 16:23:24,817 [DEBUG] SlackWS: on_channel_joined does not exist for message: {'type': 'channel_joined', 'chan |
| 363 | # nel': {'members': ['U0286NL58', 'U1U05AF5J'], 'purpose': {'last_set': 0, 'creator': '', 'value': ''}, 'topic': {'last_s | 365 | # nel': {'members': ['U0286NL58', 'U1U05AF5J'], 'purpose': {'last_set': 0, 'creator': '', 'value': ''}, 'topic': {'last_s |