minya_hotomoe/modules/Timer.py
2023-09-08 09:49:37 +09:00

31 lines
1.2 KiB
Python

import re
import asyncio
from module_interface import ModuleInterface
class Timer(ModuleInterface):
def __init__(self):
super().__init__()
self.name = "Timer"
self.regex_pattern = r"((.|\n)*)(타이머\s.*(맞춰줘|설정해줘))|.*(뒤에\s*알려줘)"
print("[Timer] Settable timer module, Timer V1 loaded.")
async def execute_module(self, ctx):
print(f"[Timer] Got Timer Related Message : {ctx.content}")
text = ctx.content
seconds_query = re.search(r'([0-9]+)초', text)
minutes_query = re.search(r'([0-9]+)분', text)
hours_query = re.search(r'([0-9]+)(시간)', text)
seconds = int(seconds_query.group(1)) if seconds_query else 0
minutes = int(minutes_query.group(1)) if minutes_query else 0
hours = int(hours_query.group(1)) if hours_query else 0
if ((seconds + minutes + hours) == 0):
await ctx.api.action.reply("올바른 값이 아니에요...")
time = (seconds) + (60 * minutes) + (60 * 60 * hours)
await ctx.api.action.reply("타이머를 설정할게요!")
await asyncio.sleep(int(time))
await ctx.api.action.reply("시간이 다 되었어요!")