-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
62 lines (49 loc) · 1.47 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
from telegram.ext import Defaults
from telegram.ext import Updater
from config import BOT_TOKEN
from config import SUDO_USERS
updater = Updater(
token=BOT_TOKEN,
defaults=Defaults(
parse_mode='HTML',
disable_web_page_preview=True,
quote=False,
run_async=True,
),
)
dp = updater.dispatcher
if __name__ == '__main__':
import os
import sys
from threading import Thread
from threading import Thread
from mongo import users
from helpers.wrappers import nice_errors
from telegram import Update
from telegram.ext import CallbackContext, CommandHandler
from handlers import add_handlers
from helpers.filters import sudo_only
if '-r' in sys.argv:
for user in SUDO_USERS:
updater.bot.send_message(user, 'Restarted.')
def stop_and_restart(chat, msg):
updater.stop()
os.execl(
sys.executable,
sys.executable,
*sys.argv,
'-r',
f'{chat}_{msg}',
)
def restart(update: Update, context: CallbackContext):
update.effective_message.reply_text('Restarting...')
Thread(
target=stop_and_restart, args=(
update.effective_chat.id,
update.effective_message.message_id,
),
).start()
dp.add_handler(CommandHandler('r', restart, sudo_only))
add_handlers(dp)
updater.start_polling(drop_pending_updates=True)
updater.idle()