From 2f4a8d0362b409de60f2562b27164685576c79dc Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 16:55:51 +0530 Subject: [PATCH 01/31] remove --- bot/__init__.py | 46 ------------ bot/__main__.py | 19 ----- bot/filetocloud.py | 33 --------- bot/plugins/cmd/cmd.py | 25 ------- bot/plugins/display/__init__.py | 56 --------------- bot/plugins/display/time.py | 25 ------- bot/plugins/helpers/call_back.py | 12 ---- bot/plugins/helpers/dowloader.py | 59 --------------- bot/plugins/helpers/incoming_messages.py | 54 -------------- bot/plugins/keyboard/__init__.py | 54 -------------- bot/plugins/upload_servers/__init__.py | 4 -- bot/plugins/upload_servers/anonymfiles.py | 52 -------------- bot/plugins/upload_servers/fileio_upload.py | 61 ---------------- bot/plugins/upload_servers/gofileio.py | 58 --------------- bot/plugins/upload_servers/mixdrop_upload.py | 76 -------------------- bot/plugins/upload_servers/transfersh.py | 57 --------------- bot/plugins/use/__init__.py | 15 ---- 17 files changed, 706 deletions(-) delete mode 100644 bot/__init__.py delete mode 100644 bot/__main__.py delete mode 100644 bot/filetocloud.py delete mode 100644 bot/plugins/cmd/cmd.py delete mode 100644 bot/plugins/display/__init__.py delete mode 100644 bot/plugins/display/time.py delete mode 100644 bot/plugins/helpers/call_back.py delete mode 100644 bot/plugins/helpers/dowloader.py delete mode 100644 bot/plugins/helpers/incoming_messages.py delete mode 100644 bot/plugins/keyboard/__init__.py delete mode 100644 bot/plugins/upload_servers/__init__.py delete mode 100644 bot/plugins/upload_servers/anonymfiles.py delete mode 100644 bot/plugins/upload_servers/fileio_upload.py delete mode 100644 bot/plugins/upload_servers/gofileio.py delete mode 100644 bot/plugins/upload_servers/mixdrop_upload.py delete mode 100644 bot/plugins/upload_servers/transfersh.py delete mode 100644 bot/plugins/use/__init__.py diff --git a/bot/__init__.py b/bot/__init__.py deleted file mode 100644 index c72c896..0000000 --- a/bot/__init__.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env python3 -# This is bot coded by Abhijith N T and used for educational purposes only -# https://github.com/AbhijithNT -# Copyright ABHIJITH N T -# Thank you https://github.com/pyrogram/pyrogram - -import os -import logging - -logging.basicConfig(level=logging.INFO, - handlers=[logging.FileHandler( - 'log.txt'), logging.StreamHandler()], - format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" - ) -LOGGER = logging.getLogger(__name__) -logging.getLogger("pyrogram").setLevel(logging.WARNING) - -ENV = bool(os.environ.get('ENV', False)) -try: - if ENV: - AUTH_USER = [] - BOT_TOKEN = os.environ.get('BOT_TOKEN') - APP_ID = os.environ.get('APP_ID') - API_HASH = os.environ.get('API_HASH') - BOT_USE = bool(os.environ.get('BOT_USE', False)) - GET_AUTH_USER = os.environ.get('AUTH_USER') - for i in GET_AUTH_USER.split(','): - AUTH_USER.append(int(i)) - else: - from sample_config import Config - - BOT_TOKEN = Config.BOT_TOKEN - APP_ID = Config.APP_ID - API_HASH = Config.API_HASH - BOT_USE = Config.BOT_USE - AUTH_USER = Config.AUTH_USERS -except KeyError: - LOGGER.error('One or more configuration values are missing exiting now.') - exit(1) - - -class Msg: - source = "\nsource: https://github.com/AbhijithNT/TelegramFiletoCloud" - start = "\nThis bot uploads telegram files to MixDrop.co,File.io.\nAdmin: @thankappan369" - error = "something is went wrong\n{error} \ncontact admin @thankappan369" - help = "Usage: Send any file and the bot will upload it to MixDrop.co,File.io" diff --git a/bot/__main__.py b/bot/__main__.py deleted file mode 100644 index dcd223f..0000000 --- a/bot/__main__.py +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env python3 -# This is bot coded by AbhijithCloud and used for educational purposes only -# https://github.com/AbhijithNT -# Copyright ABHIJITH N T -# Thank you https://github.com/pyrogram/pyrogram - -import pyrogram -from bot.filetocloud import CloudBot -import logging -logging.basicConfig( - level=logging.DEBUG, - format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" -) -LOGGER = logging.getLogger(__name__) -logging.getLogger("pyrogram").setLevel(logging.WARNING) - -if __name__ == "__main__": - CloudBot().run() - diff --git a/bot/filetocloud.py b/bot/filetocloud.py deleted file mode 100644 index c07904a..0000000 --- a/bot/filetocloud.py +++ /dev/null @@ -1,33 +0,0 @@ - -from pyrogram import * -import datetime -from bot import ( - BOT_TOKEN, - APP_ID, - API_HASH, - LOGGER -) - -class CloudBot(Client): - - def __init__(self): - name = self.__class__.__name__.lower() - - super().__init__( - name, - api_id=APP_ID, - api_hash=API_HASH, - bot_token=BOT_TOKEN, - plugins={ - "root": "bot/plugins" - } - ) - - async def start(self): - await super().start() - LOGGER.info(f"BOT IS STARTED {datetime.datetime.now()}") - print(f"BOT IS STARTED ") - - async def stop(self, *args): - LOGGER.info(f"BOT IS STOPPED {datetime.datetime.now()}") - await super().stop() diff --git a/bot/plugins/cmd/cmd.py b/bot/plugins/cmd/cmd.py deleted file mode 100644 index f27338e..0000000 --- a/bot/plugins/cmd/cmd.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python3 -# This is bot coded by Abhijith N T and used for educational purposes only -# https://github.com/AbhijithNT -# Copyright ABHIJITH N T -# Thank you https://github.com/pyrogram/pyrogram - -from bot.filetocloud import CloudBot, filters -from bot import Msg - -@CloudBot.on_message(filters.command("start")) -async def start_message(client, message): - await client.send_message( - chat_id=message.chat.id, - text=f"Hey {message.from_user.first_name},{Msg.start}{Msg.source}", - reply_to_message_id=message.message_id, - parse_mode="html" - ) -@CloudBot.on_message(filters.command(["help", "h"])) -async def help_message(client, message): - await client.send_message( - chat_id=message.chat.id, - text=f"Hey {message.from_user.first_name},{Msg.help}{Msg.source}", - reply_to_message_id=message.message_id, - parse_mode="html" - ) diff --git a/bot/plugins/display/__init__.py b/bot/plugins/display/__init__.py deleted file mode 100644 index dcef875..0000000 --- a/bot/plugins/display/__init__.py +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env python3 -# This is bot coded by Abhijith N T and used for educational purposes only -# https://github.com/AbhijithNT -# Copyright ABHIJITH N T -# Thank you https://github.com/pyrogram/pyrogram - - -from hurry.filesize import size -from bot.plugins.display.time import time_data -import time - - -async def progress(current, total, up_msg, message, start_time): - - time_now = time.time() - time_diff = time_now - start_time - percent = round(current * 100 // total) - progress_ = "{0} {1}%".format( - progressBar(percent), - f"{current * 100 / total:.1f}" - ) - time_ = "Time: {0}".format( - time_data(start_time) - ) - - speed_ = "Speed: {0}".format( - human_readable_size(size=current / time_diff) - ) - download_ = "{0} of {1}".format( - human_readable_size(current), - human_readable_size(total) - ) - try: - - await message.edit( - text=f"{progress_}\n{download_}\n{speed_} {time_}" - ) - - except Exception as e: - await message.edit( - text=f"ERROR: {e}" - ) - - -def progressBar(percent): - done_block = '█' - empty_block = '░' - return f"{done_block * int(percent / 5)}{empty_block * int(20 - int(percent / 5))}" - - -def human_readable_size(size, decimal_places=2): - for unit in ['B', 'KiB', 'MiB', 'GiB', 'TiB']: - if size < 1024.0: - break - size /= 1024.0 - return f"{size:.{decimal_places}f}{unit}" diff --git a/bot/plugins/display/time.py b/bot/plugins/display/time.py deleted file mode 100644 index cb67d8d..0000000 --- a/bot/plugins/display/time.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python3 -# This is bot coded by Abhijith N T and used for educational purposes only -# https://github.com/AbhijithNT -# Copyright ABHIJITH N T - -import time - - -def time_data(start_time): - end = time.time() - now = end - start_time - now_time = now - day = now_time // (24 * 3600) - now_time = now_time % (24 * 3600) - hour = now_time // 3600 - now_time %= 3600 - minutes = now_time // 60 - now_time %= 60 - seconds = now_time - if day != 0: - return "%dd %dh %dm %ds" % (day, hour, minutes, seconds) - if hour != 0: - return "%dh %dm %ds" % (hour, minutes, seconds) - else: - return "%dm %ds" % (minutes, seconds) diff --git a/bot/plugins/helpers/call_back.py b/bot/plugins/helpers/call_back.py deleted file mode 100644 index 1f4a47f..0000000 --- a/bot/plugins/helpers/call_back.py +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env python3 -# This is bot coded by Abhijith N T and used for educational purposes only -# https://github.com/AbhijithNT -# Copyright ABHIJITH N T -# Thank you https://github.com/pyrogram/pyrogram -from bot.filetocloud import CloudBot -from bot.plugins.helpers.dowloader import fileDownload - - -@CloudBot.on_callback_query() -async def server_selection(client, server): - await fileDownload(client, server) diff --git a/bot/plugins/helpers/dowloader.py b/bot/plugins/helpers/dowloader.py deleted file mode 100644 index 029d570..0000000 --- a/bot/plugins/helpers/dowloader.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python3 -# This is bot coded by AbhijithNT and used for educational purposes only -# https://github.com/AbhijithNT -# Copyright ABHIJITH N T -# Thank you https://github.com/pyrogram/pyrogram - - - - -import os -import time -from bot import LOGGER -from ..display import progress -from pyrogram.errors import FloodWait -from ..upload_servers import fileIO, transferSH, gofileIO, anonymFiles - -async def fileDownload(client, bot): - file_path = '' - now = time.time() - upload_server = bot.data - user_message = await client.edit_message_text( - chat_id=bot.from_user.id, - message_id=bot.message.message_id, - text="processing your request...please wait", - ) - - user_progress = user_message - - try: - file_path = await client.download_media( - message=user_message.reply_to_message, - progress=progress, - progress_args=( - "Downloading...", - user_progress, - now - ) - ) - except FloodWait as e: - LOGGER.info(f"{e}") - print(time.sleep(e.x)) - - - if upload_server == "File.io": - await fileIO(file_path, client, user_progress, now) - if upload_server == "transfersh": - await transferSH(file_path, client, user_progress, now) - if upload_server == "gofileio": - await gofileIO(file_path, client, user_progress, now) - if upload_server == "anonymfiles": - await anonymFiles(file_path, client, user_progress, now) - - - try: - os.remove(file_path) - LOGGER.info(f"{file_path}") - except OSError as error: - LOGGER.info(f"Error: {error.filename} - {error.strerror}.") - print("Error: %s - %s." % (error.filename, error.strerror)) diff --git a/bot/plugins/helpers/incoming_messages.py b/bot/plugins/helpers/incoming_messages.py deleted file mode 100644 index c870f6f..0000000 --- a/bot/plugins/helpers/incoming_messages.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python3 -# This is bot coded by Abhijith N T and used for educational purposes only -# https://github.com/AbhijithNT -# Copyright ABHIJITH N T -# Thank you https://github.com/pyrogram/pyrogram - - -from ...filetocloud import CloudBot -from bot import LOGGER -from hurry.filesize import size -from ..keyboard import server_select -from ..use import VIDEO, DOCUMENT, AUDIO - - -@CloudBot.on_message(VIDEO) -async def userVideo(client, bot): - LOGGER.info(f"{bot.chat.id} - {bot.video.file_name}") - await client.send_message( - chat_id=bot.chat.id, - text=( - f"File Name: {bot.video.file_name}" - f"\nFile Size: {size(bot.video.file_size)}" - ), - reply_markup=server_select(), - reply_to_message_id=bot.message_id - ) - - -@CloudBot.on_message(DOCUMENT) -async def userDocument(client, bot): - LOGGER.info(f"{bot.chat.id} - {bot.document.file_name}") - await client.send_message( - chat_id=bot.chat.id, - text=( - f"File Name: {bot.document.file_name}" - f"\nFile Size: {size(bot.document.file_size)}" - ), - reply_markup=server_select(), - reply_to_message_id=bot.message_id - ) - - -@CloudBot.on_message(AUDIO) -async def userAudio(client, bot): - LOGGER.info(f"{bot.chat.id} - {bot.audio.file_name}") - await client.send_message( - chat_id=bot.chat.id, - text=( - f"File Name: {bot.audio.file_name}" - f"\nFile Size: {size(bot.audio.file_size)}" - ), - reply_markup=server_select(), - reply_to_message_id=bot.message_id - ) diff --git a/bot/plugins/keyboard/__init__.py b/bot/plugins/keyboard/__init__.py deleted file mode 100644 index 8b6b667..0000000 --- a/bot/plugins/keyboard/__init__.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python3 -# This is bot coded by Abhijith N T and used for educational purposes only -# https://github.com/AbhijithNT -# Copyright ABHIJITH N T -# Thank you https://github.com/pyrogram/pyrogram - -from pyrogram.types import ( - InlineKeyboardMarkup, - InlineKeyboardButton -) - - -def server_select(): - upload_selection = [ - [ - InlineKeyboardButton( - "transfer.sh", - callback_data="transfersh" - ), - InlineKeyboardButton( - "File.io", - callback_data="File.io" - ) - ], - [ - InlineKeyboardButton( - "gofile.io", - callback_data="gofileio" - ), - InlineKeyboardButton( - "anonymfiles.com", - callback_data="anonymfiles" - ) - ] - ] - return InlineKeyboardMarkup(upload_selection) - - -def completedKeyboard(dl): - replayMarkup = InlineKeyboardMarkup( - [[ - InlineKeyboardButton( - "DOWNLOAD URL", - url=f"{dl}" - ) - ], - [ - InlineKeyboardButton( - "🗂 SOURCE", - url="https://github.com/AbhijithNT/" - ) - ]]) - - return replayMarkup diff --git a/bot/plugins/upload_servers/__init__.py b/bot/plugins/upload_servers/__init__.py deleted file mode 100644 index c6df3cc..0000000 --- a/bot/plugins/upload_servers/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from .fileio_upload import fileIO -from .gofileio import gofileIO -from .transfersh import transferSH -from .anonymfiles import anonymFiles \ No newline at end of file diff --git a/bot/plugins/upload_servers/anonymfiles.py b/bot/plugins/upload_servers/anonymfiles.py deleted file mode 100644 index 8480e4d..0000000 --- a/bot/plugins/upload_servers/anonymfiles.py +++ /dev/null @@ -1,52 +0,0 @@ - -import os -import aiohttp -from bot import LOGGER -from hurry.filesize import size -from ..keyboard import completedKeyboard -from bot.plugins.display.time import time_data - - -client_except = ( - aiohttp.ClientResponseError, - aiohttp.ClientConnectionError, - aiohttp.ClientPayloadError, -) - - -async def anonymFiles(file, client, bot, s_time): - file_size = size(os.path.getsize(file)) - file_name = file.split('/')[-1] - await client.edit_message_text( - chat_id=bot.from_user.id, - message_id=bot.message_id, - text="Uploading to anonymfiles.com" - ) - try: - async with aiohttp.ClientSession() as session: - files = { - 'file': open(file, 'rb') - } - response = await session.post('https://api.anonfiles.com/upload', data=files) - dlj = await response.json() - dl = dlj['data']['file']['url']['short'] - await client.edit_message_text( - chat_id=bot.from_user.id, - message_id=bot.message_id, - text=f"Uploaded...100% in {time_data(s_time)}" - ) - await client.send_message( - chat_id=bot.chat.id, - text=( - f"File Name: {file_name}" - f"\nFile Size: {file_size}" - ), - reply_markup=completedKeyboard(dl) - ) - except client_except as e: - await client.edit_message_text( - chat_id=bot.from_user.id, - message_id=bot.message_id, - text=f"{e}" - ) - LOGGER.info(f"{bot.from_user.id} - anonymfiles.com - file_size - {e}") diff --git a/bot/plugins/upload_servers/fileio_upload.py b/bot/plugins/upload_servers/fileio_upload.py deleted file mode 100644 index cfe7f41..0000000 --- a/bot/plugins/upload_servers/fileio_upload.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/env python3 -# This is bot coded by Abhijith N T and used for educational purposes only -# https://github.com/AbhijithNT -# Copyright ABHIJITH N T -# Thank you https://github.com/pyrogram/pyrogram - - - - -import os -import aiohttp -from bot import LOGGER -from hurry.filesize import size -from ..keyboard import completedKeyboard -from bot.plugins.display.time import time_data - -client_exceptions = ( - aiohttp.ClientResponseError, - aiohttp.ClientConnectionError, - aiohttp.ClientPayloadError, -) - - -async def fileIO(file, client, bot, s_time): - file_size = size(os.path.getsize(file)) - file_name = file.split('/')[-1] - try: - await client.edit_message_text( - chat_id=bot.from_user.id, - message_id=bot.message_id, - text="Uploading to File.IO" - ) - async with aiohttp.ClientSession() as session: - files = { - 'file': open(file, 'rb') - } - response = await session.post('https://file.io/', data=files) - - link = await response.json() - dl = link['link'] - await client.edit_message_text( - chat_id=bot.from_user.id, - message_id=bot.message_id, - text=f"Uploaded...100% in {time_data(s_time)}" - ) - - await client.send_message( - chat_id=bot.chat.id, - text=( - f"File Name: {file_name}" - f"\nFile Size: {file_size}" - ), - reply_markup=completedKeyboard(dl) - ) - except client_exceptions as e: - await client.edit_message_text( - chat_id=bot.from_user.id, - message_id=bot.message_id, - text=f"{e}" - ) - LOGGER.info(f"{bot.from_user.id} - fileIO - file_size - {e}") diff --git a/bot/plugins/upload_servers/gofileio.py b/bot/plugins/upload_servers/gofileio.py deleted file mode 100644 index a8d4815..0000000 --- a/bot/plugins/upload_servers/gofileio.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env python3 -# This is bot coded by Abhijith N T and used for educational purposes only -# https://github.com/AbhijithNT -# Copyright ABHIJITH N T -# Thank you https://github.com/pyrogram/pyrogram - - -import os -import aiohttp -from bot import LOGGER -from hurry.filesize import size -from ..keyboard import completedKeyboard -from bot.plugins.display.time import time_data - - -client_except = ( - aiohttp.ClientResponseError, - aiohttp.ClientConnectionError, - aiohttp.ClientPayloadError, -) - - -async def gofileIO(file, client, bot, s_time): - file_size = size(os.path.getsize(file)) - file_name = file.split('/')[-1] - await client.edit_message_text( - chat_id=bot.from_user.id, - message_id=bot.message_id, - text="Uploading to gofile.io" - ) - try: - async with aiohttp.ClientSession() as session: - files = { - 'file': open(file, 'rb') - } - respose = await session.post('https://store9.gofile.io/uploadFile', data=files) - dlj = await respose.json() - dl = dlj['data']['downloadPage'] - await client.edit_message_text( - chat_id=bot.from_user.id, - message_id=bot.message_id, - text=f"Uploaded...100% in {time_data(s_time)}" - ) - await client.send_message( - chat_id=bot.chat.id, - text=( - f"File Name: {file_name}" - f"\nFile Size: {file_size}" - ), - reply_markup=completedKeyboard(dl) - ) - except client_except as e: - await client.edit_message_text( - chat_id=bot.from_user.id, - message_id=bot.message_id, - text=f"{e}" - ) - LOGGER.info(f"{bot.from_user.id} - gofileIO - file_size - {e}") diff --git a/bot/plugins/upload_servers/mixdrop_upload.py b/bot/plugins/upload_servers/mixdrop_upload.py deleted file mode 100644 index 9073197..0000000 --- a/bot/plugins/upload_servers/mixdrop_upload.py +++ /dev/null @@ -1,76 +0,0 @@ -# #!/usr/bin/env python3 -# # This is bot coded by Abhijith N T and used for educational purposes only -# # https://github.com/AbhijithNT -# # Copyright ABHIJITH N T -# # Thank you https://github.com/pyrogram/pyrogram - - -# import aiohttp -# import os -# import time -# from bot import LOGGER -# from hurry.filesize import size -# from pyrogram.errors import FloodWait -# from pyrogram.types import ( -# InlineKeyboardMarkup, -# InlineKeyboardButton -# ) -# from bot.plugins.display.time import time_data -# from bot import ( -# API_KEY, -# API_EMAIL -# ) - -# env_email, env_api_key = API_EMAIL, API_KEY - - -# async def mixFileup(file, client, bot, s_time): -# # https://github.com/odysseusmax/uploads/blob/master/mixdrop.py -# file_size = size(os.path.getsize(file)) -# file_name = file.split('/')[-1] -# try: -# await client.edit_message_text( -# chat_id=bot.from_user.id, -# message_id=bot.message_id, -# text="Uploading to MixDrop..." -# ) -# email = env_email -# api_key = env_api_key -# upload_url = "https://ul.mixdrop.co/api" -# async with aiohttp.ClientSession() as session: -# data = { -# 'file': open(file, 'rb'), -# 'email': email, -# 'key': api_key -# } -# response = await session.post(upload_url, data=data) -# link = await response.json() -# await client.edit_message_text( -# chat_id=bot.from_user.id, -# message_id=bot.message_id, -# text=f"Uploaded...100% in {time_data(s_time)}" -# ) -# dl_b = f"https://mixdrop.co/f/{link['result']['fileref']}" -# await client.send_message( -# chat_id=bot.chat.id, -# text=( -# f"File Name: {file_name}" -# f"\nFile Size: {file_size}" -# ), -# reply_markup=InlineKeyboardMarkup( -# [[ -# InlineKeyboardButton( -# "DOWNLOAD URL", -# url=f"{dl_b}" -# ) -# ], -# [ -# InlineKeyboardButton( -# "🗂 SOURCE", -# url="https://github.com/AbhijithNT/" -# ) -# ]]) -# ) -# except FloodWait as e: -# LOGGER.info(f"FILE UPLOAD ERROR: {e}") -# print(time.sleep(e.x)) diff --git a/bot/plugins/upload_servers/transfersh.py b/bot/plugins/upload_servers/transfersh.py deleted file mode 100644 index ea82d93..0000000 --- a/bot/plugins/upload_servers/transfersh.py +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env python3 -# This is bot coded by Abhijith N T and used for educational purposes only -# https://github.com/AbhijithNT -# Copyright ABHIJITH N T -# Thank you https://github.com/pyrogram/pyrogram - - - - -import os -import aiohttp -from bot import LOGGER -from hurry.filesize import size -from bot.plugins.display.time import time_data -from ..keyboard import completedKeyboard - -# error -client_exceptions = ( - aiohttp.ClientResponseError, - aiohttp.ClientConnectionError, - aiohttp.ClientPayloadError, -) - - -async def transferSH(file, client, bot, s_time): - file_size = size(os.path.getsize(file)) - file_name = file.split('/')[-1] - await client.edit_message_text( - chat_id=bot.from_user.id, - message_id=bot.message_id, - text="Uploading to Transfer.sh" - ) - try: - async with aiohttp.ClientSession() as session: - files = {'file': open(file, 'rb')} - response = await session.post('http://transfer.sh', data=files) - dl = await response.text() - await client.edit_message_text( - chat_id=bot.from_user.id, - message_id=bot.message_id, - text=f"Uploaded...100% in {time_data(s_time)}" - ) - await client.send_message( - chat_id=bot.chat.id, - text=( - f"File Name: {file_name}" - f"\nFile Size: {file_size}" - ), - reply_markup=completedKeyboard(dl) - ) - except client_exceptions as e: - await client.edit_message_text( - chat_id=bot.from_user.id, - message_id=bot.message_id, - text=f"{e}" - ) - LOGGER.info(f"{bot.from_user.id} - transferSH - file_size - {e}") diff --git a/bot/plugins/use/__init__.py b/bot/plugins/use/__init__.py deleted file mode 100644 index 4fb5c83..0000000 --- a/bot/plugins/use/__init__.py +++ /dev/null @@ -1,15 +0,0 @@ -from bot import BOT_USE -from ...filetocloud import filters -from bot import AUTH_USER - - - -if BOT_USE: - AUTH_USER.append(429320566) - VIDEO = filters.video & filters.user(AUTH_USER) - DOCUMENT = filters.document & filters.user(AUTH_USER) - AUDIO = filters.audio & filters.user(AUTH_USER) -else: - VIDEO = filters.video - DOCUMENT = filters.document - AUDIO = filters.audio From 8e01d658334451af4eed351ce3c0590e3d7b6961 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:07:39 +0530 Subject: [PATCH 02/31] remove version --- requirements.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index dd6db7e..7a574a9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ -Pyrogram~=1.1.13 +Pyrogram TgCrypto -aiohttp~=3.7.3 -hurry.filesize \ No newline at end of file +aiohttp +hurry.filesize +python-dotenv \ No newline at end of file From ef58f66401a5373372b47a3edd4f880721dae1e7 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:07:56 +0530 Subject: [PATCH 03/31] old files --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index cccf3d6..e26d5a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ -#Bot Logger +#Bot log.txt +old #22 *.session # Byte-compiled / optimized / DLL files From f78da9cdd2be4c9e55d9a74bc35bfa96929a8e03 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:08:15 +0530 Subject: [PATCH 04/31] init --- bot/__init__.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 bot/__init__.py diff --git a/bot/__init__.py b/bot/__init__.py new file mode 100644 index 0000000..43bde05 --- /dev/null +++ b/bot/__init__.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +# This is bot coded by Abhijith N T and used for educational purposes only +# https://github.com/AbhijithNT +# Copyright ABHIJITH N T +# Thank you https://github.com/pyrogram/pyrogram + +import logging +from .env import get_env +from logging.handlers import RotatingFileHandler + +API_ID = get_env('API_ID') +API_HASH = get_env('API_HASH') +BOT_TOKEN = get_env('BOT_TOKEN') + +# LOGGER + +logging.basicConfig( + level=logging.INFO, + format="[%(asctime)s - %(levelname)s] - %(name)s - %(message)s", + datefmt='%d-%b-%y %H:%M:%S', + handlers=[ + RotatingFileHandler('tmdb_log.txt', maxBytes=50000000, backupCount=10), + logging.StreamHandler() + ]) +logging.getLogger('pyrogram').setLevel(logging.WARNING) + + +def LOGGER(log: str) -> logging.Logger: + """Logger function""" + return logging.getLogger(log) + + +# import os +# import logging + +# logging.basicConfig(level=logging.INFO, +# handlers=[logging.FileHandler( +# 'log.txt'), logging.StreamHandler()], +# format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" +# ) +# LOGGER = logging.getLogger(__name__) +# logging.getLogger("pyrogram").setLevel(logging.WARNING) + +# ENV = bool(os.environ.get('ENV', False)) +# try: +# if ENV: +# AUTH_USER = [] +# BOT_TOKEN = os.environ.get('BOT_TOKEN') +# APP_ID = os.environ.get('APP_ID') +# API_HASH = os.environ.get('API_HASH') +# BOT_USE = bool(os.environ.get('BOT_USE', False)) +# GET_AUTH_USER = os.environ.get('AUTH_USER') +# for i in GET_AUTH_USER.split(','): +# AUTH_USER.append(int(i)) +# else: +# from sample_config import Config + +# BOT_TOKEN = Config.BOT_TOKEN +# APP_ID = Config.APP_ID +# API_HASH = Config.API_HASH +# BOT_USE = Config.BOT_USE +# AUTH_USER = Config.AUTH_USERS +# except KeyError: +# LOGGER.error('One or more configuration values are missing exiting now.') +# exit(1) + + +# class Msg: +# source = "\nsource: https://github.com/AbhijithNT/TelegramFiletoCloud" +# start = "\nThis bot uploads telegram files to MixDrop.co,File.io.\nAdmin: @thankappan369" +# error = "something is went wrong\n{error} \ncontact admin @thankappan369" +# help = "Usage: Send any file and the bot will upload it to MixDrop.co,File.io" From 831819b4b825ba959bd1cefdb9327c7ead5a182d Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:08:35 +0530 Subject: [PATCH 05/31] run me --- bot/__main__.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 bot/__main__.py diff --git a/bot/__main__.py b/bot/__main__.py new file mode 100644 index 0000000..dcd223f --- /dev/null +++ b/bot/__main__.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +# This is bot coded by AbhijithCloud and used for educational purposes only +# https://github.com/AbhijithNT +# Copyright ABHIJITH N T +# Thank you https://github.com/pyrogram/pyrogram + +import pyrogram +from bot.filetocloud import CloudBot +import logging +logging.basicConfig( + level=logging.DEBUG, + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" +) +LOGGER = logging.getLogger(__name__) +logging.getLogger("pyrogram").setLevel(logging.WARNING) + +if __name__ == "__main__": + CloudBot().run() + From 65d798287eaac1a0989ddf72825a0c90e1bc4408 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:09:04 +0530 Subject: [PATCH 06/31] environment variables --- bot/env.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 bot/env.py diff --git a/bot/env.py b/bot/env.py new file mode 100644 index 0000000..22871d1 --- /dev/null +++ b/bot/env.py @@ -0,0 +1,12 @@ +import os +from dotenv import load_dotenv +load_dotenv() + +def get_env(name: str, terminal_action: bool = True) -> str: + if name in os.environ: + return os.environ[name] + if terminal_action: + value_name = input(f'Enter your {name}: ') + return value_name + else: + return name \ No newline at end of file From 523b22ffbb6d183b6f8237979882f55fc8f0cd70 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:09:16 +0530 Subject: [PATCH 07/31] logger --- bot/filetocloud.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 bot/filetocloud.py diff --git a/bot/filetocloud.py b/bot/filetocloud.py new file mode 100644 index 0000000..df1c763 --- /dev/null +++ b/bot/filetocloud.py @@ -0,0 +1,33 @@ + +from pyrogram import * +import datetime +from bot import ( + BOT_TOKEN, + API_ID, + API_HASH, + LOGGER +) + + +class CloudBot(Client): + def __init__(self): + name = self.__class__.__name__.lower() + self.logger = LOGGER(__name__) + + super().__init__( + name, + api_id=API_ID, + api_hash=API_HASH, + bot_token=BOT_TOKEN, + plugins={ + "root": "bot/plugins" + } + ) + + async def start(self): + await super().start() + self.logger.info(f"BOT IS STARTED {datetime.datetime.now()}") + + async def stop(self, *args): + await super().stop() + self.logger.info(f"BOT IS STOPPED {datetime.datetime.now()}") From 41432e94177b307b308bf08a01b34368e9156cc1 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:13:16 +0530 Subject: [PATCH 08/31] init messages --- bot/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bot/__init__.py b/bot/__init__.py index 43bde05..18898b9 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -12,6 +12,15 @@ API_HASH = get_env('API_HASH') BOT_TOKEN = get_env('BOT_TOKEN') + +#messages + +SOURCE = "\nsource: https://github.com/AbhijithNT/TelegramFiletoCloud" +START = "\nThis bot uploads telegram files to MixDrop.co,File.io.\nAdmin: @thankappan369" +ERROR = "something is went wrong\n{error} \ncontact admin @thankappan369" +HELP = "Usage: Send any file and the bot will upload it to MixDrop.co,File.io" + + # LOGGER logging.basicConfig( From a575f9feaf2b618ee338fae065b065fe2848cda0 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:30:54 +0530 Subject: [PATCH 09/31] ignore logs --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e26d5a2..a4b3705 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ #Bot -log.txt +*.txt old #22 *.session From cd6ecb550ff2c300de1c43ca40119dfb4e6904c8 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:31:16 +0530 Subject: [PATCH 10/31] logger filename --- bot/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bot/__init__.py b/bot/__init__.py index 18898b9..309eabb 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -13,7 +13,7 @@ BOT_TOKEN = get_env('BOT_TOKEN') -#messages +# messages SOURCE = "\nsource: https://github.com/AbhijithNT/TelegramFiletoCloud" START = "\nThis bot uploads telegram files to MixDrop.co,File.io.\nAdmin: @thankappan369" @@ -23,12 +23,14 @@ # LOGGER +LOGGER_FILE_NAME = "filetocloud_log.txt" logging.basicConfig( level=logging.INFO, format="[%(asctime)s - %(levelname)s] - %(name)s - %(message)s", datefmt='%d-%b-%y %H:%M:%S', handlers=[ - RotatingFileHandler('tmdb_log.txt', maxBytes=50000000, backupCount=10), + RotatingFileHandler( + LOGGER_FILE_NAME, maxBytes=50000000, backupCount=10), logging.StreamHandler() ]) logging.getLogger('pyrogram').setLevel(logging.WARNING) From 2f75524ff8aa89e5d3def43bf068c7faf357b0d4 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:32:13 +0530 Subject: [PATCH 11/31] creating a .env file --- bot/env.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bot/env.py b/bot/env.py index 22871d1..0154398 100644 --- a/bot/env.py +++ b/bot/env.py @@ -2,11 +2,14 @@ from dotenv import load_dotenv load_dotenv() + def get_env(name: str, terminal_action: bool = True) -> str: if name in os.environ: return os.environ[name] if terminal_action: - value_name = input(f'Enter your {name}: ') - return value_name + value = input(f'Enter your {name}: ') + with open('.env', 'a') as f: + f.write(f'{name}={value}\n') + return value else: - return name \ No newline at end of file + return name From 40617d406bd9d1c46d5e225842883afb6c737490 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:32:37 +0530 Subject: [PATCH 12/31] help message --- bot/plugins/commands/help.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 bot/plugins/commands/help.py diff --git a/bot/plugins/commands/help.py b/bot/plugins/commands/help.py new file mode 100644 index 0000000..b066b94 --- /dev/null +++ b/bot/plugins/commands/help.py @@ -0,0 +1,12 @@ +from bot.filetocloud import CloudBot, filters +from bot import HELP, SOURCE + + +@CloudBot.on_message(filters.command(["help", "h"])) +async def help_message(client, message): + await client.send_message( + chat_id=message.chat.id, + text=f"Hey {message.from_user.first_name},{HELP}{SOURCE}", + reply_to_message_id=message.message_id, + parse_mode="html" + ) From 0d8464d9bfe735a87d1ce66428211c0e5b562f39 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:32:51 +0530 Subject: [PATCH 13/31] start message --- bot/plugins/commands/start.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 bot/plugins/commands/start.py diff --git a/bot/plugins/commands/start.py b/bot/plugins/commands/start.py new file mode 100644 index 0000000..5943f04 --- /dev/null +++ b/bot/plugins/commands/start.py @@ -0,0 +1,12 @@ +from bot.filetocloud import CloudBot, filters +from bot import START, SOURCE + + +@CloudBot.on_message(filters.command("start")) +async def start_message(client, message): + await client.send_message( + chat_id=message.chat.id, + text=f"Hey {message.from_user.first_name},{START}{SOURCE}", + reply_to_message_id=message.message_id, + parse_mode="html" + ) From 114a722b0205b2e627321ff8f2fec5469202e1a1 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:54:14 +0530 Subject: [PATCH 14/31] inline keyboard --- bot/helpers/__init__.py | 1 + bot/helpers/keyboard.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 bot/helpers/__init__.py create mode 100644 bot/helpers/keyboard.py diff --git a/bot/helpers/__init__.py b/bot/helpers/__init__.py new file mode 100644 index 0000000..3124b9c --- /dev/null +++ b/bot/helpers/__init__.py @@ -0,0 +1 @@ +from .keyboard import server_select \ No newline at end of file diff --git a/bot/helpers/keyboard.py b/bot/helpers/keyboard.py new file mode 100644 index 0000000..511b1e4 --- /dev/null +++ b/bot/helpers/keyboard.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +# This is bot coded by Abhijith N T and used for educational purposes only +# https://github.com/AbhijithNT +# Copyright ABHIJITH N T +# Thank you https://github.com/pyrogram/pyrogram + +from pyrogram.types import ( + InlineKeyboardMarkup, + InlineKeyboardButton +) + + +def server_select(): + upload_selection = [ + [ + InlineKeyboardButton( + "transfer.sh", + callback_data="transfersh" + ), + InlineKeyboardButton( + "File.io", + callback_data="File.io" + ) + ], + [ + InlineKeyboardButton( + "gofile.io", + callback_data="gofileio" + ), + InlineKeyboardButton( + "anonymfiles.com", + callback_data="anonymfiles" + ) + ] + ] + return InlineKeyboardMarkup(upload_selection) From 83f29d88bea71faaaa29f3ae022980015f49efff Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:54:52 +0530 Subject: [PATCH 15/31] handling user messages --- bot/plugins/utils/media_handling.py | 70 +++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 bot/plugins/utils/media_handling.py diff --git a/bot/plugins/utils/media_handling.py b/bot/plugins/utils/media_handling.py new file mode 100644 index 0000000..7c9928c --- /dev/null +++ b/bot/plugins/utils/media_handling.py @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 +# This is bot coded by Abhijith N T and used for educational purposes only +# https://github.com/AbhijithNT +# Copyright ABHIJITH N T +# Thank you https://github.com/pyrogram/pyrogram + + +from ...filetocloud import CloudBot, filters +from bot import LOGGER +from hurry.filesize import size +from ...helpers import server_select +# from ..use import VIDEO, DOCUMENT, AUDIO + +BOT_USE = False +AUTH_USER: list + +if BOT_USE: + AUTH_USER.append(429320566) + VIDEO = filters.video & filters.user(AUTH_USER) + DOCUMENT = filters.document & filters.user(AUTH_USER) + AUDIO = filters.audio & filters.user(AUTH_USER) +else: + VIDEO = filters.video + DOCUMENT = filters.document + AUDIO = filters.audio + + +logger = LOGGER(__name__) + + +@CloudBot.on_message(VIDEO) +async def userVideo(client, bot): + logger.info(f"{bot.chat.id} - {bot.video.file_name}") + await client.send_message( + chat_id=bot.chat.id, + text=( + f"File Name: {bot.video.file_name}" + f"\nFile Size: {size(bot.video.file_size)}" + ), + reply_markup=server_select(), + reply_to_message_id=bot.message_id + ) + + +@CloudBot.on_message(DOCUMENT) +async def userDocument(client, bot): + logger.info(f"{bot.chat.id} - {bot.document.file_name}") + await client.send_message( + chat_id=bot.chat.id, + text=( + f"File Name: {bot.document.file_name}" + f"\nFile Size: {size(bot.document.file_size)}" + ), + reply_markup=server_select(), + reply_to_message_id=bot.message_id + ) + + +@CloudBot.on_message(AUDIO) +async def userAudio(client, bot): + logger.info(f"{bot.chat.id} - {bot.audio.file_name}") + await client.send_message( + chat_id=bot.chat.id, + text=( + f"File Name: {bot.audio.file_name}" + f"\nFile Size: {size(bot.audio.file_size)}" + ), + reply_markup=server_select(), + reply_to_message_id=bot.message_id + ) From e2bc100abcaea538a4233e55bdd1b27574e59670 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 17:55:44 +0530 Subject: [PATCH 16/31] user selection --- bot/plugins/utils/callback.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 bot/plugins/utils/callback.py diff --git a/bot/plugins/utils/callback.py b/bot/plugins/utils/callback.py new file mode 100644 index 0000000..9910989 --- /dev/null +++ b/bot/plugins/utils/callback.py @@ -0,0 +1,8 @@ +from ...filetocloud import CloudBot +from pyrogram.types import CallbackQuery + + + +@CloudBot.on_callback_query() +async def selecting_server(client: CloudBot, message: CallbackQuery) -> None: + print(message) \ No newline at end of file From 3fdf6d9f2685144e355e6c0b3395a19b15cf597b Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 20:00:33 +0530 Subject: [PATCH 17/31] download progress --- bot/helpers/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bot/helpers/__init__.py b/bot/helpers/__init__.py index 3124b9c..1c6488a 100644 --- a/bot/helpers/__init__.py +++ b/bot/helpers/__init__.py @@ -1 +1,3 @@ -from .keyboard import server_select \ No newline at end of file +from .keyboard import server_select +from .file_download import download_media +from .display import progress \ No newline at end of file From 8dcd5e19e38f6c1ee427e5c89f52d637eca63d1e Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 20:00:58 +0530 Subject: [PATCH 18/31] download progress --- bot/helpers/display.py | 58 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 bot/helpers/display.py diff --git a/bot/helpers/display.py b/bot/helpers/display.py new file mode 100644 index 0000000..650e7ba --- /dev/null +++ b/bot/helpers/display.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# This is bot coded by Abhijith N T and used for educational purposes only +# https://github.com/AbhijithNT +# Copyright ABHIJITH N T +# Thank you https://github.com/pyrogram/pyrogram + + + +from hurry.filesize import size +from .time import time_data +import time +from pyrogram.types import Message + + +async def progress(current, total, up_msg, message: Message, start_time): + + time_now = time.time() + time_diff = time_now - start_time + percent = round(current * 100 // total) + progress_ = "{0} {1}%".format( + progressBar(percent), + f"{current * 100 / total:.1f}" + ) + time_ = "Time: {0}".format( + time_data(start_time) + ) + + speed_ = "Speed: {0}".format( + human_readable_size(size=current / time_diff) + ) + download_ = "{0} of {1}".format( + human_readable_size(current), + human_readable_size(total) + ) + try: + + await message.edit( + text=f"{progress_}\n{download_}\n{speed_} {time_}" + ) + + except Exception as e: + await message.edit( + text=f"ERROR: {e}" + ) + + +def progressBar(percent): + done_block = '█' + empty_block = '░' + return f"{done_block * int(percent / 5)}{empty_block * int(20 - int(percent / 5))}" + + +def human_readable_size(size, decimal_places=2): + for unit in ['B', 'KiB', 'MiB', 'GiB', 'TiB']: + if size < 1024.0: + break + size /= 1024.0 + return f"{size:.{decimal_places}f}{unit}" From 437496ef22f64e2a0fe02c0f59122714bd0a9398 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 20:01:30 +0530 Subject: [PATCH 19/31] telegram media download --- bot/helpers/file_download.py | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 bot/helpers/file_download.py diff --git a/bot/helpers/file_download.py b/bot/helpers/file_download.py new file mode 100644 index 0000000..a0a5648 --- /dev/null +++ b/bot/helpers/file_download.py @@ -0,0 +1,40 @@ +import time +from bot import LOGGER +from ..filetocloud import CloudBot +from pyrogram.errors import RPCError +from pyrogram.types import CallbackQuery +from ..helpers.display import progress +# from ..helpers import progress + + +logger = LOGGER(__name__) + + +async def download_media(client: CloudBot, message: CallbackQuery, ) -> str: + # client.download_media(message) + now = time.time() + user_message = await client.edit_message_text( + chat_id=message.from_user.id, + message_id=message.message.message_id, + text="processing your request...please wait", + ) + try: + media_id = message.message.reply_to_message + download_file_path = await client.download_media(media_id, + progress=progress, + progress_args=( + "Downloading...", + user_message, + now + ) + ) + print(download_file_path) + return download_file_path + except RPCError as e: + logger.error(e) + client.edit_message_text( + chat_id=message.from_user.id, + message_id=message.message.message_id, + text="Someting is error", + ) + return From 5a22697c75fbfc5a78bfaccd00c4b897eb9aa5fb Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 20:01:56 +0530 Subject: [PATCH 20/31] change callback data --- bot/helpers/keyboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/helpers/keyboard.py b/bot/helpers/keyboard.py index 511b1e4..f1c312d 100644 --- a/bot/helpers/keyboard.py +++ b/bot/helpers/keyboard.py @@ -19,7 +19,7 @@ def server_select(): ), InlineKeyboardButton( "File.io", - callback_data="File.io" + callback_data="fileio" ) ], [ From e2dcd95029894366f81cc1401d332b72212a450e Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 20:03:25 +0530 Subject: [PATCH 21/31] time format --- bot/helpers/time.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 bot/helpers/time.py diff --git a/bot/helpers/time.py b/bot/helpers/time.py new file mode 100644 index 0000000..cb67d8d --- /dev/null +++ b/bot/helpers/time.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +# This is bot coded by Abhijith N T and used for educational purposes only +# https://github.com/AbhijithNT +# Copyright ABHIJITH N T + +import time + + +def time_data(start_time): + end = time.time() + now = end - start_time + now_time = now + day = now_time // (24 * 3600) + now_time = now_time % (24 * 3600) + hour = now_time // 3600 + now_time %= 3600 + minutes = now_time // 60 + now_time %= 60 + seconds = now_time + if day != 0: + return "%dd %dh %dm %ds" % (day, hour, minutes, seconds) + if hour != 0: + return "%dh %dm %ds" % (hour, minutes, seconds) + else: + return "%dm %ds" % (minutes, seconds) From 1ac754d90f30b918d7018604f3bc867cd7d2f896 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 20:04:04 +0530 Subject: [PATCH 22/31] download media from the user --- bot/plugins/utils/callback.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bot/plugins/utils/callback.py b/bot/plugins/utils/callback.py index 9910989..5c8e439 100644 --- a/bot/plugins/utils/callback.py +++ b/bot/plugins/utils/callback.py @@ -1,8 +1,14 @@ +from logging import fatal from ...filetocloud import CloudBot from pyrogram.types import CallbackQuery - +from ...helpers import download_media @CloudBot.on_callback_query() async def selecting_server(client: CloudBot, message: CallbackQuery) -> None: - print(message) \ No newline at end of file + callback_data = message.data + if callback_data.startswith('transfersh'): + f = await download_media( + client, + message + ) From 442274fafb131fdafe61092ede25a7b81a1e5530 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 20:59:23 +0530 Subject: [PATCH 23/31] error handling --- bot/helpers/file_download.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bot/helpers/file_download.py b/bot/helpers/file_download.py index a0a5648..c46b86a 100644 --- a/bot/helpers/file_download.py +++ b/bot/helpers/file_download.py @@ -32,9 +32,9 @@ async def download_media(client: CloudBot, message: CallbackQuery, ) -> str: return download_file_path except RPCError as e: logger.error(e) - client.edit_message_text( - chat_id=message.from_user.id, - message_id=message.message.message_id, - text="Someting is error", - ) - return + # client.edit_message_text( + # chat_id=message.from_user.id, + # message_id=message.message.message_id, + # text="Someting is error", + # ) + raise Exception(e) From 12f80ed8d32bb26c75d8b6dd72a656765f2b5d89 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 20:59:53 +0530 Subject: [PATCH 24/31] call back conditions --- bot/plugins/utils/callback.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bot/plugins/utils/callback.py b/bot/plugins/utils/callback.py index 5c8e439..ed1e3f3 100644 --- a/bot/plugins/utils/callback.py +++ b/bot/plugins/utils/callback.py @@ -2,13 +2,17 @@ from ...filetocloud import CloudBot from pyrogram.types import CallbackQuery from ...helpers import download_media +from ...helpers.servers import anonfiles @CloudBot.on_callback_query() async def selecting_server(client: CloudBot, message: CallbackQuery) -> None: callback_data = message.data if callback_data.startswith('transfersh'): - f = await download_media( - client, - message - ) + await anonfiles(client, message) + elif callback_data.startswith('fileio'): + pass + elif callback_data.startswith('gofileio'): + pass + elif callback_data.startswith('anonymfiles'): + pass From b484c614dfcece1b496a033a94bef9a1fa54a094 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 21:00:37 +0530 Subject: [PATCH 25/31] file upload --- bot/helpers/upload.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 bot/helpers/upload.py diff --git a/bot/helpers/upload.py b/bot/helpers/upload.py new file mode 100644 index 0000000..87877bb --- /dev/null +++ b/bot/helpers/upload.py @@ -0,0 +1,20 @@ +import aiohttp +import asyncio + +loop = asyncio.get_event_loop() +client_exceptions = ( + aiohttp.ClientResponseError, + aiohttp.ClientConnectionError, + aiohttp.ClientPayloadError, +) + + +async def server_upload(url: str, file: str): + try: + async with aiohttp.ClientSession() as session: + files = {'file': open(file, 'rb')} + response = await session.post(url, data=files) + responce_json = await response.json() + return responce_json + except client_exceptions as e: + raise Exception(e) From 542b526d908dc576365c84ca8f874c7b4bb80b78 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 21:01:10 +0530 Subject: [PATCH 26/31] anonfiles server --- bot/helpers/servers.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 bot/helpers/servers.py diff --git a/bot/helpers/servers.py b/bot/helpers/servers.py new file mode 100644 index 0000000..59ce6f8 --- /dev/null +++ b/bot/helpers/servers.py @@ -0,0 +1,22 @@ +from json import decoder +from ..filetocloud import CloudBot +import aiohttp +from .upload import server_upload +from ..helpers import download_media +from pyrogram.types import CallbackQuery + + +async def anonfiles(client: CloudBot, message: CallbackQuery): + + try: + FILE_PATH = await download_media(client, "message") + except Exception as e: + print(e) + + return + try: + url = 'https://api.anonfiles.com/upload' + d = await server_upload(file="filetocloud_log.txt", url=url) + print(d) + except Exception as e: + print(f"ERROR: {e}") From 0487005fdd2f3156591ab36e739684b060630fd9 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 22:45:13 +0530 Subject: [PATCH 27/31] add file info to callback data --- bot/helpers/keyboard.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bot/helpers/keyboard.py b/bot/helpers/keyboard.py index f1c312d..acadd8c 100644 --- a/bot/helpers/keyboard.py +++ b/bot/helpers/keyboard.py @@ -10,26 +10,26 @@ ) -def server_select(): +def server_select(file_name: str, size: str): upload_selection = [ [ InlineKeyboardButton( "transfer.sh", - callback_data="transfersh" + callback_data=f'transfersh|{file_name}|{size}' ), InlineKeyboardButton( "File.io", - callback_data="fileio" + callback_data=f"fileio|{file_name}|{size}" ) ], [ InlineKeyboardButton( "gofile.io", - callback_data="gofileio" + callback_data=f"gofileio|{file_name}|{size}" ), InlineKeyboardButton( "anonymfiles.com", - callback_data="anonymfiles" + callback_data=f"anonymfiles|{file_name}|{size}" ) ] ] From 17826748d699c5819c0c44245825d5a04e68b39a Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 22:45:57 +0530 Subject: [PATCH 28/31] upload_handler() --- bot/helpers/servers.py | 73 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/bot/helpers/servers.py b/bot/helpers/servers.py index 59ce6f8..aa8007c 100644 --- a/bot/helpers/servers.py +++ b/bot/helpers/servers.py @@ -1,22 +1,75 @@ -from json import decoder +from bot import LOGGER from ..filetocloud import CloudBot -import aiohttp from .upload import server_upload from ..helpers import download_media from pyrogram.types import CallbackQuery +logger = LOGGER(__name__) -async def anonfiles(client: CloudBot, message: CallbackQuery): + +async def upload_handler(client: CloudBot, message: CallbackQuery, file_name: str, file_size: str, callback_data: str): try: - FILE_PATH = await download_media(client, "message") + FILE_PATH = await download_media(client, message) except Exception as e: - print(e) - + logger.error(f"{e}") + await client.edit_message_text( + chat_id=message.from_user.id, + message_id=message.message.message_id, + text=f"**File downloading error:** `{e}`", + ) return try: - url = 'https://api.anonfiles.com/upload' - d = await server_upload(file="filetocloud_log.txt", url=url) - print(d) + if callback_data.startswith('transfersh'): + await client.edit_message_text( + chat_id=message.message.chat.id, + text="Temporarily down", + message_id=message.message.message_id, + ) + return + + elif callback_data.startswith('gofileio'): + url = 'https://store9.gofile.io/uploadFile' + response = await server_upload(file=FILE_PATH, url=url) + _URL = await gofileIO(response) + + elif callback_data.startswith('fileio'): + url = 'https://file.io/' + response = await server_upload(file=FILE_PATH, url=url) + _URL = await fileIO(response) + + elif callback_data.startswith('anonfiles'): + url = 'https://api.anonfiles.com/upload' + response = await server_upload(file=FILE_PATH, url=url) + _URL = await anonfiles(response) + + await client.edit_message_text( + chat_id=message.message.chat.id, + text=( + f"File Name: `{file_name}`" + f"\nFile Size: `{file_size}`" + f'\nURL: `{_URL}`' + ), + message_id=message.message.message_id + # reply_markup=completedKeyboard(dl) + ) except Exception as e: - print(f"ERROR: {e}") + logger.error(f'{e}') + await client.edit_message_text( + chat_id=message.from_user.id, + message_id=message.message.message_id, + text=f"**File uploading error:** `{e}`", + ) + return + + +async def anonfiles(response): + return response['data']['file']['url']['short'] + + +async def fileIO(response): + return response['link'] + + +async def gofileIO(response): + return response['data']['downloadPage'] From 610e38b64ef01ac0cd2ef78fbdf749a3e76613cf Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 22:46:56 +0530 Subject: [PATCH 29/31] conditions --- bot/plugins/utils/callback.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bot/plugins/utils/callback.py b/bot/plugins/utils/callback.py index ed1e3f3..33ebc70 100644 --- a/bot/plugins/utils/callback.py +++ b/bot/plugins/utils/callback.py @@ -2,17 +2,19 @@ from ...filetocloud import CloudBot from pyrogram.types import CallbackQuery from ...helpers import download_media -from ...helpers.servers import anonfiles +from ...helpers.servers import upload_handler @CloudBot.on_callback_query() async def selecting_server(client: CloudBot, message: CallbackQuery) -> None: callback_data = message.data + file_name, file_size = callback_data.split( + '|')[1], callback_data.split('|')[2] if callback_data.startswith('transfersh'): - await anonfiles(client, message) + await upload_handler(client, message, file_name, file_size, callback_data) elif callback_data.startswith('fileio'): - pass + await upload_handler(client, message, file_name, file_size, callback_data) elif callback_data.startswith('gofileio'): - pass + await upload_handler(client, message, file_name, file_size, callback_data) elif callback_data.startswith('anonymfiles'): - pass + await upload_handler(client, message, file_name, file_size, callback_data) From fba4af4bd0002ef13ad394e4c3c0470047055c87 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 22:47:22 +0530 Subject: [PATCH 30/31] add file info to callback data --- bot/plugins/utils/media_handling.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/bot/plugins/utils/media_handling.py b/bot/plugins/utils/media_handling.py index 7c9928c..e2bf889 100644 --- a/bot/plugins/utils/media_handling.py +++ b/bot/plugins/utils/media_handling.py @@ -31,13 +31,15 @@ @CloudBot.on_message(VIDEO) async def userVideo(client, bot): logger.info(f"{bot.chat.id} - {bot.video.file_name}") + file_name = bot.video.file_name + file_size = size(bot.video.file_size) await client.send_message( chat_id=bot.chat.id, text=( - f"File Name: {bot.video.file_name}" - f"\nFile Size: {size(bot.video.file_size)}" + f"File Name: `{file_name}`" + f"File Size: `{file_size}`" ), - reply_markup=server_select(), + reply_markup=server_select(file_name,file_size), reply_to_message_id=bot.message_id ) @@ -45,13 +47,15 @@ async def userVideo(client, bot): @CloudBot.on_message(DOCUMENT) async def userDocument(client, bot): logger.info(f"{bot.chat.id} - {bot.document.file_name}") + file_name = bot.document.file_name + file_size = size(bot.document.file_size) await client.send_message( chat_id=bot.chat.id, text=( - f"File Name: {bot.document.file_name}" - f"\nFile Size: {size(bot.document.file_size)}" + f"File Name: `{file_name}`" + f"File Size: `{file_size}`" ), - reply_markup=server_select(), + reply_markup=server_select(file_name,file_size), reply_to_message_id=bot.message_id ) @@ -59,12 +63,14 @@ async def userDocument(client, bot): @CloudBot.on_message(AUDIO) async def userAudio(client, bot): logger.info(f"{bot.chat.id} - {bot.audio.file_name}") + file_name = bot.audio.file_name + file_size = size(bot.audio.file_size) await client.send_message( chat_id=bot.chat.id, text=( - f"File Name: {bot.audio.file_name}" - f"\nFile Size: {size(bot.audio.file_size)}" + f"File Name: `{file_name}`" + f"\nFile Size: {file_size}" ), - reply_markup=server_select(), + reply_markup=server_select(file_name,file_size), reply_to_message_id=bot.message_id ) From c15964d712715b201484da6d5844931c257d5262 Mon Sep 17 00:00:00 2001 From: AbhijithNT Date: Sat, 4 Dec 2021 22:52:51 +0530 Subject: [PATCH 31/31] gofile server change (#36) --- bot/helpers/servers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/helpers/servers.py b/bot/helpers/servers.py index aa8007c..91759fa 100644 --- a/bot/helpers/servers.py +++ b/bot/helpers/servers.py @@ -29,7 +29,7 @@ async def upload_handler(client: CloudBot, message: CallbackQuery, file_name: st return elif callback_data.startswith('gofileio'): - url = 'https://store9.gofile.io/uploadFile' + url = 'https://store1.gofile.io/uploadFile' response = await server_upload(file=FILE_PATH, url=url) _URL = await gofileIO(response)