-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
125 lines (105 loc) · 3.63 KB
/
main.py
File metadata and controls
125 lines (105 loc) · 3.63 KB
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
import asyncio
import os
import sys
import time
import keyboard
import telebot
builted = False
# настройка :
# bind f2 "exec scc"
# не менять
class SourceConsoleControl :
def __init__(self) :
if builted:
with open("tg") as f:
#print(f.readline())
#exit()
self.bot = telebot.TeleBot(f.readline())
else:
self.bot = telebot.TeleBot("")
self.menu = False
self.autostart = (True, "portal2.exe", "-dev +developer 2") # запускать при старте
self.ok = "esc"
self.pressed_menu = False # зажатая клавиша (не менять)
self.portal_path = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\Portal 2\\portal2" # путь до игры
def is_locked(self,command: str) -> int :
if len(command) < 3 :
return 2
print(command)
if command.split()[0] in "map".split(",") :
return 1
if command.split()[-1] in "".split(",") :
return 1
if command.lower() in "kill,crash,quit,exit,editor_toggle,fadeout,fadein".split(",") :
return 1
if command.find("test") :
return
return 0
def exec_command(self,command: str) :
try :
with open(self.portal_path.replace("\\","/") + "/cfg/scc.cfg",'w') as f :
f.write(command)
except PermissionError :
print("команда не записана")
print(command)
keyboard.press('f2')
time.sleep(0.1)
keyboard.release('f2')
def main(self,command: str) : # функция обраборки чата
print(f"команда ({command}) введена")
if self.menu :
return
if self.is_locked(command) :
print(self.is_locked(command))
if self.is_locked(command)==1 :
print(f"команда ({command}) заблокирована")
return
self.exec_command(command)
scc = SourceConsoleControl()
@scc.bot.message_handler(commands = ['help','start'])
def send_welcome(message) :
scc.bot.reply_to(message,"бот включен")
@scc.bot.message_handler(func = lambda message : True)
def message(message) :
scc.main(message.text)
def menu_logger(x) :
if not scc.pressed_menu :
scc.menu = not scc.menu
if scc.menu :
print("меню открыто")
else :
print("меню закрыто")
scc.pressed_menu = True
scc.ok = "esc"
def menu_logger0(x) :
if not scc.pressed_menu :
if not scc.ok == "esc":
scc.menu = not scc.menu
if scc.menu :
print("меню открыто")
else :
print("меню закрыто")
scc.pressed_menu = True
scc.ok = '~'
def menu_logger1(x) :
scc.pressed_menu = False
if __name__=='__main__' :
if scc.autostart[0]:
gt = '"' + '/'.join(scc.portal_path.replace("\\", "/").split('/')[:-1]) + '/' + scc.autostart[1] + '"' + ' ' + scc.autostart[2]
print(gt)
sss = ""
if os.name != "nt":
sss = "c.sh"
else:
sss = "c.bat"
with open(sss, 'w') as f:
f.write(gt)
if os.name != "nt":
os.system("xterm -e c.sh &")
else:
os.system("start c.bat")
keyboard.on_press_key("esc",menu_logger)
keyboard.on_release_key("esc",menu_logger1)
keyboard.on_press_key("`",menu_logger0)
keyboard.on_release_key("`",menu_logger1)
asyncio.run(scc.bot.polling())