Skip to content

Commit

Permalink
Update V4.1 !!
Browse files Browse the repository at this point in the history
- Added /addpic, /pics
- Telegram Log Display
- Multi Shortners Support
- Added shrinkme.io 
- MULTI_WORKING_PROGRESS_STR ( 7 Symbols )
- Added PICS in Bot Settings
- config.env Remodeled
- Minor Changes

Co-authored-by: Karan Adhikari <[email protected]>
  • Loading branch information
SilentDemonSD and weebzone authored Nov 30, 2022
1 parent 35126aa commit 38136fe
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 261 deletions.
91 changes: 50 additions & 41 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@

CMD_PERFIX = environ.get('CMD_PERFIX', '')


TORRENT_TIMEOUT = environ.get('TORRENT_TIMEOUT', '')
TORRENT_TIMEOUT = '' if len(TORRENT_TIMEOUT) == 0 else int(TORRENT_TIMEOUT)

Expand Down Expand Up @@ -559,9 +558,16 @@

FINISHED_PROGRESS_STR = environ.get('FINISHED_PROGRESS_STR', '')
UN_FINISHED_PROGRESS_STR = environ.get('UN_FINISHED_PROGRESS_STR', '')
if len(FINISHED_PROGRESS_STR) == 0 or len(FINISHED_PROGRESS_STR) == 0:
MULTI_WORKING_PROGRESS_STR = environ.get('MULTI_WORKING_PROGRESS_STR', '')
if len(FINISHED_PROGRESS_STR) == 0 or len(FINISHED_PROGRESS_STR) == 0 or len(MULTI_WORKING_PROGRESS_STR) == 0:
FINISHED_PROGRESS_STR = '█' # '■'
UN_FINISHED_PROGRESS_STR = '▒' # '□'
MULTI_WORKING_PROGRESS_STR = '▁ ▂ ▃ ▄ ▅ ▆ ▇'
MULTI_WORKING_PROGRESS_STR = (MULTI_WORKING_PROGRESS_STR.replace("'", '').replace('"', '').replace('[', '').replace(']', '').replace(",", "")).split(' ')

if len(MULTI_WORKING_PROGRESS_STR) != 7:
LOGGER.warning("Multi Progress doesn't contain 7 Symbols. Check Agian, Using Default for Now !")
MULTI_WORKING_PROGRESS_STR = '▁ ▂ ▃ ▄ ▅ ▆ ▇'.split(' ')

CHANNEL_USERNAME = environ.get('CHANNEL_USERNAME', '')
if len(CHANNEL_USERNAME) == 0:
Expand Down Expand Up @@ -603,7 +609,8 @@
if len(WALLCRAFT_CATEGORY) == 0:
WALLCRAFT_CATEGORY = ''

PICS = (environ.get('PICS', '')).split()
PICS = environ.get('PICS', '')
PICS = (PICS.replace("'", '').replace('"', '').replace('[', '').replace(']', '').replace(",", "")).split()

SERVER_PORT = environ.get('SERVER_PORT', '')
if len(SERVER_PORT) == 0:
Expand Down Expand Up @@ -633,18 +640,38 @@
UPDATE_PACKAGES = 'False'


config_dict = {'AS_DOCUMENT': AS_DOCUMENT,
config_dict = {'ANILIST_ENABLED': ANILIST_ENABLED,
'AS_DOCUMENT': AS_DOCUMENT,
'AUTHORIZED_CHATS': AUTHORIZED_CHATS,
'AUTHOR_NAME': AUTHOR_NAME,
'AUTHOR_URL': AUTHOR_URL,
'AUTO_DELETE_MESSAGE_DURATION': AUTO_DELETE_MESSAGE_DURATION,
'AUTO_DELETE_UPLOAD_MESSAGE_DURATION': AUTO_DELETE_UPLOAD_MESSAGE_DURATION,
'BASE_URL': BASE_URL,
'BOT_TOKEN': BOT_TOKEN,
'BOT_PM': BOT_PM,
'BUTTON_FOUR_NAME': BUTTON_FOUR_NAME,
'BUTTON_FOUR_URL': BUTTON_FOUR_URL,
'BUTTON_FIVE_NAME': BUTTON_FIVE_NAME,
'BUTTON_FIVE_URL': BUTTON_FIVE_URL,
'BUTTON_SIX_NAME': BUTTON_SIX_NAME,
'BUTTON_SIX_URL': BUTTON_SIX_URL,
'CAPTION_FONT': CAPTION_FONT,
'CREDIT_NAME': CREDIT_NAME,
'CHANNEL_USERNAME': CHANNEL_USERNAME,
'CLONE_ENABLED': CLONE_ENABLED,
'CLONE_LIMIT': CLONE_LIMIT,
'CMD_PERFIX': CMD_PERFIX,
'DRIVEFIRE_CRYPT': DRIVEFIRE_CRYPT,
'DOWNLOAD_DIR': DOWNLOAD_DIR,
'DATABASE_URL': DATABASE_URL,
'DEF_IMDB_TEMP': DEF_IMDB_TEMP,
'DEF_ANI_TEMP': DEF_ANI_TEMP,
'DISABLE_DRIVE_LINK': DISABLE_DRIVE_LINK,
'OWNER_ID': OWNER_ID,
'CMD_PERFIX': CMD_PERFIX,
'EQUAL_SPLITS': EQUAL_SPLITS,
'EXTENSION_FILTER': EXTENSION_FILTER,
'EMOJI_THEME': EMOJI_THEME,
'GDRIVE_ID': GDRIVE_ID,
'IGNORE_PENDING_REQUESTS': IGNORE_PENDING_REQUESTS,
'INCOMPLETE_TASK_NOTIFIER': INCOMPLETE_TASK_NOTIFIER,
Expand All @@ -658,31 +685,12 @@
'RSS_CHAT_ID': RSS_CHAT_ID,
'RSS_COMMAND': RSS_COMMAND,
'RSS_DELAY': RSS_DELAY,
'SEARCH_API_LINK': SEARCH_API_LINK,
'SEARCH_LIMIT': SEARCH_LIMIT,
'SEARCH_PLUGINS': SEARCH_PLUGINS,
'SERVER_PORT': SERVER_PORT,
'STATUS_LIMIT': STATUS_LIMIT,
'STATUS_UPDATE_INTERVAL': STATUS_UPDATE_INTERVAL,
'STOP_DUPLICATE': STOP_DUPLICATE,
'SUDO_USERS': SUDO_USERS,
'TELEGRAM_API': TELEGRAM_API,
'TELEGRAM_HASH': TELEGRAM_HASH,
'TORRENT_TIMEOUT': TORRENT_TIMEOUT,
'UPSTREAM_REPO': UPSTREAM_REPO,
'UPSTREAM_BRANCH': UPSTREAM_BRANCH,
'UPTOBOX_TOKEN': UPTOBOX_TOKEN,
'USE_SERVICE_ACCOUNTS': USE_SERVICE_ACCOUNTS,
'VIEW_LINK': VIEW_LINK,
'LEECH_ENABLED': LEECH_ENABLED,
'MIRROR_ENABLED': MIRROR_ENABLED,
'WATCH_ENABLED': WATCH_ENABLED,
'CLONE_ENABLED': CLONE_ENABLED,
'ANILIST_ENABLED': ANILIST_ENABLED,
'WAYBACK_ENABLED': WAYBACK_ENABLED,
'MEDIAINFO_ENABLED': MEDIAINFO_ENABLED,
'SET_BOT_COMMANDS': SET_BOT_COMMANDS,
'BOT_PM': BOT_PM,
'FORCE_BOT_PM': FORCE_BOT_PM,
'LEECH_LOG': LEECH_LOG,
'LEECH_LOG_URL': LEECH_LOG_URL,
Expand All @@ -694,20 +702,32 @@
'TIMEZONE': TIMEZONE,
'TGH_THUMB': TGH_THUMB,
'TITLE_NAME': TITLE_NAME,
'AUTHOR_NAME': AUTHOR_NAME,
'AUTHOR_URL': AUTHOR_URL,
'GD_INFO': GD_INFO,
'FSUB': FSUB,
'CHANNEL_USERNAME': CHANNEL_USERNAME,
'FSUB_CHANNEL_ID': FSUB_CHANNEL_ID,
'SHORTENER': SHORTENER,
'SHORTENER_API': SHORTENER_API,
'SEARCH_API_LINK': SEARCH_API_LINK,
'SEARCH_LIMIT': SEARCH_LIMIT,
'SEARCH_PLUGINS': SEARCH_PLUGINS,
'SERVER_PORT': SERVER_PORT,
'STATUS_LIMIT': STATUS_LIMIT,
'STATUS_UPDATE_INTERVAL': STATUS_UPDATE_INTERVAL,
'STOP_DUPLICATE': STOP_DUPLICATE,
'SUDO_USERS': SUDO_USERS,
'TELEGRAM_API': TELEGRAM_API,
'TELEGRAM_HASH': TELEGRAM_HASH,
'TORRENT_TIMEOUT': TORRENT_TIMEOUT,
'UPSTREAM_REPO': UPSTREAM_REPO,
'UPSTREAM_BRANCH': UPSTREAM_BRANCH,
'UPTOBOX_TOKEN': UPTOBOX_TOKEN,
'USE_SERVICE_ACCOUNTS': USE_SERVICE_ACCOUNTS,
'UNIFIED_EMAIL': UNIFIED_EMAIL,
'UNIFIED_PASS': UNIFIED_PASS,
'VIEW_LINK': VIEW_LINK,
'GDTOT_CRYPT': GDTOT_CRYPT,
'HUBDRIVE_CRYPT': HUBDRIVE_CRYPT,
'KATDRIVE_CRYPT': KATDRIVE_CRYPT,
'DRIVEFIRE_CRYPT': DRIVEFIRE_CRYPT,
'SHAREDRIVE_PHPCKS': SHAREDRIVE_PHPCKS,
'XSRF_TOKEN': XSRF_TOKEN,
'laravel_session': laravel_session,
Expand All @@ -716,39 +736,28 @@
'STORAGE_THRESHOLD': STORAGE_THRESHOLD,
'TORRENT_DIRECT_LIMIT': TORRENT_DIRECT_LIMIT,
'ZIP_UNZIP_LIMIT': ZIP_UNZIP_LIMIT,
'CLONE_LIMIT': CLONE_LIMIT,
'LEECH_LIMIT': LEECH_LIMIT,
'MEGA_LIMIT': MEGA_LIMIT,
'TIME_GAP': TIME_GAP,
'FINISHED_PROGRESS_STR': FINISHED_PROGRESS_STR,
'UN_FINISHED_PROGRESS_STR': UN_FINISHED_PROGRESS_STR,
'EMOJI_THEME': EMOJI_THEME,
'MULTI_WORKING_PROGRESS_STR': MULTI_WORKING_PROGRESS_STR,
'SHOW_LIMITS_IN_STATS': SHOW_LIMITS_IN_STATS,
'TELEGRAPH_STYLE': TELEGRAPH_STYLE,
'CREDIT_NAME': CREDIT_NAME,
'WALLFLARE_SEARCH': WALLFLARE_SEARCH,
'WALLTIP_SEARCH': WALLTIP_SEARCH,
'WALLCRAFT_CATEGORY': WALLCRAFT_CATEGORY,
'PIXABAY_API_KEY': PIXABAY_API_KEY,
'PIXABAY_CATEGORY': PIXABAY_CATEGORY,
'PIXABAY_SEARCH': PIXABAY_SEARCH,
'PICS': PICS,
'NAME_FONT': NAME_FONT,
'CAPTION_FONT': CAPTION_FONT,
'DEF_IMDB_TEMP': DEF_IMDB_TEMP,
'DEF_ANI_TEMP': DEF_ANI_TEMP,
'DISABLE_DRIVE_LINK': DISABLE_DRIVE_LINK,
'UPDATE_PACKAGES': UPDATE_PACKAGES,
'SOURCE_LINK': SOURCE_LINK,
'START_BTN1_NAME': START_BTN1_NAME,
'START_BTN1_URL': START_BTN1_URL,
'START_BTN2_NAME': START_BTN2_NAME,
'START_BTN2_URL': START_BTN2_URL,
'BUTTON_FOUR_NAME': BUTTON_FOUR_NAME,
'BUTTON_FOUR_URL': BUTTON_FOUR_URL,
'BUTTON_FIVE_NAME': BUTTON_FIVE_NAME,
'BUTTON_FIVE_URL': BUTTON_FIVE_URL,
'BUTTON_SIX_NAME': BUTTON_SIX_NAME,
'BUTTON_SIX_URL': BUTTON_SIX_URL,
'WEB_PINCODE': WEB_PINCODE,
'YT_DLP_QUALITY': YT_DLP_QUALITY}

Expand Down
3 changes: 2 additions & 1 deletion bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from .helper.telegram_helper.button_build import ButtonMaker
from bot.modules.wayback import getRandomUserAgent
from .modules import authorize, list, cancel_mirror, mirror_status, mirror_leech, clone, ytdlp, shell, eval, bot_settings, \
delete, count, users_settings, search, rss, wayback, speedtest, anilist, imdb, bt_select, mediainfo, hash, addons, scraper
delete, count, users_settings, search, rss, wayback, speedtest, anilist, imdb, bt_select, mediainfo, hash, \
addons, scraper, pictures
from datetime import datetime

def progress_bar(percentage):
Expand Down
5 changes: 2 additions & 3 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class EngineStatus:


SIZE_UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
PROGRESS_INCOMPLETE = ['▁', '▂', '▃', '▄', '▅', '▆', '▇']

class setInterval:
def __init__(self, interval, action):
Expand Down Expand Up @@ -143,7 +142,7 @@ def get_user_task(user_id):
def progress_bar(percentage):
"""Returns a progress bar for download"""
if isinstance(percentage, str):
return "NaN"
return "N/A"
try:
percentage = int(percentage)
except Exception:
Expand Down Expand Up @@ -173,7 +172,7 @@ def get_progress_bar_string(status):
cPart = p % 8 - 1
p_str = config_dict['FINISHED_PROGRESS_STR'] * cFull
if cPart >= 0:
p_str += PROGRESS_INCOMPLETE[cPart]
p_str += config_dict['MULTI_WORKING_PROGRESS_STR'][cPart]
p_str += config_dict['UN_FINISHED_PROGRESS_STR'] * (12 - cFull)
p_str = f"[{p_str}]"
return p_str
Expand Down
3 changes: 1 addition & 2 deletions bot/helper/ext_utils/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from math import ceil
from re import split as re_split, I
from .exceptions import NotSupportedExtractionArchive
from bot import aria2, app, LOGGER, DOWNLOAD_DIR, get_client, premium_session, config_dict
from bot import aria2, app, LOGGER, DOWNLOAD_DIR, get_client, premium_session, config_dict, STORAGE_THRESHOLD


ARCH_EXT = [".tar.bz2", ".tar.gz", ".bz2", ".gz", ".tar.xz", ".tar", ".tbz2", ".tgz", ".lzma2",
Expand Down Expand Up @@ -89,7 +89,6 @@ def get_path_size(path: str):
return total_size

def check_storage_threshold(size: int, arch=False, alloc=False):
STORAGE_THRESHOLD = config_dict['STORAGE_THRESHOLD']
if not alloc:
if not arch:
if disk_usage(DOWNLOAD_DIR).free - size < STORAGE_THRESHOLD * 1024**3:
Expand Down
19 changes: 13 additions & 6 deletions bot/helper/ext_utils/shortenurl.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


from random import random, choice

from cfscrape import create_scraper
Expand All @@ -9,11 +7,17 @@

from bot import LOGGER, config_dict


SHORTENER_API = config_dict['SHORTENER_API']
SHORTENER = config_dict['SHORTENER']
LSHORTENER_API = config_dict['SHORTENER_API'].split(' ')
LSHORTENER = config_dict['SHORTENER'].split(' ')
def short_url(longurl):
if SHORTENER == '' and SHORTENER_API == '':
if len(LSHORTENER) == 0 and len(LSHORTENER_API) == 0:
return longurl
SHORTENER = choice(LSHORTENER)
ind = LSHORTENER.index(SHORTENER)
try:
SHORTENER_API = LSHORTENER_API[ind]
except IndexError:
LOGGER.error(f"{SHORTENER}'s API Key Not Found")
return longurl
try:
cget = create_scraper().get
Expand Down Expand Up @@ -48,6 +52,9 @@ def short_url(longurl):
elif "cutt.ly" in SHORTENER:
disable_warnings()
return cget(f'http://cutt.ly/api/api.php?key={SHORTENER_API}&short={longurl}', verify=False).json()['url']['shortLink']
elif "shrinkme.io" in SHORTENER:
disable_warnings()
return cget(f'https://shrinkme.io/api?api={SHORTENER_API}&url={quote(longurl)}&format=text').text
else:
return cget(f'https://{SHORTENER}/api?api={SHORTENER_API}&url={quote(longurl)}&format=text').text
except Exception as e:
Expand Down
8 changes: 4 additions & 4 deletions bot/helper/ext_utils/timegap.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import time
from time import time

from bot import config_dict, TIME_GAP_STORE
from bot.helper.ext_utils.bot_utils import timeformatter

def timegap_check(message):
if message.from_user.id in TIME_GAP_STORE:
if int(time.time() - TIME_GAP_STORE[message.from_user.id]) < config_dict['TIME_GAP']:
wtime = timeformatter((int(TIME_GAP_STORE[message.from_user.id]) + config_dict['TIME_GAP'] - int(time.time())) * 1000)
if int(time() - TIME_GAP_STORE[message.from_user.id]) < config_dict['TIME_GAP']:
wtime = timeformatter((int(TIME_GAP_STORE[message.from_user.id]) + config_dict['TIME_GAP'] - int(time())) * 1000)
#rtime = timeformatter(config_dict['TIME_GAP'])
text = f"Please wait {wtime}. Normal Users have Time Restriction for {config_dict['TIME_GAP']} sec. "
message.reply_text(
Expand All @@ -19,4 +19,4 @@ def timegap_check(message):
del TIME_GAP_STORE[message.from_user.id]
return False
else:
return False
return False
2 changes: 1 addition & 1 deletion bot/helper/mirror_utils/upload_utils/gdriveTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def __upload_dir(self, input_directory, dest_id):
def __create_directory(self, directory_name, dest_id):
file_metadata = {
"name": directory_name,
"description": "Uploaded by Mirror-leech-telegram-bot",
"description": f"{config_dict['GD_INFO']}",
"mimeType": self.__G_DRIVE_DIR_MIME_TYPE
}
if dest_id is not None:
Expand Down
8 changes: 4 additions & 4 deletions bot/helper/telegram_helper/bot_commands.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from bot import CMD_PERFIX
import os
from os import environ

def getCommand(name: str, command: str):
try:
if len(os.environ[name]) == 0:
if len(environ[name]) == 0:
raise KeyError
return os.environ[name]
return environ[name]
except KeyError:
return command


class _BotCommands:
def __init__(self):
self.StartCommand = getCommand(f'START_COMMAND', f'start{CMD_PERFIX}')
Expand Down
Loading

0 comments on commit 38136fe

Please sign in to comment.