From 3ea8e473bfbaecbc58da69a85c9b751cb7dc4147 Mon Sep 17 00:00:00 2001 From: Dima YaFlay <93622229+YaFlay@users.noreply.github.com> Date: Sat, 21 May 2022 00:26:36 +0300 Subject: [PATCH] Change sended message Add deleting logs before command, change .sh file --- main.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 61db9cf..8167605 100644 --- a/main.py +++ b/main.py @@ -1,18 +1,23 @@ # in your server config socketInput should be default (localhost) - from datetime import datetime + +from datetime import datetime import os import sys import logging from aiogram import * from aiogram.types import ContentType -BOT_TOKEN = 'UR TOKEN' + + +BOT_TOKEN = '' bot = Bot(token=BOT_TOKEN, parse_mode="HTML") dp = Dispatcher(bot) main_path = __file__.replace(os.path.basename(__file__), '') - +with open(f'{main_path}/run_server.sh', 'r+') as file: fileShReplace = file.read(); file.close() +with open(f'{main_path}/run_server.sh', 'w+') as file: file.close() +with open(f'{main_path}/run_server.sh', 'r+') as file: file.write(fileShReplace.replace('echo "config socketInput true" | ', '')) logging.basicConfig(level=logging.INFO) logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] %(message)s") rootLogger = logging.getLogger() @@ -28,19 +33,29 @@ def server_connect(text): @dp.message_handler(content_types= ContentType.TEXT) async def command(message: types.message): + if not os.path.isfile(f'{main_path}/config/logs/copy-log.log'): file = open(f'{main_path}/config/logs/copy-log.log', 'x'); file.close() + with open(f'{main_path}/config/logs/log-0.txt', 'r') as file: + with open(f'{main_path}/config/logs/copy-log.log', 'r+') as file2: + file2.write(file.read()) + file2.close() + file.close() + with open(f'{main_path}/config/logs/log-0.txt', 'w+') as file: + file.close() now = datetime.now() date_time = now.strftime("%m-%d-%Y %H:%M:%S") server_connect(message.text) rootLogger.info(message.text) await message.reply('Command entried!') with open(f'{main_path}/config/logs/log-0.txt', mode='r') as file: - text = file.read().replace("<", '').replace(">", '').replace(f"[{date_time}]", '').replace('Received command socket connection: localhost/127.0.0.1:6859', '').replace('Lost command socket connection: localhost/127.0.0.1:6859', '').replace('[I]', '').encode('utf8') + text = file.read().replace("<", '(').replace(">", ')').replace(f"[{date_time}]", '').replace('Received command socket connection: localhost/127.0.0.1:6859', '').replace('Lost command socket connection: localhost/127.0.0.1:6859', '').replace('[I]', '').encode('utf8') if len(text) > 4096: for x in range(0, len(text), 4096): await message.answer(text[x:x+4096].decode('utf8')) else: + try: await message.answer(text.decode('utf8')) - # await message.answer(f'''output: {text}''') + except: + await message.answer(f'Server don`t reply.') with open(f'{main_path}/config/logs/log-0.txt', 'w+') as file: file.close() file.close() @@ -53,4 +68,3 @@ try: executor.start_polling(dp, skip_updates=False) except Exception: sys.exit() -