-
-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
370 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#Bot Logger | ||
log.txt | ||
#Bot | ||
*.txt | ||
old | ||
#22 | ||
*.session | ||
# Byte-compiled / optimized / DLL files | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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 = input(f'Enter your {name}: ') | ||
with open('.env', 'a') as f: | ||
f.write(f'{name}={value}\n') | ||
return value | ||
else: | ||
return name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .keyboard import server_select | ||
from .file_download import download_media | ||
from .display import progress |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
# ) | ||
raise Exception(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from bot import LOGGER | ||
from ..filetocloud import CloudBot | ||
from .upload import server_upload | ||
from ..helpers import download_media | ||
from pyrogram.types import CallbackQuery | ||
|
||
logger = LOGGER(__name__) | ||
|
||
|
||
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) | ||
except Exception as 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: | ||
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://store1.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: | ||
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'] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Oops, something went wrong.