├── .gitignore ├── LICENSE ├── Procfile ├── README.md ├── gofile.py ├── main.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | **/__pycache__ 2 | *.session 3 | *.session-journal 4 | *.pyc 5 | *.env 6 | **/venv 7 | **/downloads -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Fayas Noushad 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | worker: python main.py 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GoFile Bot 2 | A telegram media to GoFile uploader bot 3 | 4 | --- 5 | 6 | ## Deploy 7 | 8 | ```sh 9 | git clone https://github.com/FayasNoushad/GoFile-Bot.git 10 | cd GoFile-Bot 11 | python3 -m venv venv 12 | . ./venv/bin/activate 13 | pip3 install -r requirements.txt 14 | # 15 | python3 main.py 16 | ``` 17 | 18 | --- 19 | 20 | ## Variables 21 | 22 | - `API_HASH` Your API Hash from my.telegram.org 23 | - `API_ID` Your API ID from my.telegram.org 24 | - `BOT_TOKEN` Your bot token from @BotFather 25 | 26 | --- 27 | 28 | ## Credits 29 | 30 | - [GoFile API](https://gofile.io/api) 31 | - [Contributors](https://github.com/FayasNoushad/GoFile-Bot/graphs/contributors) 32 | 33 | --- 34 | -------------------------------------------------------------------------------- /gofile.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | import shlex 4 | import requests 5 | import subprocess 6 | 7 | 8 | def uploadFile(file_path: str, token=None, folderId=None) -> dict: 9 | response = requests.get("https://api.gofile.io/servers/").json() 10 | servers = response["data"]["servers"] 11 | server = servers[0]["name"] 12 | cmd = "curl " 13 | cmd += f'-F "file=@{file_path}" ' 14 | if token: 15 | cmd += f'-F "token={token}" ' 16 | if folderId: 17 | cmd += f'-F "folderId={folderId}" ' 18 | cmd += f"'https://{server}.gofile.io/uploadFile'" 19 | upload_cmd = shlex.split(cmd) 20 | try: 21 | out = subprocess.check_output(upload_cmd, stderr=subprocess.STDOUT) 22 | except subprocess.CalledProcessError as e: 23 | raise Exception(e) 24 | try: 25 | os.remove(file_path) 26 | except: 27 | pass 28 | out = out.decode("UTF-8").strip() 29 | # print(out) 30 | if out: 31 | out = out.split("\n")[-1] 32 | try: 33 | response = json.loads(out) 34 | except: 35 | raise Exception("API Error (Not Vaild JSON Data Received)") 36 | if not response: 37 | raise Exception("API Error (No JSON Data Received)") 38 | else: 39 | raise Exception("API Error (No Data Received)") 40 | 41 | if response["status"] == "ok": 42 | data = response["data"] 43 | # data["directLink"] = ( 44 | # f"https://{server}.gofile.io/download/{data['id']}/{data['name']}" 45 | # ) 46 | return data 47 | elif "error-" in response["status"]: 48 | error = response["status"].split("-")[1] 49 | raise Exception(error) 50 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | import requests 3 | from dotenv import load_dotenv 4 | from gofile import uploadFile 5 | from pyrogram import Client, filters 6 | from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton 7 | 8 | 9 | load_dotenv() 10 | 11 | Bot = Client( 12 | "GoFile-Bot", 13 | bot_token=os.environ.get("BOT_TOKEN"), 14 | api_id=int(os.environ.get("API_ID")), 15 | api_hash=os.environ.get("API_HASH"), 16 | ) 17 | 18 | INSTRUCTIONS = """ 19 | I am a gofile uploader telegram bot. \ 20 | You can upload files to gofile.io with command. 21 | 22 | With media: 23 | Normal: 24 | `/upload` 25 | With token: 26 | `/upload token` 27 | With folder id: 28 | `/upload token folderid` 29 | 30 | Using Link: 31 | Normal: 32 | `/upload url` 33 | With token: 34 | `/upload url token` 35 | With folder id: 36 | `/upload url token folderid` 37 | """ 38 | 39 | 40 | @Bot.on_message(filters.private & filters.command("start")) 41 | async def start(bot, update): 42 | await update.reply_text( 43 | text=f"Hello {update.from_user.mention}," + INSTRUCTIONS, 44 | disable_web_page_preview=True, 45 | quote=True, 46 | ) 47 | 48 | 49 | @Bot.on_message(filters.private & filters.command("upload")) 50 | async def filter(_, update): 51 | 52 | message = await update.reply_text( 53 | text="`Processing...`", quote=True, disable_web_page_preview=True 54 | ) 55 | 56 | text = update.text.replace("\n", " ") 57 | url = None 58 | token = None 59 | folderId = None 60 | 61 | if " " in text: 62 | text = text.split(" ", 1)[1] 63 | if update.reply_to_message: 64 | if " " in text: 65 | token, folderId = text.split(" ", 1) 66 | else: 67 | token = text 68 | else: 69 | if " " in text: 70 | if len(text.split()) > 2: 71 | url, token, folderId = text.split(" ", 2) 72 | else: 73 | url, token = text.split() 74 | else: 75 | url = text 76 | if not (url.startswith("http://") or url.startswith("https://")): 77 | await message.edit_text("Error :- `url is wrong`") 78 | return 79 | elif not update.reply_to_message: 80 | await message.edit_text("Error :- `downloadable media or url not found`") 81 | return 82 | 83 | try: 84 | 85 | await message.edit_text("`Downloading...`") 86 | if url: 87 | response = requests.get(url) 88 | media = response.url.split("/", -1)[-1] 89 | with open(media, "wb") as file: 90 | file.write(response.content) 91 | else: 92 | media = await update.reply_to_message.download() 93 | await message.edit_text("`Downloaded Successfully`") 94 | 95 | await message.edit_text("`Uploading...`") 96 | response = uploadFile(file_path=media, token=token, folderId=folderId) 97 | await message.edit_text("`Uploading Successfully`") 98 | 99 | try: 100 | os.remove(media) 101 | except: 102 | pass 103 | 104 | except Exception as error: 105 | await message.edit_text(f"Error :- `{error}`") 106 | return 107 | 108 | text = f"**File Name:** `{response['name']}`" + "\n" 109 | text += f"**File ID:** `{response['id']}`" + "\n" 110 | text += f"**Parent Folder Code:** `{response['parentFolderCode']}`" + "\n" 111 | text += f"**Guest Token:** `{response['guestToken']}`" + "\n" 112 | text += f"**md5:** `{response['md5']}`" + "\n" 113 | text += f"**Download Page:** `{response['downloadPage']}`" 114 | link = response["downloadPage"] 115 | reply_markup = InlineKeyboardMarkup( 116 | [ 117 | [ 118 | InlineKeyboardButton(text="Open Link", url=link), 119 | InlineKeyboardButton( 120 | text="Share Link", url=f"https://telegram.me/share/url?url={link}" 121 | ), 122 | ], 123 | [ 124 | InlineKeyboardButton( 125 | text="Feedback", url="https://telegram.me/FayasNoushad" 126 | ) 127 | ], 128 | ] 129 | ) 130 | await message.edit_text( 131 | text=text, reply_markup=reply_markup, disable_web_page_preview=True 132 | ) 133 | 134 | 135 | if __name__ == "__main__": 136 | print("Bot is started working!") 137 | Bot.run() 138 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pyrogram 2 | tgcrypto 3 | requests 4 | python-dotenv 5 | --------------------------------------------------------------------------------