This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
73 lines (61 loc) · 2.06 KB
/
bot.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
from telegram.ext import Updater
from secrets import BOT_TOKEN, SUDO_USERS
updater = Updater(BOT_TOKEN, use_context=True)
dp = updater.dispatcher
from os import path
if not path.exists('utils/templates.py'):
templfile = open('utils/templates.py', 'w+')
templfile.write("template = {}")
templfile.close()
if __name__ == "__main__":
import sys
import os
from threading import Thread
from telegram.ext import CommandHandler, Filters
from handlers import all_handlers
from secrets import SUDO_USERS
import logging
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO)
logger = logging.getLogger(__name__)
for arg in sys.argv:
if "-r" in arg:
for SUDO_USER in SUDO_USERS:
updater.bot.send_message(
SUDO_USER, arg.replace("-r", ""))
def stop_and_restart(name):
updater.stop()
os.system("git pull")
args = sys.argv
for i in range(len(args)):
if "-r" in args[i]:
del args[i]
os.execl(sys.executable, sys.executable, *args,
f"Bot restarted successfully. Initialted by -r{name}.")
def restart(update, context):
update.message.reply_text("Bot is restarting...")
Thread(
target=stop_and_restart,
args=(update.message.from_user.first_name,)
).start()
for handler in all_handlers:
if len(handler) == 2:
if handler[0] == "error":
dp.add_error_handler(
handler[1]
)
pass
else:
dp.add_handler(
handler[0],
handler[1]
)
else:
dp.add_handler(
handler[0]
)
dp.add_handler(
CommandHandler("r", restart, filters=Filters.user(SUDO_USERS))
)
updater.start_polling(clean=True)
updater.idle()