alaskavix12 commited on
Commit
0c07060
·
1 Parent(s): 080dcca

initial commit

Browse files
Files changed (2) hide show
  1. aria.py +11 -2
  2. bot.py +2 -2
aria.py CHANGED
@@ -31,7 +31,7 @@ class Aria:
31
  self.reported_downloads = set()
32
  logger.info("Aria2 client initialized")
33
 
34
- def add_download(self, url):
35
  try:
36
  options = {"dir": self.download_dir}
37
  download = self.aria2.add_uris([url], options=options)
@@ -39,6 +39,7 @@ class Aria:
39
  return download.gid
40
  except Exception as e:
41
  logger.error(f"Failed to start download: {e}")
 
42
  return str(e)
43
 
44
  def get_download_status(self, gid):
@@ -87,7 +88,15 @@ class Aria:
87
 
88
  async def send_download_complete_message(self, download):
89
  message = f"Download complete: {download.name}\nDownload path: {self.download_dir}/{download.name}"
90
- await self.bot.send_message(CHAT_ID, message)
 
 
 
 
 
 
 
 
91
  logger.info(message)
92
 
93
  def start_listener(self):
 
31
  self.reported_downloads = set()
32
  logger.info("Aria2 client initialized")
33
 
34
+ def add_download(self, url, chat_id):
35
  try:
36
  options = {"dir": self.download_dir}
37
  download = self.aria2.add_uris([url], options=options)
 
39
  return download.gid
40
  except Exception as e:
41
  logger.error(f"Failed to start download: {e}")
42
+ self.notify_download_error(chat_id, str(e))
43
  return str(e)
44
 
45
  def get_download_status(self, gid):
 
88
 
89
  async def send_download_complete_message(self, download):
90
  message = f"Download complete: {download.name}\nDownload path: {self.download_dir}/{download.name}"
91
+ await self.bot.send_message(download.dir, message) # Assuming download.dir contains the chat_id
92
+ logger.info(message)
93
+
94
+ def notify_download_error(self, chat_id, error_message):
95
+ asyncio.run(self.send_download_error_message(chat_id, error_message))
96
+
97
+ async def send_download_error_message(self, chat_id, error_message):
98
+ message = f"Download error: {error_message}"
99
+ await self.bot.send_message(chat_id, message)
100
  logger.info(message)
101
 
102
  def start_listener(self):
bot.py CHANGED
@@ -15,7 +15,6 @@ app = FastAPI()
15
  API_ID = os.environ.get("API_ID", 2589472)
16
  API_HASH = os.environ.get("API_HASH", "5243628014db9798d6775b330e542602")
17
  TOKEN = os.environ.get("TOKEN", "6520286363:AAEe0c5v_JQf8ztatUx8ZeO_ARXrJkYsluI")
18
- CHAT_ID = os.environ.get("CHAT_ID", "1487943213") # Add your chat ID here
19
 
20
  async def clientbot():
21
  bot = Client(":memory:", api_id=API_ID, api_hash=API_HASH, bot_token=TOKEN)
@@ -34,7 +33,8 @@ async def clientbot():
34
  return
35
 
36
  url = message.command[1]
37
- result = aria2.add_download(url)
 
38
  if isinstance(result, str) and result.startswith("Failed"):
39
  await message.reply_text(f"Failed to start download: {result}")
40
  logger.error(f"Failed to start download for URL: {url} - Error: {result}")
 
15
  API_ID = os.environ.get("API_ID", 2589472)
16
  API_HASH = os.environ.get("API_HASH", "5243628014db9798d6775b330e542602")
17
  TOKEN = os.environ.get("TOKEN", "6520286363:AAEe0c5v_JQf8ztatUx8ZeO_ARXrJkYsluI")
 
18
 
19
  async def clientbot():
20
  bot = Client(":memory:", api_id=API_ID, api_hash=API_HASH, bot_token=TOKEN)
 
33
  return
34
 
35
  url = message.command[1]
36
+ chat_id = message.chat.id
37
+ result = aria2.add_download(url, chat_id)
38
  if isinstance(result, str) and result.startswith("Failed"):
39
  await message.reply_text(f"Failed to start download: {result}")
40
  logger.error(f"Failed to start download for URL: {url} - Error: {result}")