From 7af9ba69661905a67d8079f6b1f02046c90b7a64 Mon Sep 17 00:00:00 2001 From: none Date: Sat, 2 Mar 2024 15:05:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D0=BE=D0=B2=20=D0=B2=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=20=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D1=82=D0=B0=D1=82?= =?UTF-8?q?=D1=83=D1=81=D0=B0=20=D0=BE=D1=84=D1=84=D0=BB=D0=B0=D0=B9=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db.py | 20 ++++++++++++++++++++ online.py | 26 ++++++++++++++++---------- 2 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 db.py diff --git a/db.py b/db.py new file mode 100644 index 0000000..7c86df9 --- /dev/null +++ b/db.py @@ -0,0 +1,20 @@ +import os +import json + +if not os.path.exists('config.json'): + db = {} + js = json.dumps(db, indent=2) + with open("config.json", "w") as outfile: + outfile.write(js) + print('Created new config.json') + + +def read(file = 'config.json'): + with open(file, "r", encoding="utf-8") as openfile: + db = json.load(openfile) + return db + +def write(db, file = 'config.json'): + js = json.dumps(db, indent=2, ensure_ascii=False) + with open(file, "w", encoding="utf-8") as outfile: + outfile.write(js) diff --git a/online.py b/online.py index 1259c43..b685251 100644 --- a/online.py +++ b/online.py @@ -1,21 +1,27 @@ from mctools import PINGClient -ping = PINGClient('135.181.170.94', 25630) - import telebot -API_TOKEN = '6142777478:AAHTyrHPhr8j0jWoSEIyPvpvmozVp6axLKE' + +from db import * + +API_TOKEN = read()['token'] bot = telebot.TeleBot(API_TOKEN) +ping = PINGClient('CoolFunZone.aternos.me', 36413) stats = ping.get_stats() print(stats) @bot.message_handler(commands=['online']) -def send_welcome(message): - stats = ping.get_stats() - +def check_online(message): + try: + stats = ping.get_stats() + except: + bot.reply_to(message, "🔴 Сервер оффлайн") + return 0 + maxp = stats['players']['max'] - onp= stats['players']['online'] - + onp = stats['players']['online'] + try: first = True for i in stats['players']['sample']: @@ -26,9 +32,9 @@ def send_welcome(message): pp = pp+ ' ; ' +i[0][:i[0].find('[')] except: pp = '' - + bot.reply_to(message, f"""🟢 Игроки онлайн >> {onp}/{maxp} - + {pp}""")