from mctools import RCONClient import telebot from db import * db = read() TOKEN = db['token'] RCON_HOST = db['RCON_HOST'] RCON_PORT = db['RCON_PORT'] RCON_PASS = db['RCON_PASS'] RCON = RCONClient(RCON_HOST, port=RCON_PORT) RCON.login(RCON_PASS) bot = telebot.TeleBot(TOKEN) import re def clear_line(text): ansi_escape = re.compile(r'\x1B[@-_][0-?]*[ -/]*[@-~]') return ansi_escape.sub('', text) @bot.message_handler(commands=['online']) def check_online(message): global RCON if RCON.is_authenticated() == False: try: RCON.stop() except: pass RCON = RCONClient(RCON_HOST, port=RCON_PORT) RCON.login(RCON_PASS) resp = clear_line(RCON.command('list')).replace(',','') resp_split = resp.split() pl_list = resp_split[8:] maxp = resp_split[3] onp = 0 players = '' first = True for i in pl_list: if '[СКРЫТ]' in i: continue elif first == True: players += i first = False else: players += ' ; ' + i onp += 1 bot.reply_to(message, f"""🟢 Игроки онлайн >> {onp}/{maxp} {players}""") # while True: # try: # bot.infinity_polling() # except KeyboardInterrupt: # exit() # except: # pass bot.infinity_polling()