forked from blizzthewolf/SeaCogs
57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
# _____ _
|
|
# / ____| (_)
|
|
# | (___ ___ __ _ _____ ___ _ __ ___ _ __ ___ ___ _ __
|
|
# \___ \ / _ \/ _` / __\ \ /\ / / | '_ ` _ \| '_ ` _ \ / _ \ '__|
|
|
# ____) | __/ (_| \__ \\ V V /| | | | | | | | | | | | __/ |
|
|
# |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_|
|
|
|
|
import logging
|
|
|
|
from discord import Message
|
|
from redbot.core import commands
|
|
from redbot.core.bot import Red
|
|
|
|
from tts.config import config
|
|
from tts.menu import Menu, embed
|
|
|
|
|
|
class TTS(commands.Cog):
|
|
"""Text to Speech through Pylav"""
|
|
|
|
def __init__(self, bot: Red):
|
|
self.bot = bot
|
|
self.logger = logging.getLogger("red.sea.tts")
|
|
|
|
async def on_message(self, message: Message):
|
|
await self.bot.wait_until_red_ready()
|
|
if message.author.bot:
|
|
return
|
|
if message.guild is None:
|
|
return
|
|
valid_prefixes = await self.bot.get_valid_prefixes(message.guild)
|
|
valid_prefixes.append("\\")
|
|
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
|
|
|
|
@commands.group(name="tts")
|
|
@commands.admin_or_permissions(manage_guild=True)
|
|
async def tts(self, ctx: commands.Context):
|
|
"""Text to Speech settings"""
|
|
await ctx.send(embed=embed, view=Menu(ctx))
|
|
|
|
@tts.command(name="google")
|
|
@commands.is_owner()
|
|
async def tts_google(self, ctx: commands.Context, enable: bool = None):
|
|
"""Enable or disable Google Cloud TTS"""
|
|
if enable is None:
|
|
enable = not await config.use_google_tts()
|
|
await config.use_google_tts.set(enable)
|
|
await ctx.send(f"Google TTS has been {'enabled' if enable else 'disabled'}.")
|