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 5
/
bot.py
64 lines (52 loc) · 1.43 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
from telegram.ext import PicklePersistence, Updater
from secrets import BOT_TOKEN
p = PicklePersistence(
filename="data"
)
updater = Updater(
BOT_TOKEN,
persistence=p,
use_context=True
)
dp = updater.dispatcher
def 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, SUDO
if "-r" in sys.argv:
for SUDO_USER in SUDO_USERS:
updater.bot.send_message(SUDO_USER, "Bot restarted successfully.")
def stop_and_restart():
os.system("git pull")
updater.stop()
os.execl(sys.executable, sys.executable, *sys.argv, "-r")
def restart(update, context):
update.message.reply_text("Bot is restarting...")
Thread(target=stop_and_restart).start()
for handler in all_handlers:
if len(handler) == 2:
if handler[0] == "error":
dp.add_error_handler(
handler[1]
)
else:
dp.add_handler(
handler[0],
handler[1]
)
else:
dp.add_handler(
handler[0]
)
dp.add_handler(
CommandHandler(
"r", restart, filters=SUDO
)
)
updater.start_polling(clean=True)
updater.idle()
if __name__ == "__main__":
main()