[~] Translated to RU

This commit is contained in:
2024-01-12 17:39:09 +03:00
parent b41a4106ac
commit a44a62f154
2 changed files with 14 additions and 13 deletions

View File

@@ -14,7 +14,7 @@ class Bot:
self.group_id = vk.groups.getById()[0]['id']
with open('help_message.txt') as f:
self.help_message = f.read()
log(f"Group id: {self.group_id}")
log(f"[BOT] ID группы: {self.group_id}")
def get_lp_server(self):
lp = vk.groups.getLongPollServer(group_id=self.group_id)
@@ -25,7 +25,7 @@ class Bot:
messages = (len(message) // 4095)
for i in range(1, messages + 1):
if i > 30:
log("Found very long message...", 1)
log("[BOT] Сообщение слишком длинное...", 1)
break
self.write(peer_id, message[:4095 * i])
else:
@@ -37,13 +37,13 @@ class Bot:
r = cmd
if a or _allow:
answer = rcon(cmd)
log(f"User: {from_id}({r}) in Chat: {peer_id} use RCON cmd: \"{cmd}\", with answer: \"{answer}\"")
log(f"[BOT] User: {from_id}({r}) in Chat: {peer_id} use RCON cmd: \"{cmd}\", with answer: \"{answer}\"")
if _write:
self.write(peer_id, f"RCON:\n{answer}")
else:
return answer
else:
log(f"User: {from_id}({r}) in Chat: {peer_id} no have rights RCON cmd: \"{cmd}\".")
log(f"[BOT] User: {from_id}({r}) in Chat: {peer_id} no have rights RCON cmd: \"{cmd}\".")
def message_handle(self, message):
from_id = message['from_id']
@@ -62,7 +62,7 @@ class Bot:
def listen(self):
server, key, ts = self.get_lp_server()
log("Listening..")
log("[BOT] Начинаю получать сообщения..")
while True:
lp = requests.get(f'{server}?act=a_check&key={key}&ts={ts}&wait=25').json()
try:
@@ -75,13 +75,12 @@ class Bot:
ts = lp.get('ts')
except KeyboardInterrupt:
print('\nExiting...')
sys.exit(1)
except KeyboardInterrupt as e:
raise e
except Exception as e:
ts = lp.get('ts')
print(f"Found exception: {e}")
log(f"Found exception: {e}", 1)
traceback.print_exc()
@@ -106,6 +105,8 @@ if __name__ == '__main__':
log("Сервер не отвечает. Проверьте блок \"minecraft\" с config.json", 1)
raise e
bot.listen()
except KeyboardInterrupt:
pass
except Exception as e:
log(f"Exception: {e}", 1)
traceback.print_exc()

View File

@@ -42,16 +42,16 @@ raw_help = """\
"""
if not os.path.exists("config.json"):
log("Generating: config.json...")
log("Создание: config.json...")
with open("config.json", "w") as f:
f.write(raw_config)
with open('config.json') as f:
config = json.load(f, object_hook=lambda x: namedtuple('X', x.keys())(*x.values()))
log("Starting..")
log("Запуск..")
if not os.path.exists(config.vk.help_file):
log(f"Generating: {config.vk.help_file}...")
log(f"Создание: {config.vk.help_file}...")
with open(config.vk.help_file, "w") as f:
f.write(raw_help)
@@ -71,7 +71,7 @@ def rcon(cmd):
text = mcr.command(cmd)
return re.sub(r'§.', '', text)
except Exception as e:
log(f"RCON ERROR with command: {cmd}", 1)
log(f"[RCON] ERROR with command: {cmd}", 1)
print(traceback.format_exc())
return f"Rcon error: {e}"