WIP: Add TTS cog #18

Draft
cswimr wants to merge 14 commits from tts into main
Showing only changes of commit bcca864d02 - Show all commits

View file

@ -8,7 +8,6 @@
import logging import logging
from discord import Message from discord import Message
from discord.ext import tasks
from redbot.core import Config, commands from redbot.core import Config, commands
from redbot.core.bot import Red from redbot.core.bot import Red
@ -28,19 +27,9 @@ class TTS(commands.Cog):
announce = False, announce = False,
voice_channels = True 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): async def on_message(self, message: Message):
await self.bot.wait_until_red_ready()
if message.author.bot: if message.author.bot:
return return
if message.guild is None: if message.guild is None:
@ -50,6 +39,11 @@ class TTS(commands.Cog):
if any(message.content.startswith(prefix) for prefix in valid_prefixes): if any(message.content.startswith(prefix) for prefix in valid_prefixes):
return return
if message.channel.id in await self.config.guild(message.guild).enabled_channels(): 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 #TODO - add PyLav integration
return return