Перенос конфигов в файл и добавление статуса оффлайн

main
none 8 months ago
parent a5a386ec2a
commit 7af9ba6966

20
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)

@ -1,20 +1,26 @@
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

Loading…
Cancel
Save