mirror of
https://github.com/RPCS3/discord-bot.git
synced 2026-01-31 01:25:22 +01:00
use enum for compat api status codes
This commit is contained in:
@@ -7,7 +7,7 @@ using NLog;
|
||||
|
||||
namespace CompatApiClient;
|
||||
|
||||
using ReturnCodeType = Dictionary<int, (bool displayResults, bool overrideAll, bool displayFooter, string info)>;
|
||||
using ReturnCodeType = Dictionary<CompatApiStatus, (bool displayResults, bool overrideAll, bool displayFooter, string info)>;
|
||||
|
||||
public static class ApiConfig
|
||||
{
|
||||
@@ -22,12 +22,12 @@ public static class ApiConfig
|
||||
|
||||
public static readonly ReturnCodeType ReturnCodes = new()
|
||||
{
|
||||
[0] = (true, false, true, "Results successfully retrieved."),
|
||||
[1] = (false, false, true, "No results."),
|
||||
[2] = (true, false, true, "No match was found, displaying results for: ***{0}***."),
|
||||
[-1] = (false, true, false, "{0}: Internal error occurred, please contact Ani and Nicba1010"),
|
||||
[-2] = (false, true, false, "{0}: API is undergoing maintenance, please try again later."),
|
||||
[-3] = (false, false, false, "Illegal characters found, please try again with a different search term."),
|
||||
[CompatApiStatus.Success] = (true, false, true, "Results successfully retrieved."),
|
||||
[CompatApiStatus.NoResults] = (false, false, true, "No results."),
|
||||
[CompatApiStatus.NoExactMatch] = (true, false, true, "No match was found, displaying results for: ***{0}***."),
|
||||
[CompatApiStatus.InternalError] = (false, true, false, "{0}: Internal error occurred, please contact Ani and Nicba1010"),
|
||||
[CompatApiStatus.Maintenance] = (false, true, false, "{0}: API is undergoing maintenance, please try again later."),
|
||||
[CompatApiStatus.IllegalQuery] = (false, false, false, "Illegal characters found, please try again with a different search term."),
|
||||
};
|
||||
|
||||
public static readonly List<int> ResultAmount = [25, 50, 100, 200];
|
||||
|
||||
11
Clients/CompatApiClient/CompatApiStatus.cs
Normal file
11
Clients/CompatApiClient/CompatApiStatus.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace CompatApiClient;
|
||||
|
||||
public enum CompatApiStatus: short
|
||||
{
|
||||
IllegalQuery = -3,
|
||||
Maintenance = -2,
|
||||
InternalError = -1,
|
||||
Success = 0,
|
||||
NoResults = 1,
|
||||
NoExactMatch = 2,
|
||||
}
|
||||
@@ -7,7 +7,7 @@ namespace CompatApiClient.POCOs;
|
||||
|
||||
public class CompatResult
|
||||
{
|
||||
public int ReturnCode;
|
||||
public CompatApiStatus ReturnCode;
|
||||
public string SearchTerm;
|
||||
public Dictionary<string, TitleInfo> Results;
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ internal static partial class CompatList
|
||||
var result = new CompatResult
|
||||
{
|
||||
RequestBuilder = requestBuilder,
|
||||
ReturnCode = 0,
|
||||
ReturnCode = CompatApiStatus.Success,
|
||||
SearchTerm = requestBuilder.Search,
|
||||
Results = matches.ToDictionary(i => i.thumb.ProductCode, i => new TitleInfo
|
||||
{
|
||||
|
||||
@@ -106,7 +106,7 @@ internal static partial class IsTheGamePlayableHandler
|
||||
var status = await searchCompatListTask.ConfigureAwait(false);
|
||||
status = status?.Append(localList);
|
||||
if (status is null
|
||||
|| status.ReturnCode != 0 && status.ReturnCode != 2
|
||||
|| status.ReturnCode is not CompatApiStatus.Success and not CompatApiStatus.NoExactMatch
|
||||
|| status.Results.Count is 0)
|
||||
return (null, null);
|
||||
|
||||
|
||||
@@ -127,13 +127,13 @@ internal static partial class ProductCodeLookup
|
||||
var localList = await CompatList.GetLocalCompatResultAsync(requestBuilder).ConfigureAwait(false);
|
||||
var status = await searchCompatListTask.ConfigureAwait(false);
|
||||
result = status?.Append(localList);
|
||||
if (result?.ReturnCode == -2)
|
||||
if (result?.ReturnCode is CompatApiStatus.Maintenance)
|
||||
return (
|
||||
await TitleInfo.Maintenance.AsEmbedAsync(code).ConfigureAwait(false),
|
||||
result
|
||||
);
|
||||
|
||||
if (result?.ReturnCode == -1)
|
||||
if (result?.ReturnCode is CompatApiStatus.InternalError)
|
||||
return (
|
||||
await TitleInfo.CommunicationError.AsEmbedAsync(code).ConfigureAwait(false),
|
||||
result
|
||||
|
||||
Reference in New Issue
Block a user