WIP: Add TTS cog #18

Draft
cswimr wants to merge 14 commits from tts into main
3 changed files with 76 additions and 0 deletions
Showing only changes of commit a2f61d697f - Show all commits

5
tts/__init__.py Normal file
View file

@ -0,0 +1,5 @@
from .tts import TTS
async def setup(bot):
await bot.add_cog(TTS(bot))

18
tts/info.json Normal file
View file

@ -0,0 +1,18 @@
{
"author" : ["SeaswimmerTheFsh (seasw.)"],
"install_msg" : "Thank you for installing TTS!\nPlease read the [documentation](https://seacogs.coastalcommits.com/tts) for more information.\nYou can find the source code of this cog [here](https://coastalcommits.com/SeaswimmerTheFsh/SeaCogs).",
"name" : "TTS",
"short" : "Text to Speech through Pylav",
"description" : "Text to Speech through Pylav",
"end_user_data_statement" : "This cog does not store end user data.",
"hidden": false,
"disabled": false,
"min_bot_version": "3.5.0",
"min_python_version": [3, 10, 0],
"tags": [
"pylav",
"audio",
"tts"
],
"required_cogs": {"audio" : "https://github.com/PyLav/Red-Cogs"}
}

53
tts/tts.py Normal file
View file

@ -0,0 +1,53 @@
# _____ _
# / ____| (_)
# | (___ ___ __ _ _____ ___ _ __ ___ _ __ ___ ___ _ __
# \___ \ / _ \/ _` / __\ \ /\ / / | '_ ` _ \| '_ ` _ \ / _ \ '__|
# ____) | __/ (_| \__ \\ V V /| | | | | | | | | | | | __/ |
# |_____/ \___|\__,_|___/ \_/\_/ |_|_| |_| |_|_| |_| |_|\___|_|
import logging
from discord import Message
from discord.ext import tasks
from redbot.core import Config, commands
from redbot.core.bot import Red
class TTS(commands.Cog):
"""Text to Speech through Pylav"""
def __init__(self, bot: Red):
self.bot = bot
self.logger = logging.getLogger("red.sea.tts")
self.config = Config.get_conf(self, 69737245070283, force_registration=True)
self.config.register_global(
use_google_tts = False,
)
self.config.register_guild(
enabled_channels = [],
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:
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):
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():
#TODO - add PyLav integration
return