fix player count game status

This commit is contained in:
Дмитрий Шиманский
2023-11-16 23:47:28 +03:00
parent defc302ac9
commit d0c56b4139
3 changed files with 98 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ using Discord.Interactions;
using Discord.WebSocket;
using DiscordApp.Database;
using DiscordApp.Justice.Commands;
using DiscordApp.Types;
using Microsoft.VisualBasic;
using Newtonsoft.Json;
using System.Reflection;
@@ -50,10 +51,9 @@ namespace DiscordApp
try
{
var request = await http.GetAsync("https://api.mcsrvstat.us/3/pl.spworlds.ru");
JsonNode responseAboutPL = JsonNode.Parse(request.Content.ReadAsStringAsync().Result);
bool result;
if (bool.TryParse(responseAboutPL["online"].ToString(), out result) || result) await client.SetGameAsync($"выключенный PL", "https://yaflay.ru/", ActivityType.Watching);
else await client.SetGameAsync($"онлайн на PL: {responseAboutPL["players"]["online"]}", "https://yaflay.ru/", ActivityType.Watching);
var responseAboutPL = JsonConvert.DeserializeObject<ServerResponse>(request.Content.ReadAsStringAsync().Result);
if (!responseAboutPL.online) await client.SetGameAsync($"выключенный PL", "https://yawaflua.ru/", ActivityType.Watching);
else await client.SetGameAsync($"онлайн на PL: {responseAboutPL.players.online}", "https://yawaflua.ru/", ActivityType.Watching);
}
finally
{

View File

@@ -138,7 +138,7 @@ namespace DiscordApp
}
else
{
throw new Exception("Unknown error from site!");
throw new Exception($"Unknown error from site! {request.Content.ReadAsStringAsync().Result}") ;
}
}
catch (Exception ex)

93
Types/ServerResponse.cs Normal file
View File

@@ -0,0 +1,93 @@
namespace DiscordApp.Types
{
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class A
{
public string name { get; set; }
public string type { get; set; }
public string @class { get; set; }
public int ttl { get; set; }
public int rdlength { get; set; }
public string rdata { get; set; }
public string cname { get; set; }
public string address { get; set; }
}
public class Debug
{
public bool ping { get; set; }
public bool query { get; set; }
public bool srv { get; set; }
public bool querymismatch { get; set; }
public bool ipinsrv { get; set; }
public bool cnameinsrv { get; set; }
public bool animatedmotd { get; set; }
public bool cachehit { get; set; }
public int cachetime { get; set; }
public int cacheexpire { get; set; }
public int apiversion { get; set; }
public Dns dns { get; set; }
public Error error { get; set; }
}
public class Dns
{
public Error error { get; set; }
public List<A> a { get; set; }
}
public class Error
{
public Srv srv { get; set; }
public string query { get; set; }
}
public class List
{
public string name { get; set; }
public string uuid { get; set; }
}
public class Motd
{
public List<string> raw { get; set; }
public List<string> clean { get; set; }
public List<string> html { get; set; }
}
public class Players
{
public int online { get; set; }
public int max { get; set; }
public List<List> list { get; set; }
}
public class Protocol
{
public int version { get; set; }
public string name { get; set; }
}
public class ServerResponse
{
public string ip { get; set; }
public int port { get; set; }
public Debug debug { get; set; }
public Motd motd { get; set; }
public Players players { get; set; }
public string version { get; set; }
public bool online { get; set; }
public Protocol protocol { get; set; }
public string hostname { get; set; }
public string icon { get; set; }
public string software { get; set; }
public bool eula_blocked { get; set; }
}
public class Srv
{
public string hostname { get; set; }
public string message { get; set; }
}
}