Permalink
Browse files

Toggle officehours feature with boolean

Set in config.json, and is is off by default.

This also sets the default office hours to be 9 to 5pm.
  • Loading branch information...
1 parent e849a71 commit b18d80ce6cda3f8e3b8cdda31fa438b97ea197e8 slee committed Oct 6, 2015
Showing with 21 additions and 8 deletions.
  1. +3 −2 default.json
  2. +18 −6 slackbotExercise.py
View
@@ -4,8 +4,9 @@
"channelId": "channelIdHere",
"officeHours": {
- "begin": 10,
- "end": 16
+ "on": false,
+ "begin": 9,
+ "end": 17
},
"debug": false,
View
@@ -62,6 +62,7 @@ def setConfiguration(self):
self.group_callout_chance = settings["callouts"]["groupCalloutChance"]
self.channel_id = settings["channelId"]
self.exercises = settings["exercises"]
+ self.office_hours_on = settings["officeHours"]["on"]
self.office_hours_begin = settings["officeHours"]["begin"]
self.office_hours_end = settings["officeHours"]["end"]
@@ -191,15 +192,15 @@ def assignExercise(bot, exercise):
exercise_reps = random.randrange(exercise["minReps"], exercise["maxReps"]+1)
winner_announcement = str(exercise_reps) + " " + str(exercise["units"]) + " " + exercise["name"] + " RIGHT NOW "
-
+
# EVERYBODY
if random.random() < bot.group_callout_chance:
winner_announcement += "@channel!"
for user_id in bot.user_cache:
user = bot.user_cache[user_id]
user.addExercise(exercise, exercise_reps)
-
+
logExercise(bot,"@channel",exercise["name"],exercise_reps,exercise["units"])
else:
@@ -263,12 +264,20 @@ def saveUsers(bot):
pickle.dump(bot.user_cache,f)
def isOfficeHours(bot):
+ if not bot.office_hours_on:
+ if bot.debug:
+ print "not office hours"
+ return True
now = datetime.datetime.now()
now_time = now.time()
if now_time >= datetime.time(bot.office_hours_begin) and now_time <= datetime.time(bot.office_hours_end):
+ if bot.debug:
+ print "in office hours"
return True
else:
- return False;
+ if bot.debug:
+ print "out office hours"
+ return False
def main():
bot = Bot()
@@ -286,9 +295,12 @@ def main():
assignExercise(bot, exercise)
else:
- # Sleep and check again for office hours
- time.sleep(5*60) # Sleep 5 minutes
-
+ # Sleep the script and check again for office hours
+ if not bot.debug:
+ time.sleep(5*60) # Sleep 5 minutes
+ else:
+ # If debugging, check again in 5 seconds
+ time.sleep(5)
except KeyboardInterrupt:
saveUsers(bot)

0 comments on commit b18d80c

Please sign in to comment.