├── .gitignore ├── LICENSE ├── README.md ├── bot.py ├── rclone-v1.53.0-windows-amd64.zip ├── result.gif └── result.mp4 /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Shubham0Rajput 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rclone-Telegram-Bot 2 | This is Rclone Bot in Telegram made for your ease. 3 | Code has been updated for latest Python [CODE](https://github.com/Shubham0Rajput/Rclone-Telegram-Bot/blob/master/bot(12-September-2020).py) 4 | 5 | 6 | Step 1. Copy code to your VPS or local machine 7 | --------------------------------- 8 | _Before everything, install python3. Because we use python as our programing language._ 9 | 10 | ### Download Rclone ### 11 | 12 | * For Linux system: Install 13 | [latest rclone](https://rclone.org/downloads/#script-download-and-install). 14 | If in Debian/Ubuntu, directly use this command 15 | ``` 16 | sudo apt-get install screen git && curl https://rclone.org/install.sh | sudo bash 17 | ``` 18 | After all dependency above are successfully installed, run this command 19 | ``` 20 | sudo git clone https://github.com/xyou365/AutoRclone && cd AutoRclone && sudo pip3 install -r requirements.txt 21 | ``` 22 | 23 | * For Window system: Install 24 | [latest rclone](https://rclone.org/downloads/) 25 | 26 | * Bot Along with Rclone files 27 | [Download](https://github.com/Shubham0Rajput/Rclone-Telegram-Bot/blob/master/rclone-v1.53.0-windows-amd64.zip) 28 | 29 | * For anyother OS 30 | [RCLONE DOWNLOAD](https://rclone.org/downloads/) 31 | 32 | ### Download Python Telegram Bot ### 33 | You can install or upgrade python-telegram-bot with: 34 | ``` 35 | $ pip install python-telegram-bot --upgrade 36 | ``` 37 | Or you can install from source with: 38 | ``` 39 | $ git clone https://github.com/python-telegram-bot/python-telegram-bot --recursive 40 | $ cd python-telegram-bot 41 | $ python setup.py install 42 | ``` 43 | In case you have a previously cloned local repository already, you should initialize the added urllib3 submodule before installing with: 44 | ``` 45 | $ git submodule update --init --recursive 46 | ``` 47 | Step 2. Prerequisite For Starting The Bot 48 | --------------------------------- 49 | * Configure the Rclone like- adding the drive to rclone 50 | * Add this to config file 51 | ``` 52 | server_side_across_configs = true 53 | ``` 54 | To find the location of Rclone Config File type 55 | ``` 56 | rclone config file 57 | ``` 58 | * Also Install Some pip files 59 | ``` 60 | pip install subprocess.run 61 | ``` 62 | ``` 63 | pip install subprocess32 64 | ``` 65 | subprocess is updated recently 66 | 67 | Step 3. Start The Bot 68 | --------------------------------- 69 | * Complete the code by adding your Drive details ** Line-38,235 for best experience ** also Line-42,230 for best experience 70 | * Copy the Bot where rclone.exe is present(in case of windows) 71 | * Just run bot anywhere in case of Linux 72 | * Open Terminal or CMD in the directory/folder where the bot.py is stored 73 | To start bot type 74 | ``` 75 | python bot.py 76 | ``` 77 | HOW TO USE THIS BOT! 78 | --------------------------------- 79 | * ### /start ### 80 | This command to check is bot runing or not 81 | 82 | * ### /help ### 83 | To Know About the Commands and How to use them 84 | * ### /rclone [command] 85 | To Run Shell or Rclone Command, for example to list folder in drive1 86 | ``` 87 | /rclone lsf --csv "drive1" 88 | ``` 89 | Don't run copy command it will ####BAN your bot 90 | * ### /rclonecopy [command] ### 91 | To Copy Files from drive1 to drive2, for example 92 | ``` 93 | /rclonecopy rclone copy drive1:subfolder drive2:subfolder -P 94 | ``` 95 | * ### /folder ### 96 | To Show Inline View of Folder in Drive 97 | Change it to your drive before Running the Code 98 | 99 | * ### /backup ### 100 | To Create the Backup 101 | i.e 102 | ``` 103 | /backup 104 | ``` 105 | ![](https://github.com/Shubham0Rajput/Rclone-Telegram-Bot/blob/master/result.gif) 106 | -------------------------------------------------------------------------------- /bot.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import time 3 | import os 4 | import re 5 | from subprocess import Popen, PIPE 6 | from datetime import date 7 | from telegram import ReplyKeyboardRemove 8 | from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackQueryHandler 9 | from telegram import InlineKeyboardButton, InlineKeyboardMarkup,ReplyKeyboardRemove 10 | 11 | 12 | logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',level=logging.INFO) 13 | logger = logging.getLogger(__name__) 14 | 15 | 16 | def start(update, context): 17 | update.message.reply_text('Hi! To Authorize do /password [password] ') 18 | 19 | 20 | def help(update, context): 21 | update.message.reply_text('/start- To Start the Bot \n /help- To Know About the Commands \n ' 22 | '/rclone [COMMAND]- To Run Shell or Rclone Command (except copy) \n' 23 | '/rclonecopy [COMMAND]- To Copy Files \n' 24 | '/folder- To Inline View of Folder in Drive \n' 25 | '/password [PASSWORD]- To Get Authorize \n' 26 | '/adminpasswprd [Password]- To authorize to use rclone and rclonecopy \n' 27 | '/backup- to create backup to other drive \n') 28 | 29 | 30 | def error(update, context): 31 | logger.warning('Update "%s" caused error "%s"', update, context.error) 32 | 33 | 34 | def createfile(): 35 | f=open("user.txt","w") 36 | f.close() 37 | 38 | 39 | if os.path.exists("user.txt") == False : 40 | createfile() 41 | 42 | 43 | def createfileA(): 44 | f=open("userA.txt","w") 45 | f.close() 46 | 47 | 48 | if os.path.exists("userA.txt") == False : 49 | createfileA() 50 | 51 | 52 | def folder(update, context): 53 | if os.path.exists("adress.txt") == True : 54 | os.remove("adress.txt") 55 | if os.path.exists("link.txt") == True : 56 | os.remove("link.txt") 57 | f=open("adress.txt","w") 58 | command='____________RCLONE COMMAND FOR FOLDER VIEW______________' 59 | f.write(command) 60 | f.close() 61 | f=open("link.txt","w") 62 | linkp='______________HTTP LINK OF BOT_____________' 63 | f.write(linkp) 64 | f.close() 65 | key = [] 66 | del key[:] 67 | inID=update.message.from_user.id 68 | checku(update, context, inID) 69 | if flag==True: 70 | for path in run(command): 71 | print path 72 | key.append([InlineKeyboardButton(path,callback_data=path)]) 73 | 74 | key.append([InlineKeyboardButton("Cancel", callback_data="Cancel")]) 75 | reply_markup = InlineKeyboardMarkup(key) 76 | update.effective_message.reply_text('Please choose:', reply_markup=reply_markup) 77 | else : 78 | update.message.reply_text("Enter Password!!") 79 | 80 | 81 | def button(update, context): 82 | query = update.callback_query 83 | query.edit_message_text(text="Selected option: {}".format(query.data)) 84 | txt = query.data 85 | x = re.findall("/$", txt) 86 | if (x): 87 | f = open("adress.txt", "a") 88 | f.write(txt) 89 | f.close() 90 | f = open("link.txt", "a") 91 | f.write(txt) 92 | f.close() 93 | folder1(update, context) 94 | if "Cancel" ==txt: 95 | return 96 | if ['/'] != x: 97 | f = open("link.txt", "r") 98 | link=f.readlines() 99 | f.close() 100 | addr=str(link[0]) 101 | addr=addr+str(txt) 102 | addr=addr.replace(" ","%20") 103 | update.effective_message.reply_text("Link:{}".format(addr)) 104 | 105 | 106 | def folder1(update, context): 107 | 108 | f = open("adress.txt", "r") 109 | command=f.readline() 110 | f.close() 111 | key = [] 112 | del key[:] 113 | print command 114 | for path in run(command): 115 | print path 116 | key.append([InlineKeyboardButton(path,callback_data=path)]) 117 | key.append([InlineKeyboardButton("Cancel", callback_data="Cancel")]) 118 | reply_markup = InlineKeyboardMarkup(key) 119 | update.effective_message.reply_text('Please choose:', reply_markup=reply_markup) 120 | 121 | 122 | def checku(update, context, inID): 123 | f = open("user.txt", "r") 124 | global flag 125 | flag=False 126 | t1= '\n' 127 | ch= str(inID)+ t1 128 | for x in f: 129 | if x==ch : 130 | print "User Found" 131 | flag=True 132 | else : 133 | print "User Not Found" 134 | 135 | 136 | def checkuA(update, context, inID): 137 | f = open("userA.txt", "r") 138 | global flagA 139 | flagA=False 140 | t1= '\n' 141 | ch= str(inID)+ t1 142 | for x in f: 143 | if x==ch : 144 | print "User Found" 145 | flagA=True 146 | else : 147 | print "User Not Found" 148 | 149 | 150 | def addu(update, context, Uid): 151 | f = open("user.txt", "a") 152 | t2='\n' 153 | txt=str(Uid)+t2 154 | print txt 155 | f.write(txt) 156 | f.close() 157 | f = open("user.txt", "r") 158 | print(f.readlines()) 159 | 160 | 161 | def adduA(update, context, Uid): 162 | f = open("userA.txt", "a") 163 | t2='\n' 164 | txt=str(Uid)+t2 165 | print txt 166 | f.write(txt) 167 | f.close() 168 | f = open("userA.txt", "r") 169 | print(f.readlines()) 170 | 171 | 172 | def rclone(update, context): 173 | txt=update.message.text 174 | if "/rclone" == txt.strip()[:7]: 175 | command = " ".join(txt.strip().split(" ")[1:]) 176 | else : 177 | update.message.reply_text("Enter Correct Command") 178 | inID=update.message.from_user.id 179 | checkuA(update, context, inID) 180 | if flagA == True : 181 | for path in run(command): 182 | print path 183 | update.message.reply_text(path) 184 | else: 185 | update.message.reply_text("Enter Admin Password!") 186 | 187 | 188 | def rclonecopy(update, context): 189 | txt=update.message.text 190 | if "/rclonecopy" == txt.strip()[:11]: 191 | command = " ".join(txt.strip().split(" ")[1:]) 192 | else : 193 | update.message.reply_text("Enter Correct Command") 194 | inID=update.message.from_user.id 195 | checkuA(update, context, inID) 196 | if flagA == True : 197 | rclonecopyprocess(update, context, command) 198 | else: 199 | update.message.reply_text("Enter Admin Password!") 200 | update.message.reply_text("Done!!") 201 | 202 | 203 | def rclonecopyprocess(update, context, command): 204 | bot = context.bot 205 | message=update.message.reply_text("STATUS") 206 | mid=message.message_id 207 | percent="" 208 | percent1="" 209 | working="" 210 | working1="" 211 | prog="" 212 | for toutput in run(command): 213 | print toutput 214 | y= re.findall("^Transferred:", toutput) 215 | z= re.findall("^ * ", toutput) 216 | if (y): 217 | val=str(toutput) 218 | val=val.split(",") 219 | percent=str(val[1]) 220 | statu=val[1].replace("%","") 221 | if statu != " -": 222 | statu=int(statu) 223 | prog=status(statu) 224 | 225 | if (z): 226 | working=str(toutput) 227 | 228 | if working1 != working or percent1 != percent : 229 | bot.edit_message_text(chat_id=message.chat_id,message_id=mid,text="{} \n {} \n {}".format(percent,prog,working)) 230 | percent1=percent 231 | working1=working 232 | 233 | 234 | def status(val): 235 | if val<10 : 236 | ss= "[ ]" 237 | 238 | if val>=10 and val<=19: 239 | ss= "[# ]" 240 | 241 | if val>=20 and val<=29: 242 | ss= "[## ]" 243 | 244 | if val>=30 and val<=39: 245 | ss= "[### ]" 246 | 247 | if val>=40 and val<=49: 248 | ss= "[#### ]" 249 | 250 | if val>=50 and val<=59: 251 | ss= "[##### ]" 252 | 253 | if val>=60 and val<=69: 254 | ss= "[###### ]" 255 | 256 | if val>=70 and val<=79: 257 | ss= "[####### ]" 258 | 259 | if val>=80 and val<=89: 260 | ss= "[######## ]" 261 | 262 | if val>=90 and val<=99: 263 | ss= "[######### ]" 264 | 265 | if val==100: 266 | ss= "[##########]" 267 | return ss 268 | 269 | 270 | def run(command): 271 | process=Popen(command,stdout=PIPE,shell=True) 272 | while True: 273 | line=process.stdout.readline().rstrip() 274 | if not line: 275 | break 276 | yield line 277 | 278 | 279 | def backup(update, context): 280 | inID=update.message.from_user.id 281 | checkuA(update, context, inID) 282 | today=date.today() 283 | if flagA == True : 284 | rclonecopyprocess(update, context, '________RCLONE COMMAND TO CREATE BACKUP______________') 285 | 286 | else: 287 | update.message.reply_text("Enter Admin Password!") 288 | update.message.reply_text("Done!!") 289 | 290 | 291 | def adminpassword(update, context): 292 | txt = update.message.text 293 | 294 | if "/adminpassword" == txt.strip()[:14]: 295 | admin_password = " ".join(txt.strip().split(" ")[1:]) 296 | else : 297 | update.message.reply_text("Enter Correctly") 298 | if 'ADMINPASSWORD' == admin_password : 299 | update.message.reply_text('Correct Password') 300 | Uid=update.message.from_user.id 301 | adduA(update, context, Uid) 302 | addu(update, context, Uid) 303 | else: 304 | update.message.reply_text('Incorrect Password') 305 | 306 | 307 | def password(update, context): 308 | txt = update.message.text 309 | 310 | if "/password" == txt.strip()[:9]: 311 | used_password = " ".join(txt.strip().split(" ")[1:]) 312 | else : 313 | update.message.reply_text("Enter Correctly") 314 | if 'USERPASSWORD' == used_password : 315 | update.message.reply_text('Correct Password') 316 | Uid=update.message.from_user.id 317 | addu(update, context, Uid) 318 | else: 319 | update.message.reply_text('Incorrect Password') 320 | 321 | 322 | def main(): 323 | updater = Updater("TOKEN", use_context=True) 324 | dp = updater.dispatcher 325 | dp.add_handler(CommandHandler("start", start)) 326 | dp.add_handler(CommandHandler("help", help)) 327 | dp.add_handler(CommandHandler("rclone", rclone)) 328 | dp.add_handler(CommandHandler("rclonecopy", rclonecopy)) 329 | dp.add_handler(CommandHandler("password", password)) 330 | dp.add_handler(CommandHandler("adminpassword", adminpassword)) 331 | dp.add_handler(CommandHandler("folder", folder)) 332 | dp.add_handler(CommandHandler("backup", backup)) 333 | dp.add_handler(CallbackQueryHandler(button)) 334 | dp.add_error_handler(error) 335 | updater.start_polling() 336 | updater.idle() 337 | 338 | 339 | if __name__ == '__main__': 340 | main() 341 | -------------------------------------------------------------------------------- /rclone-v1.53.0-windows-amd64.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubham0Rajput/Rclone-Telegram-Bot/b6c2546d8fcc9437e6af8e23d8e8eb0613437472/rclone-v1.53.0-windows-amd64.zip -------------------------------------------------------------------------------- /result.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubham0Rajput/Rclone-Telegram-Bot/b6c2546d8fcc9437e6af8e23d8e8eb0613437472/result.gif -------------------------------------------------------------------------------- /result.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shubham0Rajput/Rclone-Telegram-Bot/b6c2546d8fcc9437e6af8e23d8e8eb0613437472/result.mp4 --------------------------------------------------------------------------------