You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.1 KiB

2 years ago
from mctools import PINGClient
import telebot
from db import *
API_TOKEN = read()['token']
2 years ago
bot = telebot.TeleBot(API_TOKEN)
host = 'CoolFunZone.aternos.me'
port = 36413
8 months ago
# 764 - 1.20.2
prot = 764
global c
c = PINGClient(host, port, proto_num = prot)
2 years ago
@bot.message_handler(commands=['online'])
def check_online(message):
global c
try:
stats = c.get_stats()
ms = c.ping()
except:
bot.reply_to(message, "🔴 Сервер оффлайн")
c.stop()
c = PINGClient(host, port, proto_num = prot)
return 0
2 years ago
maxp = stats['players']['max']
onp = stats['players']['online']
8 months ago
# Фикс для aternos
if maxp == 0:
bot.reply_to(message, "🔴 Сервер оффлайн")
return 0
2 years ago
try:
first = True
for i in stats['players']['sample']:
if first == True:
pp = i[0][:i[0].find('[')]
first = False
else:
pp = pp+ ' ; ' +i[0][:i[0].find('[')]
except:
pp = ''
2 years ago
bot.reply_to(message, f"""🟢 Игроки онлайн >> {onp}/{maxp}
{pp}
📡 {round(ms)} ms""")
2 years ago
8 months ago
while True:
try:
bot.infinity_polling()
except KeyboardInterrupt:
exit()
except:
pass
2 years ago