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
|
from bot import download_dict
|
||||||
|
|
||||||
|
|
||||||
def get_download(update_id):
|
def get_download(message_id):
|
||||||
return download_dict[update_id].download()
|
return download_dict[message_id].download()
|
||||||
|
|
||||||
|
|
||||||
def get_download_status_list():
|
def get_download_status_list():
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,10 @@ class DownloadStatus:
|
||||||
STATUS_WAITING = "Queued"
|
STATUS_WAITING = "Queued"
|
||||||
STATUS_FAILED = "Failed. Cleaning download"
|
STATUS_FAILED = "Failed. Cleaning download"
|
||||||
|
|
||||||
def __init__(self, gid, update_id):
|
def __init__(self, gid, message_id):
|
||||||
self.__gid = gid
|
self.__gid = gid
|
||||||
self.__download = get_download(gid)
|
self.__download = get_download(gid)
|
||||||
self.__uid = update_id
|
self.__uid = message_id
|
||||||
|
|
||||||
def __update(self):
|
def __update(self):
|
||||||
self.__download = get_download(self.__gid)
|
self.__download = get_download(self.__gid)
|
||||||
|
|
|
||||||
|
|
@ -27,19 +27,20 @@ class DownloadHelper:
|
||||||
if self.is_url(link):
|
if self.is_url(link):
|
||||||
if link.endswith('.torrent'):
|
if link.endswith('.torrent'):
|
||||||
self.__is_torrent = True
|
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):
|
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
|
self.__is_torrent = True
|
||||||
else:
|
else:
|
||||||
self.__listener.onDownloadError("No download URL or URL malformed")
|
self.__listener.onDownloadError("No download URL or URL malformed")
|
||||||
return
|
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.__listener.onDownloadStarted(link)
|
||||||
self.__update_download_status()
|
self.__update_download_status()
|
||||||
|
|
||||||
def __get_download(self):
|
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):
|
def __get_followed_download_gid(self):
|
||||||
download = self.__get_download()
|
download = self.__get_download()
|
||||||
|
|
@ -67,7 +68,7 @@ class DownloadHelper:
|
||||||
self.__listener.onDownloadProgress(get_download_status_list(), index)
|
self.__listener.onDownloadProgress(get_download_status_list(), index)
|
||||||
except KillThreadException:
|
except KillThreadException:
|
||||||
should_update = False
|
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
|
# Start tracking the actual download
|
||||||
previous = None
|
previous = None
|
||||||
|
|
|
||||||
|
|
@ -57,9 +57,9 @@ class GoogleDriveHelper:
|
||||||
|
|
||||||
def upload(self, file_name: str):
|
def upload(self, file_name: str):
|
||||||
_list = get_download_status_list()
|
_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)
|
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)
|
file_path = "{}/{}".format(file_dir, file_name)
|
||||||
link = None
|
link = None
|
||||||
LOGGER.info("Uploading File: " + file_name)
|
LOGGER.info("Uploading File: " + file_name)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
class MirrorListeners:
|
class MirrorListeners:
|
||||||
def __init__(self, context, update, reply_message):
|
def __init__(self, context, update, reply_message):
|
||||||
self.context = context
|
self.context = context
|
||||||
self.update = update
|
self.message = update.message
|
||||||
self.reply_message = reply_message
|
self.reply_message = reply_message
|
||||||
|
|
||||||
def onDownloadStarted(self, link: str):
|
def onDownloadStarted(self, link: str):
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
from telegram.error import BadRequest
|
|
||||||
from telegram.message import Message
|
from telegram.message import Message
|
||||||
from telegram.update import Update
|
from telegram.update import Update
|
||||||
from bot import LOGGER
|
|
||||||
|
|
||||||
def sendMessage(text: str, context, update: Update):
|
def sendMessage(text: str, context, update: Update):
|
||||||
return context.bot.send_message(update.message.chat_id,
|
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):
|
def editMessage(text: str, context, message: Message):
|
||||||
context.bot.edit_message_text(text=text, message_id=message.message_id,
|
context.bot.edit_message_text(text=text, message_id=message.message_id,
|
||||||
chat_id=message.chat.id,
|
chat_id=message.chat.id,
|
||||||
parse_mode='HTMl')
|
parse_mode='HTMl')
|
||||||
|
|
||||||
|
|
||||||
def deleteMessage(context, message: Message):
|
def deleteMessage(context, message: Message):
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
from telegram.ext import CommandHandler, run_async
|
from telegram.ext import CommandHandler, run_async
|
||||||
|
from telegram.error import BadRequest
|
||||||
from bot.helper import download_tools, gdriveTools, listeners
|
from bot.helper import download_tools, gdriveTools, listeners
|
||||||
from bot import LOGGER, dispatcher
|
from bot import LOGGER, dispatcher
|
||||||
from bot.helper import fs_utils
|
from bot.helper import fs_utils
|
||||||
from bot import download_dict, status_reply_dict
|
from bot import download_dict, status_reply_dict
|
||||||
from bot.helper.message_utils import *
|
from bot.helper.message_utils import *
|
||||||
from bot.helper.bot_utils import get_readable_message, KillThreadException
|
from bot.helper.bot_utils import get_readable_message, KillThreadException
|
||||||
LOGGER.info('mirror.py')
|
|
||||||
|
|
||||||
|
|
||||||
class MirrorListener(listeners.MirrorListeners):
|
class MirrorListener(listeners.MirrorListeners):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue