From 90badb4540238a8112f4a435785b98e094979cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CF=81=D1=8F=D1=94=E2=88=82=CE=B1=D1=82=CF=83=D1=8F?= <77227205+PredatorHackerzZ@users.noreply.github.com> Date: Fri, 1 Oct 2021 08:38:35 +0530 Subject: [PATCH] Add files via upload --- .gitignore | 144 +++++++++++++++++++++++++++++++++++++++++++++++ LICENSE | 21 +++++++ Procfile | 1 + README.md | 15 +++++ app.json | 40 +++++++++++++ bot.py | 60 ++++++++++++++++++++ requirements.txt | 4 ++ runtime.txt | 1 + 8 files changed, 286 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 Procfile create mode 100644 README.md create mode 100644 app.json create mode 100644 bot.py create mode 100644 requirements.txt create mode 100644 runtime.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..430dd8e --- /dev/null +++ b/.gitignore @@ -0,0 +1,144 @@ +*.session +*.session-journal + +# 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/ +share/python-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 +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.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/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +/gplink_env +/.vscode \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..650d205 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Mahesh0253 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..d80f8e7 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +worker: python3 bot.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..6448a1a --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# Pdisk Converter Bot +Make short link by using [Pdisk](https://www.cofilink.com/use-api/) API key +### Installation + +#### The Easy Way + +[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) + +##### Required Variables + +* `BOT_TOKEN`: Create a bot using [@BotFather](https://telegram.dog/BotFather), and get the Telegram API token. + +* `API_ID`: Get this value from [telegram.org](https://my.telegram.org/apps) +* `API_HASH`: Get this value from [telegram.org](https://my.telegram.org/apps) +* `API_KEY`: Create [Pdisk](https://www.cofilink.com/use-api) account then get this value diff --git a/app.json b/app.json new file mode 100644 index 0000000..ac7615c --- /dev/null +++ b/app.json @@ -0,0 +1,40 @@ +{ + "name": "PdiskShortener-Bot", + "description": "Make short link by using PdiskShortener API key", + "keywords": [ + "telegram", + "PdiskShortener" + ], + "website": "https://github.com/kevinnadar264/pdiskshortner/", + "repository": "https://github.com/kevinnadar264/pdiskshortner/", + "env": { + "BOT_TOKEN": { + "description": "Your bot token", + "value": "" + }, + "API_ID": { + "description": "Get this value from https://t.me/ScrapperRoBot", + "value": "" + }, + "API_HASH": { + "description": "Get this value from https://t.me/ScrapperRoBot", + "value": "" + }, + "API_KEY": { + "description": "Get API key from pdiskshortner.net/member/tools/api", + "required": false + } + }, + "addons": [], + "buildpacks": [ + { + "url": "heroku/python" + } + ], + "formation": { + "worker": { + "quantity": 1, + "size": "free" + } + } +} diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..abe3c14 --- /dev/null +++ b/bot.py @@ -0,0 +1,60 @@ +from os import environ +import aiohttp +import re +import requests +from pyrogram import Client, filters +from pyrogram.handlers import MessageHandler + +API_ID = environ.get('API_ID') +API_HASH = environ.get('API_HASH') +BOT_TOKEN = environ.get('BOT_TOKEN') +API_KEY = environ.get('API_KEY', '3494ad69b7c32aa52e71adf0da498357') + +bot = Client('pdiskshortner bot', + api_id=API_ID, + api_hash=API_HASH, + bot_token=BOT_TOKEN, + workers=50, + sleep_threshold=10) + + +@bot.on_message(filters.command('start') & filters.private) +async def start(bot, message): + await message.reply( + f"**Hi {message.chat.first_name}!**\n\n" + "I'm Pdisk link converter bot. Just send me link and get converted link of pdisk.\n\n Created By @steallootdeal") + +@bot.on_message(filters.command('help') & filters.private) +async def help(bot, message): + await message.reply( + f"**This is our Help Page {message.chat.first_name}!**\n\n" + "If your had **deployed bot** succesfully then you have to do nothing to use this bot\n\n **Just Simply send Any Pdisk Link in Any Format**\n -Shortend Url\n -Cofile url\n\n __Both url are accepted__ \n\n" + "**Demo Of Urls**\n **Bit.ly Shortened Url**\n https://bit.ly/38NEpVu \n\n **Pdisk Official Shorten Link** \n https://kofilink.com/1/bnYya2gxMDAwODI4?dn=3 \n\n" + "**Long Url** - https://www.cofilink.com/share-video?videoid=nv2kh1000828") + +@bot.on_message(filters.private) +async def link_handler(bot, message): + stringliteral = message.text + Link = (re.search("(?Phttps?://[^\s]+)", stringliteral).group("url")) + session = requests.Session() + resp = session.head(Link, allow_redirects=True) + short_link = await post_shortlink(resp.url) + shortlink = ('https://www.cofilink.com/share-video?videoid='+short_link) + txt = stringliteral.replace(Link, shortlink) + try: + await message.reply(f'{txt}', quote=True) + except Exception as e: + await message.reply(f'Error: {e}', quote=True) + + +async def post_shortlink(Link): + url = 'http://linkapi.net/open/create_item' + params = {'api_key': API_KEY, 'content_src': Link, 'link_type': 'link', 'cover_url' : '/steallootdeal.jpeg'} + async with aiohttp.ClientSession() as session: + async with session.get(url, params=params, raise_for_status=True) as response: + data = await response.json() + print(data["data"].get("item_id")) + return data["data"].get("item_id") + + +bot.run() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6ca689c --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +pyrogram +tgcrypto +aiohttp +requests diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..795ee72 --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.7.9