From ca49a9b2911f5775d9713ca14422247597c4e261 Mon Sep 17 00:00:00 2001 From: dnns01 <git@dnns01.de> Date: Tue, 5 Apr 2022 18:23:06 +0200 Subject: [PATCH] Add countdown timer --- .idea/misc.xml | 2 +- .idea/strolchibot.iml | 2 +- twitchbot/countdown.py | 23 +++++++++++++++++++++++ twitchbot/strolchibot.py | 3 ++- 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 twitchbot/countdown.py diff --git a/.idea/misc.xml b/.idea/misc.xml index 739588e..acb62c5 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ <component name="JavaScriptSettings"> <option name="languageLevel" value="ES6" /> </component> - <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (strolchibot)" project-jdk-type="Python SDK" /> + <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (strolchibot)" project-jdk-type="Python SDK" /> </project> \ No newline at end of file diff --git a/.idea/strolchibot.iml b/.idea/strolchibot.iml index a69cde9..e116631 100644 --- a/.idea/strolchibot.iml +++ b/.idea/strolchibot.iml @@ -18,7 +18,7 @@ <sourceFolder url="file://$MODULE_DIR$/strolchguru" isTestSource="false" /> <excludeFolder url="file://$MODULE_DIR$/venv" /> </content> - <orderEntry type="jdk" jdkName="Python 3.9 (strolchibot)" jdkType="Python SDK" /> + <orderEntry type="jdk" jdkName="Python 3.10 (strolchibot)" jdkType="Python SDK" /> <orderEntry type="sourceFolder" forTests="false" /> </component> <component name="TemplatesService"> diff --git a/twitchbot/countdown.py b/twitchbot/countdown.py new file mode 100644 index 0000000..52bae85 --- /dev/null +++ b/twitchbot/countdown.py @@ -0,0 +1,23 @@ +from asyncio import sleep +from datetime import datetime + +from twitchio.ext import commands, routines + + +class Countdown(commands.Cog): + def __init__(self, bot): + self.bot = bot + self.timer.start() + self.until = datetime(year=2022, month=4, day=5, hour=20) + + @routines.routine(minutes=1) + async def timer(self): + now = datetime.now() + diff = (self.until - now).seconds // 60 + 1 + + if diff > 0: + await self.bot.channel().send(str(diff)) + + @timer.before_routine + async def timer_before(self): + await sleep(60 - datetime.now().second) diff --git a/twitchbot/strolchibot.py b/twitchbot/strolchibot.py index 404e66f..299806e 100644 --- a/twitchbot/strolchibot.py +++ b/twitchbot/strolchibot.py @@ -9,7 +9,7 @@ from twitchio import Channel, Message from twitchio.ext import commands from twitchio.ext.commands import Context -import chat_commands, giveaway, klassenbuch, link_protection, spotify_cog, vote_cog +import chat_commands, giveaway, klassenbuch, link_protection, spotify_cog, vote_cog, countdown load_dotenv() @@ -34,6 +34,7 @@ class StrolchiBot(commands.Bot, ABC): self.add_cog(link_protection.LinkProtection(self)) self.add_cog(giveaway.Giveaway(self)) self.add_cog(chat_commands.Commands(self)) + self.add_cog(countdown.Countdown(self)) @staticmethod async def send_me(ctx, content): -- GitLab