Use message_id as a key for download_dict instead of update_id
Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
parent
7703a14058
commit
4e3f412e7a
|
|
@ -2,8 +2,8 @@
|
|||
from bot import download_dict
|
||||
|
||||
|
||||
def get_download(update_id):
|
||||
return download_dict[update_id].download()
|
||||
def get_download(message_id):
|
||||
return download_dict[message_id].download()
|
||||
|
||||
|
||||
def get_download_status_list():
|
||||
|
|
|
|||
|
|
@ -11,10 +11,10 @@ class DownloadStatus:
|
|||
STATUS_WAITING = "Queued"
|
||||
STATUS_FAILED = "Failed. Cleaning download"
|
||||
|
||||
def __init__(self, gid, update_id):
|
||||
def __init__(self, gid, message_id):
|
||||
self.__gid = gid
|
||||
self.__download = get_download(gid)
|
||||
self.__uid = update_id
|
||||
self.__uid = message_id
|
||||
|
||||
def __update(self):
|
||||
self.__download = get_download(self.__gid)
|
||||
|
|
|
|||
|
|
@ -27,19 +27,20 @@ class DownloadHelper:
|
|||
if self.is_url(link):
|
||||
if link.endswith('.torrent'):
|
||||
self.__is_torrent = True
|
||||
download = aria2.add_uris([link], {'dir': DOWNLOAD_DIR + str(self.__listener.update.update_id)})
|
||||
download = aria2.add_uris([link], {'dir': DOWNLOAD_DIR + str(self.__listener.message.message_id)})
|
||||
elif self.is_magnet(link):
|
||||
download = aria2.add_magnet(link, {'dir': DOWNLOAD_DIR + str(self.__listener.update.update_id)})
|
||||
download = aria2.add_magnet(link, {'dir': DOWNLOAD_DIR + str(self.__listener.message.message_id)})
|
||||
self.__is_torrent = True
|
||||
else:
|
||||
self.__listener.onDownloadError("No download URL or URL malformed")
|
||||
return
|
||||
download_dict[self.__listener.update.update_id] = DownloadStatus(download.gid, self.__listener.update.update_id)
|
||||
download_dict[self.__listener.message.message_id] = DownloadStatus(download.gid,
|
||||
self.__listener.message.message_id)
|
||||
self.__listener.onDownloadStarted(link)
|
||||
self.__update_download_status()
|
||||
|
||||
def __get_download(self):
|
||||
return get_download(self.__listener.update.update_id)
|
||||
return get_download(self.__listener.message.message_id)
|
||||
|
||||
def __get_followed_download_gid(self):
|
||||
download = self.__get_download()
|
||||
|
|
@ -67,7 +68,7 @@ class DownloadHelper:
|
|||
self.__listener.onDownloadProgress(get_download_status_list(), index)
|
||||
except KillThreadException:
|
||||
should_update = False
|
||||
download_dict[self.__listener.update.update_id] = DownloadStatus(new_gid, self.__listener.update.update_id)
|
||||
download_dict[self.__listener.message.message_id] = DownloadStatus(new_gid, self.__listener.message.message_id)
|
||||
|
||||
# Start tracking the actual download
|
||||
previous = None
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ class GoogleDriveHelper:
|
|||
|
||||
def upload(self, file_name: str):
|
||||
_list = get_download_status_list()
|
||||
index = get_download_index(_list, get_download(self.__listener.update.update_id).gid)
|
||||
index = get_download_index(_list, get_download(self.__listener.message.message_id).gid)
|
||||
self.__listener.onUploadStarted(_list, index)
|
||||
file_dir = "{}{}".format(DOWNLOAD_DIR, self.__listener.update.update_id)
|
||||
file_dir = "{}{}".format(DOWNLOAD_DIR, self.__listener.message.message_id)
|
||||
file_path = "{}/{}".format(file_dir, file_name)
|
||||
link = None
|
||||
LOGGER.info("Uploading File: " + file_name)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
class MirrorListeners:
|
||||
def __init__(self, context, update, reply_message):
|
||||
self.context = context
|
||||
self.update = update
|
||||
self.message = update.message
|
||||
self.reply_message = reply_message
|
||||
|
||||
def onDownloadStarted(self, link: str):
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
from telegram.error import BadRequest
|
||||
from telegram.message import Message
|
||||
from telegram.update import Update
|
||||
from bot import LOGGER
|
||||
|
||||
|
||||
def sendMessage(text: str, context, update: Update):
|
||||
return context.bot.send_message(update.message.chat_id,
|
||||
|
|
@ -10,9 +9,9 @@ def sendMessage(text: str, context, update: Update):
|
|||
|
||||
|
||||
def editMessage(text: str, context, message: Message):
|
||||
context.bot.edit_message_text(text=text, message_id=message.message_id,
|
||||
chat_id=message.chat.id,
|
||||
parse_mode='HTMl')
|
||||
context.bot.edit_message_text(text=text, message_id=message.message_id,
|
||||
chat_id=message.chat.id,
|
||||
parse_mode='HTMl')
|
||||
|
||||
|
||||
def deleteMessage(context, message: Message):
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
from telegram.ext import CommandHandler, run_async
|
||||
from telegram.error import BadRequest
|
||||
from bot.helper import download_tools, gdriveTools, listeners
|
||||
from bot import LOGGER, dispatcher
|
||||
from bot.helper import fs_utils
|
||||
from bot import download_dict, status_reply_dict
|
||||
from bot.helper.message_utils import *
|
||||
from bot.helper.bot_utils import get_readable_message, KillThreadException
|
||||
LOGGER.info('mirror.py')
|
||||
|
||||
|
||||
class MirrorListener(listeners.MirrorListeners):
|
||||
|
|
|
|||
Loading…
Reference in New Issue