aboutsummaryrefslogtreecommitdiffstats
path: root/warmachine/addons/standup.py
diff options
context:
space:
mode:
authorjason2016-08-10 17:27:56 -0600
committerjason2016-08-10 17:27:56 -0600
commit1c4f034b5d66f422f6891d318ebf95abd82a5c53 (patch)
tree8031c5677a90df61703966f91ad42d53c2e360b9 /warmachine/addons/standup.py
parent4c618df245d179d97da440520b94ae4d11a1e681 (diff)
downloadwarmachine-ng-1c4f034b5d66f422f6891d318ebf95abd82a5c53.tar.gz
warmachine-ng-1c4f034b5d66f422f6891d318ebf95abd82a5c53.zip
add debug commands, schedule for the closest weekday at the provided time
Diffstat (limited to 'warmachine/addons/standup.py')
-rw-r--r--warmachine/addons/standup.py71
1 files changed, 53 insertions, 18 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