Time functionality
This commit is contained in:
parent
e09cf4cbfe
commit
8a7ed0b106
Binary file not shown.
@ -15,7 +15,7 @@ AT_BOT = "<@" + BOT_ID + ">"
|
||||
EXAMPLE_COMMAND = "do"
|
||||
|
||||
# instantiate Slack & Twilio clients
|
||||
slack_client = SlackClient("xoxb-146731148148-cOhyqUViCY4wI2gWYMcoOkpW")
|
||||
slack_client = SlackClient("xoxb-146731148148-L3NkZn2dI5N645QUU34sl2mi")
|
||||
|
||||
def handle_command(command, channel):
|
||||
global targetDate
|
||||
@ -25,13 +25,22 @@ def handle_command(command, channel):
|
||||
response = "You have *" + str((targetDate.date() - dt.now().date()).days) + "* days left."
|
||||
|
||||
elif command.startswith("time left in hell"):
|
||||
timeDelta = str(targetDate - dt.now())
|
||||
days, other = timeDelta.split(",")
|
||||
timeDelta = str(targetDate - dt.now()).replace(":0",":")
|
||||
if "," not in timeDelta:
|
||||
other = " "+timeDelta
|
||||
days = "0 days"
|
||||
else:
|
||||
days, other = timeDelta.split(",")
|
||||
hours, minutes, seconds = other.split(":")
|
||||
response = "Only " + days + ","+hours+" hours, "+minutes+" minutes, and "+seconds.split(".")[0]+" seconds left!"
|
||||
|
||||
elif command.startswith("summary"):
|
||||
timeDelta = str(targetDate - dt.now())
|
||||
days, other = timeDelta.split(",")
|
||||
timeDelta = str(targetDate - dt.now()).replace(":0",":")
|
||||
if "," not in timeDelta:
|
||||
other = " "+timeDelta
|
||||
days = "0 days"
|
||||
else:
|
||||
days, other = timeDelta.split(",")
|
||||
hours, minutes, seconds = other.split(":")
|
||||
approx = [
|
||||
str((targetDate.date() - dt.now().date()).days) + " days, ",
|
||||
@ -41,26 +50,34 @@ def handle_command(command, channel):
|
||||
approx.append(str(int(minutes)+int(approx[2].replace(" minutes, or ",""))*60)+" seconds.")
|
||||
|
||||
first = "The current target date is *" + targetDate.strftime("%B %d, %Y") + "*!"
|
||||
second = "There are " + days + ","+hours+" hours, "+minutes+" minutes, and "+seconds.split(".")[0]+" seconds left!"
|
||||
second = "There are " + days + ","+hours.lstrip("0")+" hours, "+minutes.lstrip("0")+" minutes, and "+seconds.split(".")[0].lstrip("0")+" seconds left!"
|
||||
third = "Other representations are: " + "".join(approx);
|
||||
response = first+"\n"+second+"\n"+third
|
||||
|
||||
elif command.startswith("set new time "):
|
||||
newDate = command.lower().replace("set new time ","").split(" ")
|
||||
newDate = command.replace("set new time ","").split(" ")
|
||||
time = list(map(int, newDate[3].split(":")))
|
||||
if newDate[4] == "pm":
|
||||
if time[0] != 12:
|
||||
time[0] += 12
|
||||
elif newDate[4] == "am" and time[0] == 12:
|
||||
time[0] -= 12
|
||||
try:
|
||||
newDate = dt(int(newDate[2]),int(newDate[0]),int(newDate[1]))
|
||||
newDate = dt(int(newDate[2]),int(newDate[0]),int(newDate[1]),time[0],time[1])
|
||||
if(newDate < dt.now()):
|
||||
response = "Please enter in a date after today!"
|
||||
else:
|
||||
targetDate = newDate
|
||||
print(targetDate)
|
||||
f = open('date.dat', 'wb')
|
||||
pickle.dump(targetDate,f)
|
||||
f.close()
|
||||
response = "Ok! Your new date is *" + targetDate.strftime("%B %d, %Y") + "*!"
|
||||
response = "Ok! Your new date is *" + targetDate.strftime("%B %d, %Y %I:%M %p").replace(" 0"," ") + "*!"
|
||||
except ValueError:
|
||||
response = "That's an invalid date! The format is: *Day Month Year*"
|
||||
response = "That's an invalid date! The format is: *Day Month Year Hour:Minute AM/PM*"
|
||||
|
||||
elif command.startswith("target date"):
|
||||
response = "The current target date is *" + targetDate.strftime("%B %d, %Y") + "*!"
|
||||
response = "The current target date is *" + targetDate.strftime("%B %d, %Y %I:%M %p").replace(" 0"," ") + "*!"
|
||||
elif command.startswith("flip a coin"):
|
||||
coin = ["Heads!", "Tails!"]
|
||||
response = coin[randint(0,1)]
|
||||
@ -69,7 +86,7 @@ def handle_command(command, channel):
|
||||
"Summary: Gives a summary of all information.",
|
||||
"Days left in hell: Gives days left to date.",
|
||||
"Time left in hell: Gives countdown left to date.",
|
||||
"Set new time [Day Month Year]: Sets new target date.",
|
||||
"Set new time [Day Month Year Hour:Minute AM/PM]: Sets new target date.",
|
||||
"Target date: Gives current target date.",
|
||||
"Flip a coin: Gives heads or tails."
|
||||
]
|
||||
@ -86,7 +103,6 @@ def parse_slack_output(slack_rtm_output):
|
||||
for output in output_list:
|
||||
if output and 'text' in output and AT_BOT in output['text']:
|
||||
# return text after the @ mention, whitespace removed
|
||||
print (output)
|
||||
return output['text'].split(AT_BOT)[1].strip().lower(), \
|
||||
output['channel']
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user