Skip to content

Commit

Permalink
change back
Browse files Browse the repository at this point in the history
  • Loading branch information
breakdowns authored Jun 1, 2021
1 parent 8b970c2 commit a392a03
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Fill up rest of the fields. Meaning of each fields are discussed below:
- **TELEGRAM_API**: 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.
- **TELEGRAM_HASH**: This is to authenticate to your Telegram account for downloading Telegram files. You can get this from https://my.telegram.org
- **OWNER_ID**: The Telegram user ID (not username) of the Owner of the bot
- **DATABASE_URL**: Your Database URL. See [Generate Database](https://github.com/breakdowns/slam-mirrorbot/tree/master#generate-database) to generate database. (**NOTE**: Leave this empty if You deploying on Heroku with PostgreSQL, for using another database with Heroku just make the name of the var (DATABASE_URL), for vps You must fill database url here)
- **DATABASE_URL**: Your Database URL. See [Generate Database](https://github.com/breakdowns/slam-mirrorbot/tree/master#generate-database) to generate database. (**NOTE**: If you deploying on Heroku, no need to generate database manually, because it will automatic generate database when first deploying)
- **GDRIVE_FOLDER_ID**: This is the folder ID of the Google Drive Folder to which you want to upload all the mirrors.
- **DOWNLOAD_DIR**: The path to the local folder where the downloads should be downloaded to
- **DOWNLOAD_STATUS_UPDATE_INTERVAL**: A short interval of time in seconds after which the Mirror progress message is updated. (I recommend to keep it `5` seconds at least)
Expand Down
5 changes: 2 additions & 3 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def mktable():
DB_URI = getConfig('DATABASE_URL')
parent_id = getConfig('GDRIVE_FOLDER_ID')
DOWNLOAD_DIR = getConfig('DOWNLOAD_DIR')
if DOWNLOAD_DIR[-1] != '/' or DOWNLOAD_DIR[-1] != '\\':
if not DOWNLOAD_DIR.endswith("/"):
DOWNLOAD_DIR = DOWNLOAD_DIR + '/'
DOWNLOAD_STATUS_UPDATE_INTERVAL = int(getConfig('DOWNLOAD_STATUS_UPDATE_INTERVAL'))
OWNER_ID = int(getConfig('OWNER_ID'))
Expand Down Expand Up @@ -125,8 +125,7 @@ def mktable():
conn.close()

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()
app = Client(':memory:', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN)

#Generate Telegraph Token
sname = ''.join(random.SystemRandom().choices(string.ascii_letters, k=8))
Expand Down
23 changes: 11 additions & 12 deletions bot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import shutil, psutil
import signal
import pickle
import os

from pyrogram import idle
from bot import app
from os import execl, kill, path, remove
from sys import executable
from datetime import datetime
import pytz
import time

from telegram import ParseMode, BotCommand
from telegram.ext import CommandHandler, run_async
from bot import dispatcher, updater, botStartTime, IMAGE_URL
from bot import bot, dispatcher, updater, botStartTime, IMAGE_URL
from bot.helper.ext_utils import fs_utils
from bot.helper.telegram_helper.bot_commands import BotCommands
from bot.helper.telegram_helper.message_utils import *
Expand Down Expand Up @@ -75,10 +74,11 @@ def restart(update, context):
restart_message = sendMessage("Restarting, Please wait!", context.bot, update)
LOGGER.info(f'Restarting the Bot...')
# Save restart message object in order to reply to it after restarting
with open(".restartmsg", "w") as f:
f.truncate(0)
f.write(f"{restart_message.chat.id}\n{restart_message.message_id}\n")
fs_utils.clean_all()
with open('restart.pickle', 'wb') as status:
pickle.dump(restart_message, status)
execl(executable, executable, "-m", "bot")
os.execl(executable, executable, "-m", "bot")


@run_async
Expand Down Expand Up @@ -215,12 +215,11 @@ def bot_help(update, context):
def main():
fs_utils.start_cleanup()
# Check if the bot is restarting
if path.exists('restart.pickle'):
with open('restart.pickle', 'rb') as status:
restart_message = pickle.load(status)
restart_message.edit_text("Restarted Successfully!")
LOGGER.info('Restarted Successfully!')
remove('restart.pickle')
if os.path.isfile(".restartmsg"):
with open(".restartmsg") as f:
chat_id, msg_id = map(int, f)
bot.edit_message_text("Restarted successfully!", chat_id, msg_id)
os.remove(".restartmsg")

bot.set_my_commands(botcmds)

Expand Down
10 changes: 2 additions & 8 deletions bot/helper/mirror_utils/download_utils/telegram_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
import threading
import time

from pyrogram import Client

from bot import LOGGER, download_dict, download_dict_lock, TELEGRAM_API, \
TELEGRAM_HASH, USER_SESSION_STRING
from bot import LOGGER, download_dict, download_dict_lock, app
from .download_helper import DownloadHelper
from ..status_utils.telegram_download_status import TelegramDownloadStatus

Expand All @@ -23,10 +20,7 @@ def __init__(self, listener):
self.__name = ""
self.__gid = ''
self.__start_time = time.time()
self._bot = Client(api_id=TELEGRAM_API,
api_hash=TELEGRAM_HASH,
session_name=USER_SESSION_STRING)
self._bot.start()
self._bot = app
self.__is_cancelled = False

@property
Expand Down
2 changes: 1 addition & 1 deletion config_sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ AUTO_DELETE_MESSAGE_DURATION = 20
IS_TEAM_DRIVE = ""
TELEGRAM_API =
TELEGRAM_HASH = ""
DATABASE_URL = "" #Leave this empty if You deploying on Heroku with PostgreSQL, for using another database with Heroku just make the name of the var (DATABASE_URL), for vps You must fill database url here
DATABASE_URL = ""
# Optional config
AUTHORIZED_CHATS = ""
USE_SERVICE_ACCOUNTS = ""
Expand Down

0 comments on commit a392a03

Please sign in to comment.