feat(tts): made pylav check happen on message invocation instead of on cog load
All checks were successful
Actions / Lint Code (Ruff) (pull_request) Successful in 8s
Actions / Build Documentation (MkDocs) (pull_request) Successful in 15s

This commit is contained in:
Seaswimmer 2024-02-19 18:51:59 -05:00
parent e5d466cf8b
commit bcca864d02
Signed by: cswimr
GPG key ID: B8953EC01E5C4063

View file

@ -8,7 +8,6 @@
import logging
from discord import Message
from discord.ext import tasks
from redbot.core import Config, commands
from redbot.core.bot import Red
@ -28,19 +27,9 @@ class TTS(commands.Cog):
announce = False,
voice_channels = True
)
self.check_pylav.start()
@tasks.loop(seconds=5)
async def check_pylav(self):
await self.bot.wait_until_red_ready()
pylav = self.bot.get_cog("PyLavPlayer")
self.check_pylav.stop()
if pylav is None:
await self.bot.send_to_owners("You need to install PyLav to use the TTS cog.\nThe cog has been automatically unloaded.\nSee https://github.com/PyLav/Red-Cogs")
await self.bot.remove_cog("TTS")
raise RuntimeError("You need to install PyLav to use this cog. See https://github.com/PyLav/Red-Cogs")
async def on_message(self, message: Message):
await self.bot.wait_until_red_ready()
if message.author.bot:
return
if message.guild is None:
@ -50,6 +39,11 @@ class TTS(commands.Cog):
if any(message.content.startswith(prefix) for prefix in valid_prefixes):
return
if message.channel.id in await self.config.guild(message.guild).enabled_channels():
pylav = self.bot.get_cog("PyLavPlayer")
if pylav is None:
self.logger.error("PyLav is not loaded, so TTS is not available.")
await message.reply("PyLav is not loaded, so TTS is not available.\nPlease report this to the bot owner.\nIf you are the bot owner, see [https://github.com/PyLav/Red-Cogs](PyLav/RedCogs) for more information.")
return
#TODO - add PyLav integration
return