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.py60
1 files changed, 55 insertions, 5 deletions
diff --git a/warmachine/addons/standup.py b/warmachine/addons/standup.py
index a21efdd..7d1ec99 100644
--- a/warmachine/addons/standup.py
+++ b/warmachine/addons/standup.py
@@ -1,3 +1,7 @@
1import asyncio
2from datetime import datetime, timedelta
3import functools
4
1from .base import WarMachinePlugin 5from .base import WarMachinePlugin
2 6
3 7
@@ -9,6 +13,11 @@ class StandUpPlugin(WarMachinePlugin):
9 !standup-add <24 hr time to kick off> <SunMTWThFSat> [channel] 13 !standup-add <24 hr time to kick off> <SunMTWThFSat> [channel]
10 !standup-remove [channel] 14 !standup-remove [channel]
11 """ 15 """
16 def __init__(self, *args, **kwargs):
17 super().__init__(*args, **kwargs)
18
19 self.standup_schedules = {}
20
12 async def recv_msg(self, connection, message): 21 async def recv_msg(self, connection, message):
13 if not message['message'].startswith('!standup'): 22 if not message['message'].startswith('!standup'):
14 return 23 return
@@ -18,11 +27,52 @@ class StandUpPlugin(WarMachinePlugin):
18 cmd = message['message'].split(' ')[0] 27 cmd = message['message'].split(' ')[0]
19 parts = message['message'].split(' ')[1:] 28 parts = message['message'].split(' ')[1:]
20 29
30 self._loop = asyncio.get_event_loop()
31
21 if cmd == '!standup-add': 32 if cmd == '!standup-add':
22 await connection.say('Scheduling standup for {} on {}'.format( 33 pretty_next_standup, next_standup_secs = \
23 parts[1], parts[2])) 34 self.get_next_standup_secs(parts[0])
35
36 f = self._loop.call_later(
37 next_standup_secs, functools.partial(
38 self.standup_schedule_func, connection, message['channel']))
39
40 self.standup_schedules[message['channel']] = {
41 'future': f,
42 }
43 await connection.say('Next standup in {}'.format(
44 pretty_next_standup), message['channel'])
45 await connection.say(str(self.standup_schedules),
46 message['channel'])
47
48 def standup_schedule_func(self, connection, channel):
49 asyncio.ensure_future(self.start_standup(connection, channel))
50
51 async def start_standup(self, connection, channel):
52 await connection.say('@channel Time for standup', channel)
53 connection.get_users_by_channel(channel)
54
55 @classmethod
56 def get_next_standup_secs(cls, time24h):
57 """
58 calculate the number of seconds until the next standup time
59 """
60 now = datetime.now()
61
62 # if it's friday, wait 72 hours
63 if now.isoweekday() == 5:
64 hours = 72
65 # if it's saturday, wait 48
66 elif now.isoweekday() == 6:
67 hours = 48
68 # if it's sunday-thur wait 24
69 else:
70 hours = 24
24 71
25 # await connection.say('{}, {}'.format(cmd, parts), message['channel']) 72 standup_hour, standup_minute = (int(s) for s in time24h.split(':'))
26 73
27 async def start_standup(self, connection): 74 future = now + timedelta(hours=hours)
28 pass 75 next_standup = datetime(future.year, future.month, future.day,
76 standup_hour, standup_minute)
77 standup_in = next_standup-now
78 return standup_in, standup_in.seconds