Files
WorldCraft_Discord_Bot/functions/timer.py
2020-11-08 01:16:47 +01:00

27 lines
749 B
Python

import asyncio
class Timer():
def __init__(self, minutes, seconds):
self.minutes = minutes
self.seconds = seconds
self.ended = True
def start(self):
self.ended = False
self.timer_task = asyncio.ensure_future(self.update())
def stop(self):
self.timer_task.cancel()
self.endend = True
async def update(self):
while self.ended == False:
await asyncio.sleep(1)
if (self.minutes > 0 and self.seconds == 0):
self.minutes -= 1
self.seconds = 59
elif (self.seconds > 0):
self.seconds -= 1
if (self.minutes == 0 and self.seconds == 0):
self.ended = True