Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions cogs/alarm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from discord.ext import commands
import asyncio
import datetime
import time

ALLOWED_TIME_FORMAT = "%H:%M"

class alarm(commands.Cog):

class alarm(commands.Cog):
def __init__(self, client):
self.client = client

Expand All @@ -13,10 +18,27 @@ async def alarm(self, ctx, time):
time ([type]): time in 24 hour format
"""
# Take user input (time in 24-hour format), for example 23:00
# Check if it is a valid 24-hour format, and return an apppropriate message
# Parse the user input using time.split(":")
# Remind the user as soon as it's time
pass
# Check if it is a valid 24-hour format, and return an apppropriate
# message

try:
alarm_time = datetime.datetime.strptime(time, ALLOWED_TIME_FORMAT)
except ValueError:
await ctx.send(
ctx.message.author.mention
+ " Please input the alarm time in 24-hour format (e.g. 14:00)"
)

while True:
now = datetime.now()
if now >= alarm_time:
await ctx.send(
ctx.message.author.mention
+ f" Ding dong, it is {alarm_time}, your alarm went off!"
)
break
await asyncio.sleep(1)


def setup(client):
client.add_cog(alarm(client))
client.add_cog(alarm(client))