forked from cswimr/SeaCogs
feat(tts): made pylav check happen on message invocation instead of on cog load
This commit is contained in:
parent
e5d466cf8b
commit
bcca864d02
1 changed files with 6 additions and 12 deletions
18
tts/tts.py
18
tts/tts.py
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue