diff options
| author | SamlonDev <stankiewiczgracjan2019@gmail.com> | 2025-06-14 18:54:02 +0200 |
|---|---|---|
| committer | SamlonDev <stankiewiczgracjan2019@gmail.com> | 2025-06-14 18:54:02 +0200 |
| commit | 791e75cb2beeca45a6edf52b65f7e299e03b5eaf (patch) | |
| tree | cfee93211b7f8ac1c985325aaf8d9399b7a357ca /cogs/tts.py | |
| parent | temp downloads the files instead (diff) | |
| download | senator-sperma-791e75cb2beeca45a6edf52b65f7e299e03b5eaf.tar.gz senator-sperma-791e75cb2beeca45a6edf52b65f7e299e03b5eaf.zip | |
code-style issues
Diffstat (limited to '')
| -rw-r--r-- | cogs/tts.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/cogs/tts.py b/cogs/tts.py index 41dc366..2481ab3 100644 --- a/cogs/tts.py +++ b/cogs/tts.py | |||
| @@ -1,8 +1,10 @@ | |||
| 1 | import datetime | ||
| 2 | import os | ||
| 3 | |||
| 1 | import discord | 4 | import discord |
| 2 | from discord.ext import commands | 5 | from discord.ext import commands |
| 3 | from gtts import gTTS | 6 | from gtts import gTTS |
| 4 | import os | 7 | |
| 5 | import datetime | ||
| 6 | 8 | ||
| 7 | class TTS(commands.Cog): | 9 | class TTS(commands.Cog): |
| 8 | def __init__(self, bot): | 10 | def __init__(self, bot): |
| @@ -10,22 +12,22 @@ class TTS(commands.Cog): | |||
| 10 | 12 | ||
| 11 | @commands.slash_command(name="tts", description="Generuje TTS dla danego tekstu") | 13 | @commands.slash_command(name="tts", description="Generuje TTS dla danego tekstu") |
| 12 | async def tts(self, ctx, | 14 | async def tts(self, ctx, |
| 13 | text: str = discord.Option(str, "Tekst do przeczytania", required=True), | 15 | text: str = discord.Option(str, "Tekst do przeczytania", required=True), |
| 14 | output: str = discord.Option(str, "Wybierz sposób odtwarzania", choices=["file", "vc"], required=True) | 16 | output: str = discord.Option(str, "Wybierz sposób odtwarzania", choices=["file", "vc"], required=True) |
| 15 | ): | 17 | ): |
| 16 | tts = gTTS(text=text, lang='pl') | 18 | tts = gTTS(text=text, lang='pl') |
| 17 | tts.save('tts.mp3') | 19 | tts.save('tts.mp3') |
| 18 | if output == "file": | 20 | if output == "file": |
| 19 | await ctx.respond(file=discord.File('tts.mp3')) | 21 | await ctx.respond(file=discord.File('tts.mp3')) |
| 20 | os.remove('tts.mp3') | 22 | os.remove('tts.mp3') |
| 21 | elif output == "vc": | 23 | elif output == "vc": |
| 22 | # Check if user is in a voice channel | 24 | # Check if the user is in a voice channel |
| 23 | if not (ctx.author.voice and ctx.author.voice.channel): | 25 | if not (ctx.author.voice and ctx.author.voice.channel): |
| 24 | await ctx.respond("Musisz być na kanale głosowym, aby odtworzyć TTS!", ephemeral=True) | 26 | await ctx.respond("Musisz być na kanale głosowym, aby odtworzyć TTS!", ephemeral=True) |
| 25 | os.remove('tts.mp3') | 27 | os.remove('tts.mp3') |
| 26 | return | 28 | return |
| 27 | channel = ctx.author.voice.channel | 29 | channel = ctx.author.voice.channel |
| 28 | # Connect to voice channel if not already connected | 30 | # Connect to the voice channel if not already connected |
| 29 | voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild) | 31 | voice_client = discord.utils.get(self.bot.voice_clients, guild=channel.guild) |
| 30 | if not voice_client or not voice_client.is_connected(): | 32 | if not voice_client or not voice_client.is_connected(): |
| 31 | voice_client = await channel.connect() | 33 | voice_client = await channel.connect() |
| @@ -43,5 +45,6 @@ class TTS(commands.Cog): | |||
| 43 | await ctx.respond("Nieznany sposób odtwarzania.", ephemeral=True) | 45 | await ctx.respond("Nieznany sposób odtwarzania.", ephemeral=True) |
| 44 | os.remove('tts.mp3') | 46 | os.remove('tts.mp3') |
| 45 | 47 | ||
| 48 | |||
| 46 | def setup(bot): | 49 | def setup(bot): |
| 47 | bot.add_cog(TTS(bot)) \ No newline at end of file | 50 | bot.add_cog(TTS(bot)) |
