forked from Rishikesh-Sharma09/File-to-link
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Adarsh Goel
committed
Aug 26, 2022
0 parents
commit d3df983
Showing
34 changed files
with
2,702 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
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,26 @@ | ||
name: Notify on Telegram | ||
|
||
on: | ||
fork: | ||
push: | ||
release: | ||
issue_comment: | ||
types: created | ||
watch: | ||
types: started | ||
pull_request_review_comment: | ||
types: created | ||
pull_request: | ||
types: [opened, closed, reopened] | ||
issues: | ||
types: [opened, pinned, closed, reopened] | ||
jobs: | ||
notify: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Notify the commit on Telegram. | ||
uses: EverythingSuckz/github-telegram-notify@main | ||
with: | ||
bot_token: '${{ secrets.BOT_TOKEN }}' | ||
chat_id: '${{ secrets.CHAT_ID }}' |
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,121 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
config.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
#session files | ||
*.session | ||
WebStreamer/template/new.html | ||
WebStreamer/template/beta.html | ||
WebStreamer/template/style.css |
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,6 @@ | ||
# (c) adarsh-goel | ||
|
||
|
||
import time | ||
StartTime = time.time() | ||
__version__ = 1.1 |
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,87 @@ | ||
# (c) adarsh-goel | ||
import os | ||
import sys | ||
import glob | ||
import asyncio | ||
import logging | ||
import importlib | ||
from pathlib import Path | ||
from pyrogram import idle | ||
from .bot import StreamBot | ||
from .vars import Var | ||
from aiohttp import web | ||
from .server import web_server | ||
from .utils.keepalive import ping_server | ||
from Adarsh.bot.clients import initialize_clients | ||
|
||
logging.basicConfig( | ||
level=logging.INFO, | ||
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" | ||
) | ||
logging.getLogger("aiohttp").setLevel(logging.ERROR) | ||
logging.getLogger("pyrogram").setLevel(logging.ERROR) | ||
logging.getLogger("aiohttp.web").setLevel(logging.ERROR) | ||
|
||
ppath = "Adarsh/bot/plugins/*.py" | ||
files = glob.glob(ppath) | ||
StreamBot.start() | ||
loop = asyncio.get_event_loop() | ||
|
||
|
||
async def start_services(): | ||
print('\n') | ||
print('------------------- Initalizing Telegram Bot -------------------') | ||
bot_info = await StreamBot.get_me() | ||
StreamBot.username = bot_info.username | ||
print("------------------------------ DONE ------------------------------") | ||
print() | ||
print( | ||
"---------------------- Initializing Clients ----------------------" | ||
) | ||
await initialize_clients() | ||
print("------------------------------ DONE ------------------------------") | ||
print('\n') | ||
print('--------------------------- Importing ---------------------------') | ||
for name in files: | ||
with open(name) as a: | ||
patt = Path(a.name) | ||
plugin_name = patt.stem.replace(".py", "") | ||
plugins_dir = Path(f"Adarsh/bot/plugins/{plugin_name}.py") | ||
import_path = ".plugins.{}".format(plugin_name) | ||
spec = importlib.util.spec_from_file_location(import_path, plugins_dir) | ||
load = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(load) | ||
sys.modules["Adarsh.bot.plugins." + plugin_name] = load | ||
print("Imported => " + plugin_name) | ||
if Var.ON_HEROKU: | ||
print("------------------ Starting Keep Alive Service ------------------") | ||
print() | ||
asyncio.create_task(ping_server()) | ||
print('-------------------- Initalizing Web Server -------------------------') | ||
app = web.AppRunner(await web_server()) | ||
await app.setup() | ||
bind_address = "0.0.0.0" if Var.ON_HEROKU else Var.BIND_ADRESS | ||
await web.TCPSite(app, bind_address, Var.PORT).start() | ||
print('----------------------------- DONE ---------------------------------------------------------------------') | ||
print('\n') | ||
print('---------------------------------------------------------------------------------------------------------') | ||
print('---------------------------------------------------------------------------------------------------------') | ||
print(' follow me for more such exciting bots! https://github.com/adarsh-goel') | ||
print('---------------------------------------------------------------------------------------------------------') | ||
print('\n') | ||
print('----------------------- Service Started -----------------------------------------------------------------') | ||
print(' bot =>> {}'.format((await StreamBot.get_me()).first_name)) | ||
print(' server ip =>> {}:{}'.format(bind_address, Var.PORT)) | ||
print(' Owner =>> {}'.format((Var.OWNER_USERNAME))) | ||
if Var.ON_HEROKU: | ||
print(' app runnng on =>> {}'.format(Var.FQDN)) | ||
print('---------------------------------------------------------------------------------------------------------') | ||
print('Give a star to my repo https://github.com/adarsh-goel/filestreambot-pro also follow me for new bots') | ||
print('---------------------------------------------------------------------------------------------------------') | ||
await idle() | ||
|
||
if __name__ == '__main__': | ||
try: | ||
loop.run_until_complete(start_services()) | ||
except KeyboardInterrupt: | ||
logging.info('----------------------- Service Stopped -----------------------') |
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,17 @@ | ||
# (c) adarsh-goel | ||
from pyrogram import Client | ||
import pyromod.listen | ||
from ..vars import Var | ||
from os import getcwd | ||
|
||
StreamBot = Client( | ||
name='Web Streamer', | ||
api_id=Var.API_ID, | ||
api_hash=Var.API_HASH, | ||
bot_token=Var.BOT_TOKEN, | ||
sleep_threshold=Var.SLEEP_THRESHOLD, | ||
workers=Var.WORKERS | ||
) | ||
|
||
multi_clients = {} | ||
work_loads = {} |
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,45 @@ | ||
# (c) adarsh-goel | ||
|
||
import asyncio | ||
import logging | ||
from ..vars import Var | ||
from pyrogram import Client | ||
from Adarsh.utils.config_parser import TokenParser | ||
from . import multi_clients, work_loads, StreamBot | ||
|
||
|
||
async def initialize_clients(): | ||
multi_clients[0] = StreamBot | ||
work_loads[0] = 0 | ||
all_tokens = TokenParser().parse_from_env() | ||
if not all_tokens: | ||
print("No additional clients found, using default client") | ||
return | ||
|
||
async def start_client(client_id, token): | ||
try: | ||
print(f"Starting - Client {client_id}") | ||
if client_id == len(all_tokens): | ||
await asyncio.sleep(2) | ||
print("This will take some time, please wait...") | ||
client = await Client( | ||
name=str(client_id), | ||
api_id=Var.API_ID, | ||
api_hash=Var.API_HASH, | ||
bot_token=token, | ||
sleep_threshold=Var.SLEEP_THRESHOLD, | ||
no_updates=True, | ||
in_memory=True | ||
).start() | ||
work_loads[client_id] = 0 | ||
return client_id, client | ||
except Exception: | ||
logging.error(f"Failed starting Client - {client_id} Error:", exc_info=True) | ||
|
||
clients = await asyncio.gather(*[start_client(i, token) for i, token in all_tokens.items()]) | ||
multi_clients.update(dict(clients)) | ||
if len(multi_clients) != 1: | ||
Var.MULTI_CLIENT = True | ||
print("Multi-Client Mode Enabled") | ||
else: | ||
print("No additional clients were initialized, using default client") |
Oops, something went wrong.