Skip to content

Commit

Permalink
Minor bug fixes in source
Browse files Browse the repository at this point in the history
Signed-off-by: harshhaareddy <[email protected]>
  • Loading branch information
harshhaareddy committed May 15, 2022
1 parent 9ec64d4 commit 2562c95
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 50 deletions.
8 changes: 6 additions & 2 deletions bot/helper/mirror_utils/status_utils/aria_download_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from .status import Status

def get_download(gid):
return aria2.get_download(gid)
try:
return aria2.get_download(gid)
except Exception as e:
LOGGER.error(f'{e}: while getting torrent info')


class AriaDownloadStatus(Status):
Expand Down Expand Up @@ -39,7 +42,8 @@ def processed_bytes(self):
return self.aria_download().completed_length

def speed(self):
return self.aria_download().download_speed_string()
self.__update()
return self.__download.download_speed_string()

def name(self):
return self.aria_download().name
Expand Down
9 changes: 8 additions & 1 deletion bot/helper/mirror_utils/status_utils/qbit_download_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
from bot import DOWNLOAD_DIR, LOGGER, get_client
from bot.helper.ext_utils.bot_utils import MirrorStatus, get_readable_file_size, get_readable_time
from .status import Status
from time import sleep

def get_download(client, hash_):
try:
return client.torrents_info(torrent_hashes=hash_)[0]
except Exception as e:
LOGGER.error(f'{e}: while getting torrent info')

class QbDownloadStatus(Status):

Expand Down Expand Up @@ -37,7 +43,8 @@ def processed_bytes(self):
return self.torrent_info().downloaded

def speed(self):
return f"{get_readable_file_size(self.torrent_info().dlspeed)}/s"
self.__update()
return f"{get_readable_file_size(self.__info.dlspeed)}/s"

def name(self):
return self.torrent_info().name
Expand Down
19 changes: 1 addition & 18 deletions bot/helper/telegram_helper/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from telegram.ext import MessageFilter
from telegram import Message
from bot import AUTHORIZED_CHATS, SUDO_USERS, OWNER_ID, download_dict, download_dict_lock
from bot import AUTHORIZED_CHATS, SUDO_USERS, OWNER_ID


class CustomFilters:
Expand Down Expand Up @@ -28,20 +28,3 @@ def filter(self,message):
return bool(message.from_user.id in SUDO_USERS)

sudo_user = _SudoUser()

class _MirrorOwner(MessageFilter):
def filter(self, message: Message):
user_id = message.from_user.id
if user_id == OWNER_ID:
return True
args = str(message.text).split(' ')
if len(args) > 1:
# Cancelling by gid
with download_dict_lock:
return any(status.gid() == args[1] and status.message.from_user.id == user_id for message_id, status in download_dict.items())
if not message.reply_to_message and len(args) == 1:
return True
# Cancelling by replying to original mirror message
reply_user = message.reply_to_message.from_user.id
return bool(reply_user == user_id)
mirror_owner_filter = _MirrorOwner()
65 changes: 42 additions & 23 deletions bot/modules/cancel_mirror.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from telegram.ext import CommandHandler
from bot import download_dict, dispatcher, download_dict_lock, DOWNLOAD_DIR
from bot import download_dict, dispatcher, download_dict_lock, DOWNLOAD_DIR, SUDO_USERS, OWNER_ID
from bot.helper.ext_utils.fs_utils import clean_download
from bot.helper.telegram_helper.bot_commands import BotCommands
from bot.helper.telegram_helper.filters import CustomFilters
from bot.helper.telegram_helper.message_utils import sendMessage, sendMarkup
from bot.helper.ext_utils.bot_utils import getDownloadByGid, MirrorStatus, getAllDownload
from bot.helper.telegram_helper import button_build
from bot.helper.telegram_helper.message_utils import *

from time import sleep
Expand All @@ -11,37 +14,31 @@

def cancel_mirror(update, context):
args = update.message.text.split(" ", maxsplit=1)
mirror_message = None
user_id = update.message.from_user.id
if len(args) > 1:
gid = args[1]
dl = getDownloadByGid(gid)
if not dl:
sendMessage(f"GID: <code>{gid}</code> ๐๐จ๐ญ ๐…๐จ๐ฎ๐ง๐.", context.bot, update)
return
mirror_message = dl.message
return sendMessage(f"GID: <code>{gid}</code> ๐๐จ๐ญ ๐…๐จ๐ฎ๐ง๐.", context.bot, update.message)
elif update.message.reply_to_message:
mirror_message = update.message.reply_to_message
with download_dict_lock:
keys = list(download_dict.keys())
try:
dl = download_dict[mirror_message.message_id]
except:
pass
if len(args) == 1:
msg = f"Please reply to the <code>/{BotCommands.MirrorCommand}</code> message which was used to start the download or send <code>/{BotCommands.CancelMirror} GID</code> to cancel it!"
if mirror_message and mirror_message.message_id not in keys:
if BotCommands.MirrorCommand in mirror_message.text or \
BotCommands.TarMirrorCommand in mirror_message.text or \
BotCommands.UnzipMirrorCommand in mirror_message.text:
msg1 = "๐Œ๐ข๐ซ๐ซ๐จ๐ซ ๐€๐ฅ๐ซ๐ž๐š๐๐ฒ ๐‡๐š๐ฏ๐ž ๐๐ž๐ž๐ง ๐‚๐š๐ง๐œ๐ž๐ฅ๐ฅ๐ž๐"
sendMessage(msg1, context.bot, update)
return
else:
sendMessage(msg, context.bot, update)
return
elif not mirror_message:
sendMessage(msg, context.bot, update)
return
dl = None
if not dl:
return sendMessage(f"๐“๐ก๐ข๐ฌ ๐ข๐ฌ ๐ง๐จ๐ญ ๐š๐ง ๐š๐œ๐ญ๐ข๐ฏ๐ž ๐ญ๐š๐ฌ๐ค!", context.bot, update.message)
elif len(args) == 1:
msg = f"๐‘๐ž๐ฉ๐ฅ๐ฒ ๐ญ๐จ ๐š๐ง ๐š๐œ๐ญ๐ข๐ฏ๐ž <code>/{BotCommands.MirrorCommand}</code> ๐ฆ๐ž๐ฌ๐ฌ๐š๐ ๐ž ๐ฐ๐ก๐ข๐œ๐ก ๐ฐ๐š๐ฌ ๐ฎ๐ฌ๐ž๐ ๐ญ๐จ ๐ฌ๐ญ๐š๐ซ๐ญ ๐ญ๐ก๐ž ๐๐จ๐ฐ๐ง๐ฅ๐จ๐š๐ ๐จ๐ซ ๐ฌ๐ž๐ง๐ <code>/{BotCommands.CancelMirror} GID</code> ๐ญ๐จ ๐œ๐š๐ง๐œ๐ž๐ฅ ๐ข๐ญ!"
return sendMessage(msg, context.bot, update.message)

if OWNER_ID == user_id or dl.message.from_user.id == user_id or user_id in SUDO_USERS:
pass
else:
return sendMessage("๐“๐ก๐ข๐ฌ ๐ญ๐š๐ฌ๐ค ๐๐จ๐ž๐ฌ๐ง'๐ญ ๐›๐ž๐ฅ๐จ๐ง๐  ๐ญ๐จ ๐ฒ๐จ๐ฎ!", context.bot, update.message)

if dl.status() == MirrorStatus.STATUS_ARCHIVING:
sendMessage("๐€๐ซ๐œ๐ก๐ข๐ฏ๐š๐ฅ ๐ข๐ง ๐๐ซ๐จ๐ ๐ซ๐ž๐ฌ๐ฌ, ๐˜๐จ๐ฎ ๐‚๐š๐ง'๐ญ ๐‚๐š๐ง๐œ๐ž๐ฅ ๐ˆ๐ญ.", context.bot, update)
elif dl.status() == MirrorStatus.STATUS_EXTRACTING:
Expand All @@ -66,12 +63,34 @@ def cancel_all(update, context):
else:
break
sendMessage(f'{count} ๐ƒ๐จ๐ฐ๐ง๐ฅ๐จ๐š๐(๐ฌ) ๐ก๐š๐ฌ ๐›๐ž๐ž๐ง ๐‚๐š๐ง๐œ๐ž๐ฅ๐ฅ๐ž๐!', context.bot, update)

def cancell_all_buttons(update, context):
buttons = button_build.ButtonMaker()
buttons.sbutton("Downloading", "canall down")
buttons.sbutton("Uploading", "canall up")
if QB_SEED:
buttons.sbutton("Seeding", "canall seed")
buttons.sbutton("Cloning", "canall clone")
buttons.sbutton("All", "canall all")
button = InlineKeyboardMarkup(buttons.build_menu(2))
sendMarkup('Choose tasks to cancel.', context.bot, update.message, button)
def cancel_all_update(update, context):
query = update.callback_query
user_id = query.from_user.id
data = query.data
data = data.split(" ")
if CustomFilters._owner_query(user_id):
query.answer()
query.message.delete()
cancel_all(data[1])
else:
query.answer(text="๐˜๐จ๐ฎ ๐๐จ๐ง'๐ญ ๐ก๐š๐ฏ๐ž ๐ฉ๐ž๐ซ๐ฆ๐ข๐ฌ๐ฌ๐ข๐จ๐ง ๐ญ๐จ ๐ฎ๐ฌ๐ž ๐ญ๐ก๐ž๐ฌ๐ž ๐›๐ฎ๐ญ๐ญ๐จ๐ง๐ฌ!", show_alert=True)



cancel_mirror_handler = CommandHandler(BotCommands.CancelMirror, cancel_mirror,
filters=(CustomFilters.authorized_chat | CustomFilters.authorized_user) & CustomFilters.mirror_owner_filter | CustomFilters.sudo_user, run_async=True)
cancel_all_handler = CommandHandler(BotCommands.CancelAllCommand, cancel_all,
filters=(CustomFilters.authorized_chat | CustomFilters.authorized_user), run_async=True)
cancel_all_handler = CommandHandler(BotCommands.CancelAllCommand, cancell_all_buttons,
filters=CustomFilters.owner_filter | CustomFilters.sudo_user, run_async=True)
dispatcher.add_handler(cancel_all_handler)
dispatcher.add_handler(cancel_mirror_handler)
17 changes: 12 additions & 5 deletions bot/modules/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ def cloneNode(update, context):
sendMarkup(msg3, context.bot, update, button)
return
if CLONE_LIMIT is not None:
result = check_limit(size, CLONE_LIMIT)
if result:
msg2 = f'๐…๐š๐ข๐ฅ๐ž๐, ๐‚๐ฅ๐จ๐ง๐ž ๐ฅ๐ข๐ฆ๐ข๐ญ ๐ข๐ฌ {CLONE_LIMIT}.\n๐˜๐จ๐ฎ๐ซ ๐…๐ข๐ฅ๐ž/๐…๐จ๐ฅ๐๐ž๐ซ ๐ฌ๐ข๐ณ๐ž ๐ข๐ฌ {get_readable_file_size(clonesize)}.'
sendMessage(msg2, context.bot, update)
return
LOGGER.info('Checking File/Folder Size...')
if size > CLONE_LIMIT * 1024**3:
msg2 = f'๐…๐š๐ข๐ฅ๐ž๐, ๐‚๐ฅ๐จ๐ง๐ž ๐ฅ๐ข๐ฆ๐ข๐ญ ๐ข๐ฌ {CLONE_LIMIT}GB.\n๐˜๐จ๐ฎ๐ซ ๐…๐ข๐ฅ๐ž/๐…๐จ๐ฅ๐๐ž๐ซ ๐ฌ๐ข๐ณ๐ž ๐ข๐ฌ {get_readable_file_size(size)}.'
return sendMessage(msg2, bot, message)
if multi > 1:
sleep(1)
nextmsg = type('nextmsg', (object, ), {'chat_id': message.chat_id, 'message_id': message.reply_to_message.message_id + 1})
nextmsg = sendMessage(args[0], bot, nextmsg)
nextmsg.from_user.id = message.from_user.id
multi -= 1
sleep(1)
Thread(target=_clone, args=(nextmsg, bot, multi)).start()
if files < 15:
msg = sendMessage(f"๐‚๐ฅ๐จ๐ง๐ข๐ง๐ : <code>{link}</code>", context.bot, update)
result, button = gd.clone(link)
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def _mirror(bot, update, isTar=False, extract=False, isZip=False, isQbit=False):
open(file_name, "wb").write(resp.content)
link = f"{file_name}"
else:
sendMessage("ERROR: link got HTTP response:" + resp.status_code, bot, update)
sendMessage("๐„๐‘๐‘๐Ž๐‘: ๐ฅ๐ข๐ง๐ค ๐ ๐จ๐ญ ๐‡๐“๐“๐ ๐ซ๐ž๐ฌ๐ฉ๐จ๐ง๐ฌ๐ž:" + resp.status_code, bot, update)
return

elif not bot_utils.is_url(link) and not bot_utils.is_magnet(link):
Expand Down

0 comments on commit 2562c95

Please sign in to comment.