From e7c8df45f25ceb9b5cf514897ceef424b5f46eec Mon Sep 17 00:00:00 2001 From: dnns01 <mail@dnns01.de> Date: Wed, 9 Dec 2020 19:23:35 +0100 Subject: [PATCH] fix $11e - add random motivation texts at random channels (from a certain list of channels). Random texts can appear every 1 to 24 hours --- text_commands_cog.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/text_commands_cog.py b/text_commands_cog.py index 9167eb5..d6f8051 100644 --- a/text_commands_cog.py +++ b/text_commands_cog.py @@ -3,10 +3,12 @@ import os import random import discord -from discord.ext import commands +from discord.ext import commands, tasks import utils +motivation_channels = [566329830682132502, 666937772879249409, 693194667075960875] + class TextCommandsCog(commands.Cog): def __init__(self, bot): @@ -14,6 +16,7 @@ class TextCommandsCog(commands.Cog): self.text_commands = {} self.cmd_file = os.getenv("DISCORD_TEXT_COMMANDS_FILE") self.load_text_commands() + self.motivation_loop.start() def load_text_commands(self): """ Loads all appointments from APPOINTMENTS_FILE """ @@ -153,3 +156,13 @@ class TextCommandsCog(commands.Cog): message = await channel.fetch_message(payload.message_id) if len(message.embeds) > 0 and message.embeds[0].title == "Neuer Motivations Text": await self.motivation_approved(message) + + @tasks.loop(hours=1 + (random.random() * 24)) + async def motivation_loop(self): + channel_id = random.choice(motivation_channels) + channel = await self.bot.fetch_channel(channel_id) + texts = self.text_commands.get("!motivation") + + await channel.send(random.choice(texts)) + + self.motivation_loop.change_interval(hours=1 + (random.random() * 12)) -- GitLab