Further cleanup of osu commands
This commit is contained in:
parent
97f9a4e609
commit
a39204b4a9
4 changed files with 51 additions and 56 deletions
|
@ -40,7 +40,7 @@ public partial class Searches
|
||||||
}
|
}
|
||||||
|
|
||||||
var userId = obj.UserId;
|
var userId = obj.UserId;
|
||||||
var smode = ResolveGameMode(obj.ModeNumber);
|
var smode = OsuService.ResolveGameMode(obj.ModeNumber);
|
||||||
|
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
|
@ -69,24 +69,15 @@ public partial class Searches
|
||||||
[Cmd]
|
[Cmd]
|
||||||
public async Task Gatari(string user, [Leftover] string mode = null)
|
public async Task Gatari(string user, [Leftover] string mode = null)
|
||||||
{
|
{
|
||||||
using var http = _httpFactory.CreateClient();
|
var modeNumber = OsuService.ResolveGameMode(mode);
|
||||||
var modeNumber = string.IsNullOrWhiteSpace(mode) ? 0 : ResolveGameMode(mode);
|
var modeStr = OsuService.ResolveGameMode(modeNumber);
|
||||||
|
var (userData, userStats) = await _service.GetGatariDataAsync(user, mode);
|
||||||
var modeStr = ResolveGameMode(modeNumber);
|
if (userStats is null)
|
||||||
var resString = await http.GetStringAsync($"https://api.gatari.pw/user/stats?u={user}&mode={modeNumber}");
|
|
||||||
|
|
||||||
var statsResponse = JsonConvert.DeserializeObject<GatariUserStatsResponse>(resString);
|
|
||||||
if (statsResponse.Code != 200 || statsResponse.Stats.Id == 0)
|
|
||||||
{
|
{
|
||||||
await Response().Error(strs.osu_user_not_found).SendAsync();
|
await Response().Error(strs.osu_user_not_found).SendAsync();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var usrResString = await http.GetStringAsync($"https://api.gatari.pw/users/get?u={user}");
|
|
||||||
|
|
||||||
var userData = JsonConvert.DeserializeObject<GatariUserResponse>(usrResString).Users[0];
|
|
||||||
var userStats = statsResponse.Stats;
|
|
||||||
|
|
||||||
var embed = _sender.CreateEmbed()
|
var embed = _sender.CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle($"osu!Gatari {modeStr} profile for {user}")
|
.WithTitle($"osu!Gatari {modeStr} profile for {user}")
|
||||||
|
@ -122,7 +113,7 @@ public partial class Searches
|
||||||
using var http = _httpFactory.CreateClient();
|
using var http = _httpFactory.CreateClient();
|
||||||
var m = 0;
|
var m = 0;
|
||||||
if (!string.IsNullOrWhiteSpace(mode))
|
if (!string.IsNullOrWhiteSpace(mode))
|
||||||
m = ResolveGameMode(mode);
|
m = OsuService.ResolveGameMode(mode);
|
||||||
|
|
||||||
var reqString = "https://osu.ppy.sh/api/get_user_best"
|
var reqString = "https://osu.ppy.sh/api/get_user_best"
|
||||||
+ $"?k={_creds.OsuApiKey}"
|
+ $"?k={_creds.OsuApiKey}"
|
||||||
|
@ -209,42 +200,6 @@ public partial class Searches
|
||||||
return Math.Round(hitPoints / totalHits * 100, 2);
|
return Math.Round(hitPoints / totalHits * 100, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int ResolveGameMode(string mode)
|
|
||||||
{
|
|
||||||
switch (mode.ToUpperInvariant())
|
|
||||||
{
|
|
||||||
case "STD":
|
|
||||||
case "STANDARD":
|
|
||||||
return 0;
|
|
||||||
case "TAIKO":
|
|
||||||
return 1;
|
|
||||||
case "CTB":
|
|
||||||
case "CATCHTHEBEAT":
|
|
||||||
return 2;
|
|
||||||
case "MANIA":
|
|
||||||
case "OSU!MANIA":
|
|
||||||
return 3;
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string ResolveGameMode(int mode)
|
|
||||||
{
|
|
||||||
switch (mode)
|
|
||||||
{
|
|
||||||
case 0:
|
|
||||||
return "Standard";
|
|
||||||
case 1:
|
|
||||||
return "Taiko";
|
|
||||||
case 2:
|
|
||||||
return "Catch";
|
|
||||||
case 3:
|
|
||||||
return "Mania";
|
|
||||||
default:
|
|
||||||
return "Standard";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//https://github.com/ppy/osu-api/wiki#mods
|
//https://github.com/ppy/osu-api/wiki#mods
|
||||||
private static string ResolveMods(int mods)
|
private static string ResolveMods(int mods)
|
||||||
|
|
|
@ -38,7 +38,7 @@ public sealed class OsuService : IEService
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int ResolveGameMode(string mode)
|
public static int ResolveGameMode(string mode)
|
||||||
{
|
{
|
||||||
switch (mode.ToUpperInvariant())
|
switch (mode.ToUpperInvariant())
|
||||||
{
|
{
|
||||||
|
@ -57,4 +57,44 @@ public sealed class OsuService : IEService
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string ResolveGameMode(int mode)
|
||||||
|
{
|
||||||
|
switch (mode)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return "Standard";
|
||||||
|
case 1:
|
||||||
|
return "Taiko";
|
||||||
|
case 2:
|
||||||
|
return "Catch";
|
||||||
|
case 3:
|
||||||
|
return "Mania";
|
||||||
|
default:
|
||||||
|
return "Standard";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<(GatariUserData userData, GatariUserStats userStats)> GetGatariDataAsync(
|
||||||
|
string user,
|
||||||
|
string mode)
|
||||||
|
{
|
||||||
|
using var http = _httpFactory.CreateClient();
|
||||||
|
var modeNumber = string.IsNullOrWhiteSpace(mode) ? 0 : ResolveGameMode(mode);
|
||||||
|
|
||||||
|
var resString = await http.GetStringAsync($"https://api.gatari.pw/user/stats?u={user}&mode={modeNumber}");
|
||||||
|
|
||||||
|
var statsResponse = JsonConvert.DeserializeObject<GatariUserStatsResponse>(resString);
|
||||||
|
if (statsResponse.Code != 200 || statsResponse.Stats.Id == 0)
|
||||||
|
{
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
|
||||||
|
var usrResString = await http.GetStringAsync($"https://api.gatari.pw/users/get?u={user}");
|
||||||
|
|
||||||
|
var userData = JsonConvert.DeserializeObject<GatariUserResponse>(usrResString).Users[0];
|
||||||
|
var userStats = statsResponse.Stats;
|
||||||
|
|
||||||
|
return (userData, userStats);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@ using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace EllieBot.Modules.Searches.Common;
|
namespace EllieBot.Modules.Searches.Common;
|
||||||
|
|
||||||
public class UserData
|
public class GatariUserData
|
||||||
{
|
{
|
||||||
[JsonProperty("abbr")]
|
[JsonProperty("abbr")]
|
||||||
public object Abbr { get; set; }
|
public object Abbr { get; set; }
|
||||||
|
@ -48,5 +48,5 @@ public class GatariUserResponse
|
||||||
public int Code { get; set; }
|
public int Code { get; set; }
|
||||||
|
|
||||||
[JsonProperty("users")]
|
[JsonProperty("users")]
|
||||||
public List<UserData> Users { get; set; }
|
public List<GatariUserData> Users { get; set; }
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@ using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace EllieBot.Modules.Searches.Common;
|
namespace EllieBot.Modules.Searches.Common;
|
||||||
|
|
||||||
public class UserStats
|
public class GatariUserStats
|
||||||
{
|
{
|
||||||
[JsonProperty("a_count")]
|
[JsonProperty("a_count")]
|
||||||
public int ACount { get; set; }
|
public int ACount { get; set; }
|
||||||
|
@ -72,5 +72,5 @@ public class GatariUserStatsResponse
|
||||||
public int Code { get; set; }
|
public int Code { get; set; }
|
||||||
|
|
||||||
[JsonProperty("stats")]
|
[JsonProperty("stats")]
|
||||||
public UserStats Stats { get; set; }
|
public GatariUserStats Stats { get; set; }
|
||||||
}
|
}
|
Loading…
Reference in a new issue