diff options
Diffstat (limited to 'cogs')
| -rw-r--r-- | cogs/music/play.py | 1 | ||||
| -rw-r--r-- | cogs/tts.py | 5 | ||||
| -rw-r--r-- | cogs/vclogs.py | 3 | ||||
| -rw-r--r-- | cogs/web.py | 9 |
4 files changed, 17 insertions, 1 deletions
diff --git a/cogs/music/play.py b/cogs/music/play.py index 5664d31..e75c91f 100644 --- a/cogs/music/play.py +++ b/cogs/music/play.py | |||
| @@ -62,6 +62,7 @@ class Play(commands.Cog): | |||
| 62 | logger.info(f"Playing: {title}") | 62 | logger.info(f"Playing: {title}") |
| 63 | except Exception as e: | 63 | except Exception as e: |
| 64 | await ctx.followup.send(f"Wystąpił błąd podczas odtwarzania: {str(e)}") | 64 | await ctx.followup.send(f"Wystąpił błąd podczas odtwarzania: {str(e)}") |
| 65 | logger.error(f"Error playing audio: {e}", exc_info=True) | ||
| 65 | 66 | ||
| 66 | @commands.slash_command(name="grajcuj", description="grajcuj melodyje") | 67 | @commands.slash_command(name="grajcuj", description="grajcuj melodyje") |
| 67 | async def play(self, ctx, *, search: str): | 68 | async def play(self, ctx, *, search: str): |
diff --git a/cogs/tts.py b/cogs/tts.py index dceb26c..8076a2d 100644 --- a/cogs/tts.py +++ b/cogs/tts.py | |||
| @@ -22,12 +22,13 @@ class TTS(commands.Cog): | |||
| 22 | tts.save('tts.mp3') | 22 | tts.save('tts.mp3') |
| 23 | if output == "file": | 23 | if output == "file": |
| 24 | await ctx.respond(file=discord.File('tts.mp3')) | 24 | await ctx.respond(file=discord.File('tts.mp3')) |
| 25 | logger.info("TTS file sent") | ||
| 25 | os.remove('tts.mp3') | 26 | os.remove('tts.mp3') |
| 26 | elif output == "vc": | 27 | elif output == "vc": |
| 27 | # Check if the user is in a voice channel | 28 | # Check if the user is in a voice channel |
| 28 | if not (ctx.author.voice and ctx.author.voice.channel): | 29 | if not (ctx.author.voice and ctx.author.voice.channel): |
| 29 | await ctx.respond("Musisz być na kanale głosowym, aby odtworzyć TTS!", ephemeral=True) | 30 | await ctx.respond("Musisz być na kanale głosowym, aby odtworzyć TTS!", ephemeral=True) |
| 30 | logger.info("tts: User is not in a voice channel") | 31 | logger.info("User is not in a voice channel") |
| 31 | os.remove('tts.mp3') | 32 | os.remove('tts.mp3') |
| 32 | return | 33 | return |
| 33 | channel = ctx.author.voice.channel | 34 | channel = ctx.author.voice.channel |
| @@ -40,6 +41,7 @@ class TTS(commands.Cog): | |||
| 40 | # Play the TTS audio | 41 | # Play the TTS audio |
| 41 | if not voice_client.is_playing(): | 42 | if not voice_client.is_playing(): |
| 42 | audio_source = discord.FFmpegPCMAudio('tts.mp3', options='-filter:a "volume=6"') | 43 | audio_source = discord.FFmpegPCMAudio('tts.mp3', options='-filter:a "volume=6"') |
| 44 | logger.info("TTS audio played") | ||
| 43 | voice_client.play(audio_source) | 45 | voice_client.play(audio_source) |
| 44 | # Wait for playback to finish | 46 | # Wait for playback to finish |
| 45 | while voice_client.is_playing(): | 47 | while voice_client.is_playing(): |
| @@ -47,6 +49,7 @@ class TTS(commands.Cog): | |||
| 47 | os.remove('tts.mp3') | 49 | os.remove('tts.mp3') |
| 48 | else: | 50 | else: |
| 49 | await ctx.respond("Nieznany sposób odtwarzania.", ephemeral=True) | 51 | await ctx.respond("Nieznany sposób odtwarzania.", ephemeral=True) |
| 52 | logger.info("Unknown playback method") | ||
| 50 | os.remove('tts.mp3') | 53 | os.remove('tts.mp3') |
| 51 | 54 | ||
| 52 | 55 | ||
diff --git a/cogs/vclogs.py b/cogs/vclogs.py index ed0737b..a9672ac 100644 --- a/cogs/vclogs.py +++ b/cogs/vclogs.py | |||
| @@ -66,6 +66,7 @@ class VcLogs(commands.Cog): | |||
| 66 | else: | 66 | else: |
| 67 | with open('settings.json', 'w') as f: | 67 | with open('settings.json', 'w') as f: |
| 68 | json.dump({'volume': '5'}, f, indent=4) | 68 | json.dump({'volume': '5'}, f, indent=4) |
| 69 | logger.info("settings.json created") | ||
| 69 | 70 | ||
| 70 | audio_source = discord.FFmpegPCMAudio('temp_tts.mp3', options=f'-filter:a "volume={volume}"') | 71 | audio_source = discord.FFmpegPCMAudio('temp_tts.mp3', options=f'-filter:a "volume={volume}"') |
| 71 | voice_client.play(audio_source) | 72 | voice_client.play(audio_source) |
| @@ -81,9 +82,11 @@ class VcLogs(commands.Cog): | |||
| 81 | if not os.path.exists('settings.json'): | 82 | if not os.path.exists('settings.json'): |
| 82 | with open('settings.json', 'w') as f: | 83 | with open('settings.json', 'w') as f: |
| 83 | json.dump({'volume': '5'}, f, indent=4) | 84 | json.dump({'volume': '5'}, f, indent=4) |
| 85 | logger.info("settings.json created") | ||
| 84 | with open('settings.json', 'w') as f: | 86 | with open('settings.json', 'w') as f: |
| 85 | json.dump({"volume": volume}, f, indent=4) | 87 | json.dump({"volume": volume}, f, indent=4) |
| 86 | await ctx.followup.send(f"Volume has been set to: {volume}") | 88 | await ctx.followup.send(f"Volume has been set to: {volume}") |
| 89 | logger.info(f"Volume changed to: {volume}") | ||
| 87 | except Exception as e: | 90 | except Exception as e: |
| 88 | await ctx.respond(e, ephemeral=True) | 91 | await ctx.respond(e, ephemeral=True) |
| 89 | logger.error(f"Error in volume command: {e}", exc_info=True) | 92 | logger.error(f"Error in volume command: {e}", exc_info=True) |
diff --git a/cogs/web.py b/cogs/web.py index bea684b..9431e84 100644 --- a/cogs/web.py +++ b/cogs/web.py | |||
| @@ -5,6 +5,9 @@ import requests | |||
| 5 | from bs4 import BeautifulSoup | 5 | from bs4 import BeautifulSoup |
| 6 | import urllib.parse | 6 | import urllib.parse |
| 7 | import pytube | 7 | import pytube |
| 8 | import logging | ||
| 9 | |||
| 10 | logger = logging.getLogger(__name__) | ||
| 8 | 11 | ||
| 9 | class Web(commands.Cog): | 12 | class Web(commands.Cog): |
| 10 | def __init__(self, bot): | 13 | def __init__(self, bot): |
| @@ -24,6 +27,8 @@ class Web(commands.Cog): | |||
| 24 | url = f"https://duckduckgo.com/html/?q={query}" | 27 | url = f"https://duckduckgo.com/html/?q={query}" |
| 25 | response = requests.get(url, headers=headers) | 28 | response = requests.get(url, headers=headers) |
| 26 | 29 | ||
| 30 | logger.info(f"Query: {query}") | ||
| 31 | |||
| 27 | if response.status_code == 200: | 32 | if response.status_code == 200: |
| 28 | soup = BeautifulSoup(response.text, 'html.parser') | 33 | soup = BeautifulSoup(response.text, 'html.parser') |
| 29 | links = soup.find_all('a', class_='result__a') | 34 | links = soup.find_all('a', class_='result__a') |
| @@ -33,6 +38,7 @@ class Web(commands.Cog): | |||
| 33 | for i, link in enumerate(links[:5], start=1): | 38 | for i, link in enumerate(links[:5], start=1): |
| 34 | title = link.text | 39 | title = link.text |
| 35 | if link.get('href').startswith('https://www.youtube.com/'): | 40 | if link.get('href').startswith('https://www.youtube.com/'): |
| 41 | logger.info("youtube link") | ||
| 36 | try: | 42 | try: |
| 37 | parsed_url = urllib.parse.urlparse(link.get('href')) | 43 | parsed_url = urllib.parse.urlparse(link.get('href')) |
| 38 | video_id = urllib.parse.parse_qs(parsed_url.query).get('v', [None])[0] | 44 | video_id = urllib.parse.parse_qs(parsed_url.query).get('v', [None])[0] |
| @@ -48,10 +54,13 @@ class Web(commands.Cog): | |||
| 48 | button.callback = button_callback | 54 | button.callback = button_callback |
| 49 | view.add_item(button) | 55 | view.add_item(button) |
| 50 | await ctx.respond(embed=embed, view=view, ephemeral=True) | 56 | await ctx.respond(embed=embed, view=view, ephemeral=True) |
| 57 | logger.info("Search results sent") | ||
| 51 | else: | 58 | else: |
| 52 | await ctx.respond(content="No results found.", ephemeral=True) | 59 | await ctx.respond(content="No results found.", ephemeral=True) |
| 60 | logger.warning("No results found") | ||
| 53 | else: | 61 | else: |
| 54 | await ctx.respond(content=f"Error: {response.status_code}", ephemeral=True) | 62 | await ctx.respond(content=f"Error: {response.status_code}", ephemeral=True) |
| 63 | logger.error(f"Error: {response.status_code}") | ||
| 55 | 64 | ||
| 56 | def setup(bot): | 65 | def setup(bot): |
| 57 | bot.add_cog(Web(bot)) | 66 | bot.add_cog(Web(bot)) |
