From 1ad5f78de20db3584c9375961bf2bb883a12f447 Mon Sep 17 00:00:00 2001 From: Wrench <65120517+JyothisJayanth@users.noreply.github.com> Date: Sat, 17 Apr 2021 19:26:26 +0530 Subject: [PATCH] :rocket: Added Heroku Support - Added Heroku Support - Added a Readme since the repo page was looking so bad. - Removed unused variables --- Procfile | 1 + README.md | 149 ++++++++++++++++++++++++++++++++++++++++ WebStreamer/__main__.py | 6 +- WebStreamer/vars.py | 15 ++-- app.json | 68 ++++++++++++++++++ requirements.txt | 4 ++ 6 files changed, 233 insertions(+), 10 deletions(-) create mode 100644 Procfile create mode 100644 README.md create mode 100644 app.json create mode 100644 requirements.txt diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..9a79e65 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: python -m WebStreamer \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..46a39dd --- /dev/null +++ b/README.md @@ -0,0 +1,149 @@ +

Telegram File Stream Bot

+

+ + Cover Image + +

+ A Telegram bot to stream files to web +
+ Telegram Bot » +
+ Report a Bug + | + Request Feature +

+

+ +
+ +
+ Table of Contents +
    +
  1. + About this Bot + +
  2. +
  3. + How to make your own + +
  4. +
  5. Setting up things
  6. + +
  7. How to use the bot
  8. +
  9. Contributing
  10. +
  11. Contact me
  12. +
  13. Credits
  14. +
+
+ +## About This Bot + +

+ + Telegram Logo + +

+

+ This bot will give you stream links for Telegram files without the need of waiting till the download completes +

+ +### Original Repository + +The main working part was taken from [Megatron](https://github.com/eyaadh/megadlbot_oss) and thanks to [eyaadh](https://github.com/eyaadh) for his awesome project. + +## How to make your own + +Either you could locally host or deploy on [Heroku](https://heroku.com) + +### Deploy on Heroku + +Press the below button to Fast deply to Heroky + +[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) + +then goto the variables tab for more info on setting up environmental variables. + +### Host it on VPS or Locally + +```sh +git clone https://github.com/EverythingSuckz/TG-FlieStreamBot +cd TG-FlieStreamBot +virtualenv -p /usr/bin/python3 venv +. ./venv/bin/activate +pip install -r requirements.txt +python3 -m WebStreamer +``` + +and to stop the whole bot, + do CTRL+C + +## Setting up things + +If you're on Heroku, just add these in the Environmental Variables +or if you're Locally hosting, create a file named `.env` in the root directory and add all the variables there. +An example of `.env` file: + +```sh +API_ID=452525 +API_HASH=esx576f8738x883f3sfzx83 +BOT_TOKEN=55838383:yourtbottokenhere +BIN_CHANNEL=-100 +PORT=8080 +FQDN=yourserverip +``` + +### Mandatory Vars + +`API_ID` : Goto [my.telegram.org](https://my.telegram.org) to obtain this. + +`API_HASH` : Goto [my.telegram.org](https://my.telegram.org) to obtain this. + +`BOT_TOKEN` : Get the bot token from [@BotFather](https://telegram.dog/BotFather) + +`BIN_CHANNEL` : Create a new channel (private/public), add [@missrose_bot](https://telegram.dog/MissRose_bot) as admin to the channel and type /id. Now copy paste the ID into this field. + + +### Optional Vars + +`SLEEP_THRESHOLD` : Set a sleep threshold for flood wait exceptions happening globally in this telegram bot instance, below which any request that raises a flood wait will be automatically invoked again after sleeping for the required amount of time. Flood wait exceptions requiring higher waiting times will be raised. Defaults to 60 seconds. + +`WORKERS` : Number of maximum concurrent workers for handling incoming updates. Defaults to `3` + +`PORT` : The port that you want your webapp to be listened to. Defaults to `8080` + +`WEB_SERVER_BIND_ADDRESS` : Your server bind adress. Defauls to `0.0.0.0` + +`FQDN` : A Fully Qualified Domain Name if present. Defaults to `WEB_SERVER_BIND_ADDRESS` + +## How to use the bot + +:warning: **Before using the bot, don't forget to add the bot to the `BIN_CHANNEL` as an admin** + +`/start` : To check if the bot is alive or not. + +To get an instant stream link, just forward any media to the bot and boom, its fast af. + +## Contributing + +Feel free to contribute to this project if you have any further ideas + +## Contact me + +[![Telegram Channel](https://img.shields.io/static/v1?label=Join&message=Telegram%20Channel&color=blueviolet&style=for-the-badge&logo=telegram&logoColor=violet)](https://xn--r1a.click/WhySooSerious) +[![Telegram Group](https://img.shields.io/static/v1?label=Join&message=Telegram%20Channel&color=blueviolet&style=for-the-badge&logo=telegram&logoColor=violet)](https://xn--r1a.click/WhyThisUsername) + +You can contact either via my [Telegram Chat](https://xn--r1a.click/WhyThisUsername) or you can PM me on [@EverythingSuckz](https://xn--r1a.click/EverythingSuckz) + +## Credits + +- Me +- [eyaadh](https://github.com/eyaadh) for his awesome [Megatron Bot](https://github.com/eyaadh/megadlbot_oss) +- [Dan Tès](https://telegram.dog/haskell) for his [Pyrogram Library](https://github.com/pyrogram/pyrogram) \ No newline at end of file diff --git a/WebStreamer/__main__.py b/WebStreamer/__main__.py index 793d0bc..31830fb 100644 --- a/WebStreamer/__main__.py +++ b/WebStreamer/__main__.py @@ -14,7 +14,7 @@ from .vars import Var from aiohttp import web from .server import web_server -ppath = f"WebStreamer/bot/plugins/*.py" +ppath = "WebStreamer/bot/plugins/*.py" files = glob.glob(ppath) loop = asyncio.get_event_loop() @@ -43,12 +43,14 @@ async def start_services(): print('------------------- Initalizing Web Server -------------------') app = web.AppRunner(await web_server()) await app.setup() - bind_address = "0.0.0.0" if Var.ENV else Var.FQDN + bind_address = "0.0.0.0" if Var.ON_HEROKU else Var.FQDN await web.TCPSite(app, bind_address, Var.PORT).start() print('\n') print('----------------------- Service Started -----------------------') print(' bot =>> {}'.format((await StreamBot.get_me()).first_name)) print(' server ip =>> {}:{}'.format(bind_address, Var.PORT)) + if Var.ON_HEROKU: + print(' app runnng on =>> {}'.format(Var.FQDN)) print('---------------------------------------------------------------') await idle() diff --git a/WebStreamer/vars.py b/WebStreamer/vars.py index f61a32c..4129bfe 100644 --- a/WebStreamer/vars.py +++ b/WebStreamer/vars.py @@ -7,19 +7,18 @@ from dotenv import load_dotenv load_dotenv() class Var(object): - ENV = bool(getenv('ENV', False)) API_ID = int(getenv('API_ID')) API_HASH = str(getenv('API_HASH')) BOT_TOKEN = str(getenv('BOT_TOKEN')) - SLEEP_THRESHOLD = int(getenv('SLEEP_THRESHOLD', '300')) + SLEEP_THRESHOLD = int(getenv('SLEEP_THRESHOLD', '60')) WORKERS = int(getenv('WORKERS', '3')) - BIN_CHANNEL = int(getenv('BIN_CHANNEL', None)) - FQDN = str(getenv('FQDN', 'localhost')) + BIN_CHANNEL = int(getenv('BIN_CHANNEL', None)) PORT = int(getenv('PORT', 8080)) - BIND_ADRESS = str(getenv('BIND_ADRESS', '0.0.0.0')) - CACHE_DIR = str(getenv('CACHE_DIR', 'WebStreamer/bot/cache')) - OWNER_ID = int(getenv('OWNER_ID')) + BIND_ADRESS = str(getenv('WEB_SERVER_BIND_ADDRESS', '0.0.0.0')) + OWNER_ID = int(getenv('OWNER_ID', None)) #TODO if 'DYNO' in environ: ON_HEROKU = True + APP_NAME = str(getenv('APP_NAME')) else: - ON_HEROKU = False \ No newline at end of file + ON_HEROKU = False + FQDN = str(getenv('FQDN', BIND_ADRESS)) if not ON_HEROKU else APP_NAME+'.herokuapp.com' \ No newline at end of file diff --git a/app.json b/app.json new file mode 100644 index 0000000..b566e6e --- /dev/null +++ b/app.json @@ -0,0 +1,68 @@ +{ + "name": "TG-FlieStreamBot", + "description": "A Pyrogram Telegram bot to Stream Telegram files to web.", + "keywords": [ + "telegram", + "stream", + "web", + "pyrogram", + "aiohttp", + "python", + "plugin", + "modular", + "media" + ], + "repository": "https://github.com/EverythingSuckz/TG-FlieStreamBot", + "success_url": "https://telegram.dog/WhyThisUsername", + "website": "stream.wrench.gq", + "env": { + "ENV": { + "description": "Set this to True if you don't want to crash the bot", + "value": "True" + }, + "APP_NAME": { + "description": "Copy-Paste the app name that you just typed above." + }, + "API_ID": { + "description": "Get this value from https://my.telegram.org" + }, + "API_HASH": { + "description": "Get this value from https://my.telegram.org" + }, + "BOT_TOKEN": { + "description": "Get this value from @BotFather" + }, + "BIN_CHANNEL": { + "description": "The BIN Channel ID. Read the readme for more info about this var" + }, + "SLEEP_THRESHOLD": { + "description": "Floodwait Sleep timer. Read the readme for more info about this var", + "required": false + }, + "WORKERS": { + "description": "No. of workers that is to be assigned. Read the readme for more info about this var", + "required": false + }, + "PORT": { + "description": "Port that you want your webapp to be listened to. Read the readme for more info about this var", + "required": false + }, + "BIND_ADRESS": { + "description": "Read the readme for more info about this var", + "required": false + }, + "FQDN": { + "description": "Read the readme for more info about this var", + "required": false + } + }, + "buildpacks": [{ + "url": "heroku/python" + }], + "formation": { + "worker": { + "quantity": 1, + "size": "free" + } + } + } \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..2c40272 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +pyrogram +tgcrypto +aiohttp +python-dotenv \ No newline at end of file