Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
breakdowns authored Jun 1, 2021
1 parent 17db401 commit 8b970c2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/breakdowns/slam-mirrorbot)
[![Slam Mirror Support](https://img.shields.io/badge/slam%20mirror%20bot-support%20group-blue)](https://t.me/SlamMirrorSupport)

**Slam Mirror Bot** is a Telegram Bot writen in Python for mirroring files on the Internet to our beloved Google Drive.
**Slam Mirror Bot** is a multipurpose Telegram Bot writen in Python for mirroring files on the Internet to our beloved Google Drive.

# Features supported:

Expand All @@ -26,7 +26,7 @@
- Multiple Trackers support
- Check Heroku dynos stats
- Custom image support
- Counting file/folders
- Counting file/folder
- Racaty.net support
- Shell and Executor
- Stickers module
Expand Down
7 changes: 4 additions & 3 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def mktable():

try:
BOT_TOKEN = getConfig('BOT_TOKEN')
DB_URI = os.environ.get("DATABASE_URL")
DB_URI = getConfig('DATABASE_URL')
parent_id = getConfig('GDRIVE_FOLDER_ID')
DOWNLOAD_DIR = getConfig('DOWNLOAD_DIR')
if not DOWNLOAD_DIR.endswith("/"):
if DOWNLOAD_DIR[-1] != '/' or DOWNLOAD_DIR[-1] != '\\':
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,7 +125,8 @@ def mktable():
conn.close()

LOGGER.info("Generating USER_SESSION_STRING")
app = Client(':memory:', api_id=int(TELEGRAM_API), api_hash=TELEGRAM_HASH, bot_token=BOT_TOKEN)
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))
Expand Down
31 changes: 16 additions & 15 deletions bot/__main__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import shutil, psutil
import signal
import os
import pickle

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 bot, dispatcher, updater, botStartTime, IMAGE_URL
from bot import 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 @@ -74,11 +75,10 @@ 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()
os.execl(executable, executable, "-m", "bot")
with open('restart.pickle', 'wb') as status:
pickle.dump(restart_message, status)
execl(executable, executable, "-m", "bot")


@run_async
Expand Down Expand Up @@ -197,29 +197,30 @@ def bot_help(update, context):
BotCommand(f'{BotCommands.TarMirrorCommand}','Upload tar (zipped) file'),
BotCommand(f'{BotCommands.UnzipMirrorCommand}','Extract files'),
BotCommand(f'{BotCommands.CloneCommand}','Copy file/folder to Drive'),
BotCommand(f'{BotCommands.CountCommand}','Count file/folder of Drive Links'),
BotCommand(f'{BotCommands.CountCommand}','Count file/folder of Drive link'),
BotCommand(f'{BotCommands.WatchCommand}','Mirror YT-DL support link'),
BotCommand(f'{BotCommands.TarWatchCommand}','Mirror Youtube playlist link as tar'),
BotCommand(f'{BotCommands.CancelMirror}','Cancel a task'),
BotCommand(f'{BotCommands.CancelAllCommand}','Cancel all tasks'),
BotCommand(f'{BotCommands.DeleteCommand}','Delete file from Drive'),
BotCommand(f'{BotCommands.ListCommand}',' [query] Searches files in G-Drive'),
BotCommand(f'{BotCommands.ListCommand}',' [query] Searches files in Drive'),
BotCommand(f'{BotCommands.StatusCommand}','Get Mirror Status message'),
BotCommand(f'{BotCommands.StatsCommand}','Bot Usage Stats'),
BotCommand(f'{BotCommands.HelpCommand}','Get Detailed Help'),
BotCommand(f'{BotCommands.SpeedCommand}','Check Speed of the host'),
BotCommand(f'{BotCommands.LogCommand}','Bot Log [owner only]'),
BotCommand(f'{BotCommands.RestartCommand}','Restart bot [owner only]')]
BotCommand(f'{BotCommands.LogCommand}','Bot Log [owner/sudo only]'),
BotCommand(f'{BotCommands.RestartCommand}','Restart bot [owner/sudo only]')]


def main():
fs_utils.start_cleanup()
# Check if the bot is restarting
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")
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')

bot.set_my_commands(botcmds)

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

from bot import LOGGER, download_dict, download_dict_lock, app
from pyrogram import Client

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

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

@property
Expand Down

0 comments on commit 8b970c2

Please sign in to comment.