- Remove USE_TELEGRAPH, cuz its causes some issue
- Added support group link in /repo command
This commit is contained in:
Hafitz Setya 2021-04-14 15:13:34 +07:00 committed by GitHub
parent d9c3249e75
commit 4fa3f74a36
Signed by untrusted user: GitHub
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 121 additions and 163 deletions

View File

@ -83,7 +83,6 @@ Fill up rest of the fields. Meaning of each fields are discussed below:
- **INDEX_URL**: (Optional field) Refer to https://github.com/maple3142/GDIndex/ The URL should not have any trailing '/'
- **API_KEY**: This is to authenticate to your telegram account for downloading Telegram files. You can get this from https://my.telegram.org DO NOT put this in quotes.
- **API_HASH**: This is to authenticate to your telegram account for downloading Telegram files. You can get this from https://my.telegram.org
- **USE_TELEGRAPH**: Set to `true` to use Telegra.ph for search results from /list bot command, or else set to `false`.
- **MEGA_API_KEY**: Mega.nz api key to mirror mega.nz links. Get it from [Mega SDK Page](https://mega.nz/sdk)
- **MEGA_EMAIL_ID**: Your email id you used to sign up on mega.nz for using premium accounts (Leave th)
- **MEGA_PASSWORD**: Your password for your mega.nz account
@ -140,8 +139,9 @@ sudo docker run mirrorbot
## Deploying on Heroku
- Fork this repo
- Upload **token.pickle** to your forks
Fork this repo then upload **token.pickle** to your forks
**NOTE**: If you didn't upload **token.pickle**, uploading will not working.
<p><a href="https://heroku.com/deploy"> <img src="https://img.shields.io/badge/Deploy%20To%20Heroku-blueviolet?style=for-the-badge&logo=heroku" width="200""/></a></p>
## Deploying on Heroku using heroku-cli
@ -155,15 +155,15 @@ heroku login
```
- Create a new heroku app:
```
heroku create <appname>
heroku create appname
```
- Select This App in your Heroku-cli:
```
heroku git:remote -a <appname>
heroku git:remote -a appname
```
- Change Dyno Stack to a Docker Container:
```
heroku stack:set container -a <appname>
heroku stack:set container -a appname
```
- Add Private Credentials and Config Stuff:
```
@ -180,11 +180,11 @@ git push heroku master --force
- Restart Worker by these commands,You can Do it manually too in heroku.
- For Turning off the Bot:
```
heroku ps:scale worker=0 -a <appname>
heroku ps:scale worker=0 -a appname
```
- For Turning on the Bot:
```
heroku ps:scale worker=1 -a <appname>
heroku ps:scale worker=1 -a appname
```
</details>

View File

@ -66,11 +66,6 @@
"description": "This is to authenticate to your telegram account for downloading Telegram files. You can get this from https://my.telegram.org.",
"required": true
},
"USE_TELEGRAPH": {
"description": "Set to true to use Telegra.ph for search results from /list bot command, or else set to false.",
"value": "",
"required": true
},
"HEROKU_API_KEY": {
"description": "Your Heroku API key, get it from https://dashboard.heroku.com/account.",
"required": true

View File

@ -90,6 +90,28 @@ except KeyError as e:
LOGGER.error("One or more env variables missing! Exiting now")
exit(1)
LOGGER.info("Generating USER_SESSION_STRING")
with Client(':memory:', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN) as app:
USER_SESSION_STRING = app.export_session_string()
#Generate Telegraph Token
sname = ''.join(random.SystemRandom().choices(string.ascii_letters, k=8))
LOGGER.info("Generating Telegraph Token using '" + sname + "' name")
telegraph = Telegraph()
telegraph.create_account(short_name=sname)
telegraph_token = telegraph.get_access_token()
LOGGER.info("Telegraph Token Generated: '" + telegraph_token + "'")
try:
HEROKU_API_KEY = getConfig('HEROKU_API_KEY')
except KeyError:
logging.warning('HEROKU API KEY not provided!')
HEROKU_API_KEY = None
try:
HEROKU_APP_NAME = getConfig('HEROKU_APP_NAME')
except KeyError:
logging.warning('HEROKU APP NAME not provided!')
HEROKU_APP_NAME = None
try:
MAX_TORRENT_SIZE = int(getConfig("MAX_TORRENT_SIZE"))
except KeyError:
@ -102,44 +124,6 @@ try:
ENABLE_FILESIZE_LIMIT = False
except KeyError:
ENABLE_FILESIZE_LIMIT = False
try:
if os.environ['USE_TELEGRAPH'].upper() == 'TRUE':
USE_TELEGRAPH = True
else:
raise KeyError
except KeyError:
USE_TELEGRAPH = False
# Generate USER_SESSION_STRING
LOGGER.info("Generating USER_SESSION_STRING")
with Client(':memory:', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN) as app:
USER_SESSION_STRING = app.export_session_string()
# Generate TELEGRAPH_TOKEN
if USE_TELEGRAPH:
sname = ''.join(random.SystemRandom().choices(string.ascii_letters, k=8))
LOGGER.info("Using Telegra.ph")
LOGGER.info("Generating TELEGRAPH_TOKEN using '" + sname + "' name")
telegraph = Telegraph()
telegraph.create_account(short_name=sname)
TELEGRAPH_TOKEN = telegraph.get_access_token()
LOGGER.info("Telegraph Token Generated: '" + TELEGRAPH_TOKEN + "'")
if not USE_TELEGRAPH:
TELEGRAPH_TOKEN = None
LOGGER.info("Not Using Telegra.ph")
pass
try:
HEROKU_API_KEY = getConfig('HEROKU_API_KEY')
except KeyError:
logging.warning('HEROKU API KEY not provided!')
HEROKU_API_KEY = None
try:
HEROKU_APP_NAME = getConfig('HEROKU_APP_NAME')
except KeyError:
logging.warning('HEROKU APP NAME not provided!')
HEROKU_APP_NAME = None
try:
UPTOBOX_TOKEN = getConfig('UPTOBOX_TOKEN')
except KeyError:

View File

@ -60,7 +60,7 @@ def chat_list(update, context):
def repo(update, context):
bot.send_message(update.message.chat_id,
reply_to_message_id=update.message.message_id,
text="Repo: https://github.com/breakdowns/slam-mirrorbot", disable_web_page_preview=True)
text="Repo: https://github.com/breakdowns/slam-mirrorbot\nGroup: https://t.me/SlamMirrorSupportGroup", disable_web_page_preview=True)
@run_async

View File

@ -29,18 +29,19 @@ class AriaDownloadHelper(DownloadHelper):
aria2.remove([download])
return
update_all_messages()
gdrive = GoogleDriveHelper(None)
smsg, button = gdrive.drive_list(sname)
if STOP_DUPLICATE_MIRROR:
if smsg:
dl.getListener().onDownloadError(f'😡 File is already available in drive. You should have search before mirror any file. You might get ban if you do this again. This download has been stopped.\n\n')
print(dl.getListener())
if button:
sendMarkup("Here are the search results:👇\n", dl.getListener().bot, dl.getListener().update, button)
else:
sendMessage("Here are the search results:👇\n" + smsg, dl.getListener().bot, dl.getListener().update)
aria2.remove([download])
return
if dl.getListener().isTar == True:
sname = sname + ".tar"
if dl.getListener().extract == True:
smsg = None
else:
gdrive = GoogleDriveHelper(None)
smsg, button = gdrive.drive_list(sname)
if smsg:
dl.getListener().onDownloadError(f'😡 File is already available in drive. You should have search before mirror any file. You might get ban if you do this again. This download has been stopped.\n\n')
sendMarkup(" Here are the search results:👇", dl.getListener().bot, dl.getListener().update, button)
aria2.remove([download])
return
update_all_messages()
def __onDownloadComplete(self, api: API, gid):

View File

@ -19,8 +19,8 @@ from tenacity import *
from telegram import InlineKeyboardMarkup
from bot.helper.telegram_helper import button_build
from telegraph import Telegraph
from bot import parent_id, DOWNLOAD_DIR, IS_TEAM_DRIVE, INDEX_URL, USE_TELEGRAPH, \
USE_SERVICE_ACCOUNTS, download_dict, TELEGRAPH_TOKEN, BUTTON_THREE_NAME, BUTTON_THREE_URL, BUTTON_FOUR_NAME, BUTTON_FOUR_URL, BUTTON_FIVE_NAME, BUTTON_FIVE_URL, SHORTENER, SHORTENER_API
from bot import parent_id, DOWNLOAD_DIR, IS_TEAM_DRIVE, INDEX_URL, \
USE_SERVICE_ACCOUNTS, download_dict, telegraph_token, BUTTON_THREE_NAME, BUTTON_THREE_URL, BUTTON_FOUR_NAME, BUTTON_FOUR_URL, BUTTON_FIVE_NAME, BUTTON_FIVE_URL, SHORTENER, SHORTENER_API
from bot.helper.ext_utils.bot_utils import *
from bot.helper.ext_utils.fs_utils import get_mime_type, get_path_size
@ -477,7 +477,7 @@ class GoogleDriveHelper:
if nxt_page < self.num_of_path:
content += f'<b> | <a href="https://telegra.ph/{self.path[nxt_page]}">Next</a></b>'
nxt_page += 1
Telegraph(access_token=TELEGRAPH_TOKEN).edit_page(path = self.path[prev_page],
Telegraph(access_token=telegraph_token).edit_page(path = self.path[prev_page],
title = 'Slam Mirror Bot - Search',
author_name='Slam Mirror Bot',
author_url='https://github.com/breakdowns/slam-mirrorbot',
@ -503,87 +503,69 @@ class GoogleDriveHelper:
fields='files(id, name, mimeType, size)',
orderBy='name asc').execute()
content_count = 0
if USE_TELEGRAPH:
if response["files"]:
msg += f'<h4>{len(response["files"])} Results : {fileName}</h4><br><br>'
for file in response.get('files', []):
if file.get(
'mimeType') == "application/vnd.google-apps.folder": # Detect Whether Current Entity is a Folder or File.
furl = f"https://drive.google.com/drive/folders/{file.get('id')}"
msg += f"⁍<code>{file.get('name')}<br>(folder)📁</code><br>"
if SHORTENER is not None and SHORTENER_API is not None:
sfurl = requests.get(
'https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, furl)).text
msg += f"<b><a href={sfurl}>Drive Link</a></b>"
else:
msg += f"<b><a href={furl}>Drive Link</a></b>"
if INDEX_URL is not None:
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}/')
if SHORTENER is not None and SHORTENER_API is not None:
siurl = requests.get(
'https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API,
url)).text
msg += f' <b>| <a href="{siurl}">Index Link</a></b>'
else:
msg += f' <b>| <a href="{url}">Index Link</a></b>'
else:
furl = f"https://drive.google.com/uc?id={file.get('id')}&export=download"
msg += f"⁍<code>{file.get('name')}<br>({get_readable_file_size(int(file.get('size')))})📄</code><br>"
if SHORTENER is not None and SHORTENER_API is not None:
sfurl = requests.get(
'https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, furl)).text
msg += f"<b><a href={sfurl}>Drive Link</a></b>"
else:
msg += f"<b><a href={furl}>Drive Link</a></b>"
if INDEX_URL is not None:
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}')
if SHORTENER is not None and SHORTENER_API is not None:
siurl = requests.get(
'https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API,
url)).text
msg += f' <b>| <a href="{siurl}">Index Link</a></b>'
else:
msg += f' <b>| <a href="{url}">Index Link</a></b>'
msg += '<br><br>'
content_count += 1
if content_count == TELEGRAPHLIMIT:
self.telegraph_content.append(msg)
msg = ""
content_count = 0
if msg != '':
self.telegraph_content.append(msg)
if len(self.telegraph_content) == 0:
return "No Result Found ❌", None
for content in self.telegraph_content:
self.path.append(Telegraph(access_token=TELEGRAPH_TOKEN).create_page(
title='Slam Mirror Bot Search',
author_name='Slam Mirror Bot',
author_url='https://github.com/breakdowns/slam-mirrorbot',
html_content=content
)['path'])
self.num_of_path = len(self.path)
if self.num_of_path > 1:
self.edit_telegraph()
msg = f"<b>🔎 Search Results For <i>{fileName}</i></b> \n<b>📚 Found {len(response['files'])} results</b>"
buttons = button_build.ButtonMaker()
buttons.buildbutton("HERE", f"https://telegra.ph/{self.path[0]}")
return msg, InlineKeyboardMarkup(buttons.build_menu(1))
else:
return '', ''
if not USE_TELEGRAPH:
if response["files"]:
msg += f'<h4>{len(response["files"])} Results : {fileName}</h4><br><br>'
for file in response.get('files', []):
if file.get(
'mimeType') == "application/vnd.google-apps.folder": # Detect Whether Current Entity is a Folder or File.
msg += f"⁍ <a href='https://drive.google.com/drive/folders/{file.get('id')}'>{file.get('name')}" \
f"</a> (folder)"
if file.get('mimeType') == "application/vnd.google-apps.folder": # Detect Whether Current Entity is a Folder or File.
furl = f"https://drive.google.com/drive/folders/{file.get('id')}"
msg += f"⁍<code>{file.get('name')}<br>(folder)📁</code><br>"
if SHORTENER is not None and SHORTENER_API is not None:
sfurl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, furl)).text
msg += f"<b><a href={sfurl}>Drive Link</a></b>"
else:
msg += f"<b><a href={furl}>Drive Link</a></b>"
if INDEX_URL is not None:
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}/')
msg += f' | <a href="{url}"> Index URL</a>'
if SHORTENER is not None and SHORTENER_API is not None:
siurl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, url)).text
msg += f' <b>| <a href="{siurl}">Index Link</a></b>'
else:
msg += f' <b>| <a href="{url}">Index Link</a></b>'
else:
msg += f"⁍ <a href='https://drive.google.com/uc?id={file.get('id')}" \
f"&export=download'>{file.get('name')}</a> ({get_readable_file_size(int(file.get('size')))})"
furl = f"https://drive.google.com/uc?id={file.get('id')}&export=download"
msg += f"⁍<code>{file.get('name')}<br>({get_readable_file_size(int(file.get('size')))})📄</code><br>"
if SHORTENER is not None and SHORTENER_API is not None:
sfurl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, furl)).text
msg += f"<b><a href={sfurl}>Drive Link</a></b>"
else:
msg += f"<b><a href={furl}>Drive Link</a></b>"
if INDEX_URL is not None:
url = requests.utils.requote_uri(f'{INDEX_URL}/{file.get("name")}')
msg += f' | <a href="{url}"> Index URL</a>'
msg += '\n'
return msg, ''
if SHORTENER is not None and SHORTENER_API is not None:
siurl = requests.get('https://{}/api?api={}&url={}&format=text'.format(SHORTENER, SHORTENER_API, url)).text
msg += f' <b>| <a href="{siurl}">Index Link</a></b>'
else:
msg += f' <b>| <a href="{url}">Index Link</a></b>'
msg += '<br><br>'
content_count += 1
if content_count == TELEGRAPHLIMIT :
self.telegraph_content.append(msg)
msg = ""
content_count = 0
if msg != '':
self.telegraph_content.append(msg)
if len(self.telegraph_content) == 0:
return "No Result Found ❌", None
for content in self.telegraph_content :
self.path.append(Telegraph(access_token=telegraph_token).create_page(
title = 'Slam Mirror Bot Search',
author_name='Slam Mirror Bot',
author_url='https://github.com/breakdowns/slam-mirrorbot',
html_content=content
)['path'])
self.num_of_path = len(self.path)
if self.num_of_path > 1:
self.edit_telegraph()
msg = f"<b>🔎 Search Results For <i>{fileName}</i></b> \n<b>📚 Found {len(response['files'])} results</b>"
buttons = button_build.ButtonMaker()
buttons.buildbutton("HERE", f"https://telegra.ph/{self.path[0]}")
return msg, InlineKeyboardMarkup(buttons.build_menu(1))
else :
return '', ''

View File

@ -1,31 +1,28 @@
from telegram.ext import CommandHandler, run_async
from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
from bot import LOGGER, dispatcher
from bot.helper.telegram_helper.message_utils import sendMessage, editMessage
from bot.helper.telegram_helper.message_utils import sendMessage, sendMarkup, editMessage
from bot.helper.telegram_helper.filters import CustomFilters
import threading
from bot.helper.telegram_helper.bot_commands import BotCommands
@run_async
def list_drive(update, context):
if update.message.text == f'/{BotCommands.ListCommand}':
sendMessage(f'Send a search key along with {BotCommands.ListCommand} command', context.bot, update)
else:
search = update.message.text.split(' ', maxsplit=1)[1]
LOGGER.info(f"Searching: '{search}'...")
reply = sendMessage('Searching..... Please Wait!', context.bot, update)
def list_drive(update,context):
try:
search = update.message.text.split(' ',maxsplit=1)[1]
LOGGER.info(f"Searching: {search}")
reply = sendMessage('Searching..... Please wait!', context.bot, update)
gdrive = GoogleDriveHelper(None)
msg, button = gdrive.drive_list(search)
if msg:
if button:
editMessage(msg, reply, button)
else:
editMessage(msg, reply)
if button:
editMessage(msg, reply, button)
else:
editMessage('No results found', reply)
# if not USE_TELEGRAPH:
# threading.Thread(target=auto_delete_message, args=(context.bot, update.message, reply)).start()
editMessage('No result found', reply, button)
except IndexError:
sendMessage('Send a search key along with command', context.bot, update)
list_handler = CommandHandler(BotCommands.ListCommand, list_drive, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
list_handler = CommandHandler(BotCommands.ListCommand, list_drive,filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
dispatcher.add_handler(list_handler)

View File

@ -15,7 +15,6 @@ TELEGRAM_HASH = ""
AUTHORIZED_CHATS = ""
USE_SERVICE_ACCOUNTS = ""
INDEX_URL = ""
USE_TELEGRAPH = ""
UPTOBOX_TOKEN = ""
MEGA_API_KEY = ""
MEGA_EMAIL_ID = ""