forked from ayushteke/torrent-to-gdrive-mirrorbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
168 lines (132 loc) · 6.87 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import shutil, psutil
import signal
import pickle
from pyrogram import idle
from bot import app
from os import execl, kill, path, remove
from sys import executable
import time
from telegram import ParseMode
from telegram.ext import CommandHandler, run_async
from bot import dispatcher, updater, botStartTime
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 *
from .helper.ext_utils.bot_utils import get_readable_file_size, get_readable_time
from .helper.telegram_helper.filters import CustomFilters
from .modules import authorize, list, cancel_mirror, mirror_status, mirror, clone, watch, shell, eval, anime, stickers, search, delete, speedtest, usage, drive-tar
@run_async
def stats(update, context):
currentTime = get_readable_time((time.time() - botStartTime))
total, used, free = shutil.disk_usage('.')
total = get_readable_file_size(total)
used = get_readable_file_size(used)
free = get_readable_file_size(free)
sent = get_readable_file_size(psutil.net_io_counters().bytes_sent)
recv = get_readable_file_size(psutil.net_io_counters().bytes_recv)
cpuUsage = psutil.cpu_percent(interval=0.5)
memory = psutil.virtual_memory().percent
disk = psutil.disk_usage('/').percent
stats = f'<b>╭─────────「 ⭕️ BOT STATISTICS ⭕️ 」</b>\n' \
f'<b>│</b>\n' \
f'<b>├ ⏰ Bot Uptime : {currentTime}</b>\n' \
f'<b>├ 💾 Total Disk Space : {total}</b>\n' \
f'<b>├ 📀 Total Used Space : {used}</b>\n' \
f'<b>├ 💿 Total Free Space : {free}</b>\n' \
f'<b>├ 🔼 Total Upload : {sent}</b>\n' \
f'<b>├ 🔽 Total Download : {recv}</b>\n' \
f'<b>├ 🖥️ CPU : {cpuUsage}%</b>\n' \
f'<b>├ 🎮 RAM : {memory}%</b>\n' \
f'<b>├ 💽 DISK : {disk}%</b>\n' \
f'<b>│</b>\n' \
f'<b>╰──「 🚸 @AT_BOTS 🚸 」</b>'
sendMessage(stats, context.bot, update)
@run_async
def start(update, context):
start_string = f'''
Hi {update.message.chat.first_name}, This bot can mirror all your links to Google drive!
Type /{BotCommands.HelpCommand} to get a list of available commands
'''
update.effective_message.reply_photo("https://telegra.ph/file/019996f816db9ed576cff.jpg", start_string, parse_mode=ParseMode.MARKDOWN)
@run_async
def repo(update, context):
bot.send_message(update.message.chat_id,
reply_to_message_id=update.message.message_id,
text="https://github.com/ayushteke/slam_aria_mirror_bot_HEROKU", disable_web_page_preview=false)
@run_async
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
fs_utils.clean_all()
with open('restart.pickle', 'wb') as status:
pickle.dump(restart_message, status)
execl(executable, executable, "-m", "bot")
@run_async
def ping(update, context):
start_time = int(round(time.time() * 1000))
reply = sendMessage("Starting Ping", context.bot, update)
end_time = int(round(time.time() * 1000))
editMessage(f'{end_time - start_time} ms', reply)
@run_async
def log(update, context):
sendLogFile(context.bot, update)
@run_async
def bot_help(update, context):
help_string = f'''
/{BotCommands.HelpCommand}: To get this message
/{BotCommands.MirrorCommand} [download_url][magnet_link]: Start mirroring the link to google drive
/{BotCommands.UnzipMirrorCommand} [download_url][magnet_link]: Starts mirroring and if downloaded file is any archive, extracts it to google drive
/{BotCommands.TarMirrorCommand} [download_url][magnet_link]: Start mirroring and upload the archived (.tar) version of the download
/{BotCommands.CloneCommand}: Copy file/folder to google drive
/{BotCommands.WatchCommand} [youtube-dl supported link]: Mirror through youtube-dl. Click /{BotCommands.WatchCommand} for more help.
/{BotCommands.TarWatchCommand} [youtube-dl supported link]: Mirror through youtube-dl and tar before uploading
/{BotCommands.CancelMirror}: Reply to the message by which the download was initiated and that download will be cancelled
/{BotCommands.StatusCommand}: Shows a status of all the downloads
/{BotCommands.ListCommand} [search term]: Searches the search term in the Google drive, if found replies with the link
/{BotCommands.StatsCommand}: Show Stats of the machine the bot is hosted on
/{BotCommands.AuthorizeCommand}: Authorize a chat or a user to use the bot (Can only be invoked by owner of the bot)
/{BotCommands.LogCommand}: Get a log file of the bot. Handy for getting crash reports
/{BotCommands.UsageCommand}: To see Heroku Dyno Stats (Owner only).
/{BotCommands.SpeedCommand}: Check Internet Speed of the Host
/{BotCommands.RepoCommand}: Get the bot repo.
/tshelp: Get help for torrent search module.
/weebhelp: Get help for anime, manga and character module.
/stickerhelp: Get help for stickers module.
'''
sendMessage(help_string, context.bot, update)
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')
start_handler = CommandHandler(BotCommands.StartCommand, start,
filters=CustomFilters.authorized_user)
ping_handler = CommandHandler(BotCommands.PingCommand, ping,
filters=CustomFilters.authorized_user)
restart_handler = CommandHandler(BotCommands.RestartCommand, restart,
filters=CustomFilters.authorized_user | CustomFilters.owner_filter)
help_handler = CommandHandler(BotCommands.HelpCommand,
bot_help, filters=CustomFilters.authorized_chat | CustomFilters.authorized_user)
stats_handler = CommandHandler(BotCommands.StatsCommand,
stats, filters=CustomFilters.authorized_user)
log_handler = CommandHandler(BotCommands.LogCommand, log, filters=CustomFilters.owner_filter)
repo_handler = CommandHandler(BotCommands.RepoCommand, repo,
filters=CustomFilters.authorized_user)
dispatcher.add_handler(start_handler)
dispatcher.add_handler(ping_handler)
dispatcher.add_handler(restart_handler)
dispatcher.add_handler(help_handler)
dispatcher.add_handler(stats_handler)
dispatcher.add_handler(log_handler)
dispatcher.add_handler(repo_handler)
updater.start_polling()
LOGGER.info("Bot Started!")
signal.signal(signal.SIGINT, fs_utils.exit_clean_up)
app.start()
main()
idle()