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"
|
EXAMPLE_COMMAND = "do"
|
||||||
|
|
||||||
# instantiate Slack & Twilio clients
|
# instantiate Slack & Twilio clients
|
||||||
slack_client = SlackClient("xoxb-146731148148-cOhyqUViCY4wI2gWYMcoOkpW")
|
slack_client = SlackClient("xoxb-146731148148-L3NkZn2dI5N645QUU34sl2mi")
|
||||||
|
|
||||||
def handle_command(command, channel):
|
def handle_command(command, channel):
|
||||||
global targetDate
|
global targetDate
|
||||||
@ -25,13 +25,22 @@ def handle_command(command, channel):
|
|||||||
response = "You have *" + str((targetDate.date() - dt.now().date()).days) + "* days left."
|
response = "You have *" + str((targetDate.date() - dt.now().date()).days) + "* days left."
|
||||||
|
|
||||||
elif command.startswith("time left in hell"):
|
elif command.startswith("time left in hell"):
|
||||||
timeDelta = str(targetDate - dt.now())
|
timeDelta = str(targetDate - dt.now()).replace(":0",":")
|
||||||
days, other = timeDelta.split(",")
|
if "," not in timeDelta:
|
||||||
|
other = " "+timeDelta
|
||||||
|
days = "0 days"
|
||||||
|
else:
|
||||||
|
days, other = timeDelta.split(",")
|
||||||
hours, minutes, seconds = other.split(":")
|
hours, minutes, seconds = other.split(":")
|
||||||
response = "Only " + days + ","+hours+" hours, "+minutes+" minutes, and "+seconds.split(".")[0]+" seconds left!"
|
response = "Only " + days + ","+hours+" hours, "+minutes+" minutes, and "+seconds.split(".")[0]+" seconds left!"
|
||||||
|
|
||||||
elif command.startswith("summary"):
|
elif command.startswith("summary"):
|
||||||
timeDelta = str(targetDate - dt.now())
|
timeDelta = str(targetDate - dt.now()).replace(":0",":")
|
||||||
days, other = timeDelta.split(",")
|
if "," not in timeDelta:
|
||||||
|
other = " "+timeDelta
|
||||||
|
days = "0 days"
|
||||||
|
else:
|
||||||
|
days, other = timeDelta.split(",")
|
||||||
hours, minutes, seconds = other.split(":")
|
hours, minutes, seconds = other.split(":")
|
||||||
approx = [
|
approx = [
|
||||||
str((targetDate.date() - dt.now().date()).days) + " days, ",
|
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.")
|
approx.append(str(int(minutes)+int(approx[2].replace(" minutes, or ",""))*60)+" seconds.")
|
||||||
|
|
||||||
first = "The current target date is *" + targetDate.strftime("%B %d, %Y") + "*!"
|
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);
|
third = "Other representations are: " + "".join(approx);
|
||||||
response = first+"\n"+second+"\n"+third
|
response = first+"\n"+second+"\n"+third
|
||||||
|
|
||||||
elif command.startswith("set new time "):
|
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:
|
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()):
|
if(newDate < dt.now()):
|
||||||
response = "Please enter in a date after today!"
|
response = "Please enter in a date after today!"
|
||||||
else:
|
else:
|
||||||
targetDate = newDate
|
targetDate = newDate
|
||||||
|
print(targetDate)
|
||||||
f = open('date.dat', 'wb')
|
f = open('date.dat', 'wb')
|
||||||
pickle.dump(targetDate,f)
|
pickle.dump(targetDate,f)
|
||||||
f.close()
|
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:
|
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"):
|
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"):
|
elif command.startswith("flip a coin"):
|
||||||
coin = ["Heads!", "Tails!"]
|
coin = ["Heads!", "Tails!"]
|
||||||
response = coin[randint(0,1)]
|
response = coin[randint(0,1)]
|
||||||
@ -69,7 +86,7 @@ def handle_command(command, channel):
|
|||||||
"Summary: Gives a summary of all information.",
|
"Summary: Gives a summary of all information.",
|
||||||
"Days left in hell: Gives days left to date.",
|
"Days left in hell: Gives days left to date.",
|
||||||
"Time left in hell: Gives countdown 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.",
|
"Target date: Gives current target date.",
|
||||||
"Flip a coin: Gives heads or tails."
|
"Flip a coin: Gives heads or tails."
|
||||||
]
|
]
|
||||||
@ -86,7 +103,6 @@ def parse_slack_output(slack_rtm_output):
|
|||||||
for output in output_list:
|
for output in output_list:
|
||||||
if output and 'text' in output and AT_BOT in output['text']:
|
if output and 'text' in output and AT_BOT in output['text']:
|
||||||
# return text after the @ mention, whitespace removed
|
# return text after the @ mention, whitespace removed
|
||||||
print (output)
|
|
||||||
return output['text'].split(AT_BOT)[1].strip().lower(), \
|
return output['text'].split(AT_BOT)[1].strip().lower(), \
|
||||||
output['channel']
|
output['channel']
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user