-
Notifications
You must be signed in to change notification settings - Fork 9
/
devs.py
96 lines (76 loc) 路 2.79 KB
/
devs.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
import os
import subprocess
import sys
from contextlib import suppress
from time import sleep
import FallenRobot
from FallenRobot import dispatcher
from FallenRobot.modules.helper_funcs.chat_status import dev_plus
from telegram import TelegramError, Update
from telegram.error import Unauthorized
from telegram.ext import CallbackContext, CommandHandler, run_async
@run_async
@dev_plus
def allow_groups(update: Update, context: CallbackContext):
args = context.args
if not args:
update.effective_message.reply_text(f"Current state: {FallenRobot.ALLOW_CHATS}")
return
if args[0].lower() in ["off", "no"]:
FallenRobot.ALLOW_CHATS = True
elif args[0].lower() in ["yes", "on"]:
FallenRobot.ALLOW_CHATS = False
else:
update.effective_message.reply_text("Format: /lockdown Yes/No or Off/On")
return
update.effective_message.reply_text("Done! Lockdown value toggled.")
@run_async
@dev_plus
def leave(update: Update, context: CallbackContext):
bot = context.bot
args = context.args
if args:
chat_id = str(args[0])
try:
bot.leave_chat(int(chat_id))
except TelegramError:
update.effective_message.reply_text(
"Beep boop, I could not leave that group(dunno why tho)."
)
return
with suppress(Unauthorized):
update.effective_message.reply_text("Beep boop, I left that soup!.")
else:
update.effective_message.reply_text("Send a valid chat ID")
@run_async
@dev_plus
def gitpull(update: Update, context: CallbackContext):
sent_msg = update.effective_message.reply_text(
"Pulling all changes from remote and then attempting to restart."
)
subprocess.Popen("git pull", stdout=subprocess.PIPE, shell=True)
sent_msg_text = sent_msg.text + "\n\nChanges pulled...I guess.. Restarting in "
for i in reversed(range(5)):
sent_msg.edit_text(sent_msg_text + str(i + 1))
sleep(1)
sent_msg.edit_text("Restarted.")
os.system("restart.bat")
os.execv("start.bat", sys.argv)
@run_async
@dev_plus
def restart(update: Update, context: CallbackContext):
update.effective_message.reply_text(
"Starting a new instance and shutting down this one"
)
os.system("restart.bat")
os.execv("start.bat", sys.argv)
LEAVE_HANDLER = CommandHandler("leave", leave)
GITPULL_HANDLER = CommandHandler("gitpull", gitpull)
RESTART_HANDLER = CommandHandler("reboot", restart)
ALLOWGROUPS_HANDLER = CommandHandler("lockdown", allow_groups)
dispatcher.add_handler(ALLOWGROUPS_HANDLER)
dispatcher.add_handler(LEAVE_HANDLER)
dispatcher.add_handler(GITPULL_HANDLER)
dispatcher.add_handler(RESTART_HANDLER)
__mod_name__ = "Dev"
__handlers__ = [LEAVE_HANDLER, GITPULL_HANDLER, RESTART_HANDLER, ALLOWGROUPS_HANDLER]