diff options
| author | salmonik <raisersoft@proton.me> | 2026-01-18 16:20:33 +0100 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-01-18 16:20:33 +0100 |
| commit | cb625506be95cec4d4a402119eec0c79699142b9 (patch) | |
| tree | 7d5a60f7754d6e753a9c4f853c2fbccd9222973b /cogs/jarvis.py | |
| parent | jarvis (diff) | |
| download | senator-sperma-cb625506be95cec4d4a402119eec0c79699142b9.tar.gz senator-sperma-cb625506be95cec4d4a402119eec0c79699142b9.zip | |
fix tmp dir being deleted before sending file
Diffstat (limited to 'cogs/jarvis.py')
| -rw-r--r-- | cogs/jarvis.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/cogs/jarvis.py b/cogs/jarvis.py index 0f4606b..21f71f6 100644 --- a/cogs/jarvis.py +++ b/cogs/jarvis.py | |||
| @@ -4,6 +4,7 @@ from discord.ext import commands | |||
| 4 | import requests | 4 | import requests |
| 5 | import json | 5 | import json |
| 6 | import logging | 6 | import logging |
| 7 | import os | ||
| 7 | 8 | ||
| 8 | from cogs.compression import Compression | 9 | from cogs.compression import Compression |
| 9 | from cogs.downloader import Downloader | 10 | from cogs.downloader import Downloader |
| @@ -78,7 +79,7 @@ class Jarvis(commands.Cog): | |||
| 78 | 79 | ||
| 79 | if action == "download": | 80 | if action == "download": |
| 80 | # Extract the URL from the message using regex | 81 | # Extract the URL from the message using regex |
| 81 | url_match = re.search(r'(https?://\S+)', message.content).group(0) | 82 | url_match = re.search(r'https://(?:[A-Za-z0-9-]+\.)*[A-Za-z0-9-]{1,63}\.[A-Za-z]{2,63}/\S*', message.content).group(0) |
| 82 | if not url_match: | 83 | if not url_match: |
| 83 | await channel.send("Nie znaleziono poprawnego linku w odpowiedzi.") | 84 | await channel.send("Nie znaleziono poprawnego linku w odpowiedzi.") |
| 84 | return | 85 | return |
| @@ -91,10 +92,12 @@ class Jarvis(commands.Cog): | |||
| 91 | elif response["type"] == "file": | 92 | elif response["type"] == "file": |
| 92 | file_data = response["content"] | 93 | file_data = response["content"] |
| 93 | await channel.send("wysyłon:", file=discord.File(file_data)) | 94 | await channel.send("wysyłon:", file=discord.File(file_data)) |
| 95 | os.remove(response["temp_dir"]) | ||
| 94 | else: | 96 | else: |
| 95 | logger.error(f"Error: {response['content']}") | 97 | logger.error(f"Error: {response['content']}") |
| 96 | if 'details' in response: | 98 | if 'details' in response: |
| 97 | logger.error(f"Details: {response['details']}") | 99 | logger.error(f"Details: {response['details']}") |
| 100 | os.remove(response["temp_dir"]) | ||
| 98 | 101 | ||
| 99 | elif action == "compress": | 102 | elif action == "compress": |
| 100 | pass | 103 | pass |
