-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonline.py
63 lines (48 loc) · 1.08 KB
/
online.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from mctools import PINGClient
import telebot
from db import *
API_TOKEN = read()['token']
bot = telebot.TeleBot(API_TOKEN)
host = 'CoolFunZone.aternos.me'
port = 36413
# 764 - 1.20.2
prot = 764
global c
c = PINGClient(host, port, proto_num = prot)
@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
maxp = stats['players']['max']
onp = stats['players']['online']
# Фикс для aternos
if maxp == 0:
bot.reply_to(message, "🔴 Сервер оффлайн")
return 0
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 = ''
bot.reply_to(message, f"""🟢 Игроки онлайн >> {onp}/{maxp}
{pp}
📡 {round(ms)} ms""")
while True:
try:
bot.infinity_polling()
except KeyboardInterrupt:
exit()
except:
pass