minestatsping/online.py

43 lines
779 B
Python
Raw Normal View History

2023-02-03 20:33:10 +00:00
from mctools import PINGClient
import telebot
from db import *
API_TOKEN = read()['token']
2023-02-03 20:33:10 +00:00
bot = telebot.TeleBot(API_TOKEN)
ping = PINGClient('CoolFunZone.aternos.me', 36413)
2023-02-03 20:33:10 +00:00
stats = ping.get_stats()
print(stats)
@bot.message_handler(commands=['online'])
def check_online(message):
try:
stats = ping.get_stats()
except:
bot.reply_to(message, "🔴 Сервер оффлайн")
return 0
2023-02-03 20:33:10 +00:00
maxp = stats['players']['max']
onp = stats['players']['online']
2023-02-03 20:33:10 +00:00
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 = ''
2023-02-03 20:33:10 +00:00
bot.reply_to(message, f"""🟢 Игроки онлайн >> {onp}/{maxp}
2023-02-03 20:33:10 +00:00
{pp}""")
bot.infinity_polling()