mirror of
https://github.com/RPCS3/discord-bot.git
synced 2024-11-23 02:09:38 +00:00
minor code cleanup
This commit is contained in:
parent
965236ae52
commit
e8fd467a73
@ -37,27 +37,27 @@ public static class CirrusCi
|
||||
queryResult.EnsureNoErrors();
|
||||
if (queryResult.Data?.OwnerRepository?.Builds?.Edges is {Count: > 0} edgeList)
|
||||
{
|
||||
var node = edgeList.LastOrDefault(e => e?.Node?.ChangeIdInRepo == commit)?.Node;
|
||||
var node = edgeList.LastOrDefault(e => e.Node.ChangeIdInRepo == commit)?.Node;
|
||||
if (node is null)
|
||||
return null;
|
||||
|
||||
var winTask = node.Tasks?.FirstOrDefault(t => t?.Name.Contains("Windows") ?? false);
|
||||
var winArtifact = winTask?.Artifacts?
|
||||
.Where(a => a?.Files is {Count: >0})
|
||||
.SelectMany(a => a!.Files!)
|
||||
.FirstOrDefault(f => f?.Path.EndsWith(".7z") ?? false);
|
||||
var winTask = node.Tasks.FirstOrDefault(t => t.Name.Contains("Windows"));
|
||||
var winArtifact = winTask?.Artifacts
|
||||
.Where(a => a.Files is {Count: >0})
|
||||
.SelectMany(a => a.Files)
|
||||
.FirstOrDefault(f => f.Path.EndsWith(".7z"));
|
||||
|
||||
var linTask = node.Tasks?.FirstOrDefault(t => t is {} lt && lt.Name.Contains("Linux") && lt.Name.Contains("GCC"));
|
||||
var linArtifact = linTask?.Artifacts?
|
||||
.Where(a => a?.Files is {Count: >0})
|
||||
.SelectMany(a => a!.Files!)
|
||||
.FirstOrDefault(a => a?.Path.EndsWith(".AppImage") ?? false);
|
||||
var linTask = node.Tasks.FirstOrDefault(t => t is {} lt && lt.Name.Contains("Linux") && lt.Name.Contains("GCC"));
|
||||
var linArtifact = linTask?.Artifacts
|
||||
.Where(a => a.Files is {Count: >0})
|
||||
.SelectMany(a => a.Files)
|
||||
.FirstOrDefault(a => a.Path.EndsWith(".AppImage"));
|
||||
|
||||
var macTask = node.Tasks?.FirstOrDefault(t => t?.Name.Contains("macOS") ?? false);
|
||||
var macArtifact = macTask?.Artifacts?
|
||||
.Where(a => a?.Files is { Count: > 0 })
|
||||
.SelectMany(a => a!.Files!)
|
||||
.FirstOrDefault(a => a?.Path.EndsWith(".dmg") ?? false);
|
||||
var macTask = node.Tasks.FirstOrDefault(t => t.Name.Contains("macOS"));
|
||||
var macArtifact = macTask?.Artifacts
|
||||
.Where(a => a.Files is { Count: > 0 })
|
||||
.SelectMany(a => a.Files)
|
||||
.FirstOrDefault(a => a.Path.EndsWith(".dmg"));
|
||||
|
||||
var startTime = FromTimestamp(node.BuildCreatedTimestamp);
|
||||
var finishTime = GetFinishTime(node);
|
||||
@ -142,7 +142,7 @@ public static class CirrusCi
|
||||
? FromTimestamp(finalTimes.Max()!.Value)
|
||||
: node.ClockDurationInSeconds > 0
|
||||
? FromTimestamp(node.BuildCreatedTimestamp).AddSeconds(node.ClockDurationInSeconds.Value)
|
||||
: (DateTime?)null;
|
||||
: null;
|
||||
|
||||
[return: NotNullIfNotNull(nameof(DateTime))]
|
||||
private static string? ToTimestamp(this DateTime? dateTime) => dateTime.HasValue ? (dateTime.Value.ToUniversalTime() - DateTime.UnixEpoch).TotalMilliseconds.ToString("0") : null;
|
||||
|
@ -22,59 +22,57 @@ 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.") },
|
||||
[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."),
|
||||
};
|
||||
|
||||
public static readonly List<int> ResultAmount = [25, 50, 100, 200];
|
||||
|
||||
public static readonly Dictionary<char, string[]> Directions = new()
|
||||
{
|
||||
{'a', ["a", "asc", "ascending"] },
|
||||
{'d', ["d", "desc", "descending"] },
|
||||
['a'] = ["a", "asc", "ascending"],
|
||||
['d'] = ["d", "desc", "descending"],
|
||||
};
|
||||
|
||||
public static readonly Dictionary<string, int> Statuses = new()
|
||||
{
|
||||
{"all", 0 },
|
||||
{"playable", 1 },
|
||||
{"ingame", 2 },
|
||||
{"intro", 3 },
|
||||
{"loadable", 4 },
|
||||
{"nothing", 5 },
|
||||
["all"] = 0,
|
||||
["playable"] = 1,
|
||||
["ingame"] = 2,
|
||||
["intro"] = 3,
|
||||
["loadable"] = 4,
|
||||
["nothing"] = 5,
|
||||
};
|
||||
|
||||
public static readonly Dictionary<string, int> SortTypes = new()
|
||||
{
|
||||
{"id", 1 },
|
||||
{"title", 2 },
|
||||
{"status", 3 },
|
||||
{"date", 4 },
|
||||
["id"] = 1,
|
||||
["title"] = 2,
|
||||
["status"] = 3,
|
||||
["date"] = 4,
|
||||
};
|
||||
|
||||
public static readonly Dictionary<char, string[]> ReleaseTypes = new()
|
||||
{
|
||||
{'b', ["b", "d", "disc", "disk", "bluray", "blu-ray"] },
|
||||
{'n', ["n", "p", "PSN"] },
|
||||
['b'] = ["b", "d", "disc", "disk", "bluray", "blu-ray"],
|
||||
['n'] = ["n", "p", "PSN"],
|
||||
};
|
||||
|
||||
public static readonly Dictionary<string, char> ReverseDirections;
|
||||
public static readonly Dictionary<string, char> ReverseReleaseTypes;
|
||||
|
||||
private static Dictionary<TV, TK> Reverse<TK, TV>(this Dictionary<TK, TV[]> dic, IEqualityComparer<TV> comparer)
|
||||
where TK: notnull
|
||||
where TV: notnull
|
||||
{
|
||||
return (
|
||||
where TK : notnull
|
||||
where TV : notnull
|
||||
=> (
|
||||
from kvp in dic
|
||||
from val in kvp.Value
|
||||
select (val, kvp.Key)
|
||||
).ToDictionary(rkvp => rkvp.val, rkvp => rkvp.Key, comparer);
|
||||
}
|
||||
|
||||
public static readonly ILogger Log;
|
||||
public static readonly RecyclableMemoryStreamManager MemoryStreamManager = new();
|
||||
|
@ -22,7 +22,7 @@ public class Client: IDisposable
|
||||
public Client()
|
||||
{
|
||||
client = HttpClientFactory.Create(new CompressionMessageHandler());
|
||||
jsonOptions = new JsonSerializerOptions
|
||||
jsonOptions = new()
|
||||
{
|
||||
PropertyNamingPolicy = SpecialJsonNamingPolicy.SnakeCase,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
@ -46,7 +46,7 @@ public class Client: IDisposable
|
||||
using var response = await client.SendAsync(message, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await response.Content.LoadIntoBufferAsync().ConfigureAwait(false);
|
||||
await response.Content.LoadIntoBufferAsync(cancellationToken).ConfigureAwait(false);
|
||||
var result = await response.Content.ReadFromJsonAsync<CompatResult>(jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
if (result != null)
|
||||
{
|
||||
@ -84,7 +84,7 @@ public class Client: IDisposable
|
||||
using var response = await client.SendAsync(message, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await response.Content.LoadIntoBufferAsync().ConfigureAwait(false);
|
||||
await response.Content.LoadIntoBufferAsync(cancellationToken).ConfigureAwait(false);
|
||||
result = await response.Content.ReadFromJsonAsync<CompatResult>(jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||
if (result != null)
|
||||
ResponseCache.Set(url, result, TimeSpan.FromDays(1));
|
||||
|
@ -3,13 +3,6 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<LangVersion>latest</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
|
@ -21,11 +21,7 @@ public class CompressionMessageHandler : DelegatingHandler
|
||||
{
|
||||
this.isServer = isServer;
|
||||
isClient = !isServer;
|
||||
Compressors = new ICompressor[]
|
||||
{
|
||||
new GZipCompressor(),
|
||||
new DeflateCompressor(),
|
||||
};
|
||||
Compressors = [new GZipCompressor(), new DeflateCompressor()];
|
||||
}
|
||||
|
||||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
|
||||
|
@ -76,7 +76,7 @@ public static class UriExtensions
|
||||
if (value == null)
|
||||
continue;
|
||||
|
||||
result.AppendFormat("&{0}={1}", Uri.EscapeDataString(key), Uri.EscapeDataString(value));
|
||||
result.Append($"&{Uri.EscapeDataString(key)}={Uri.EscapeDataString(value)}");
|
||||
}
|
||||
if (result.Length == 0)
|
||||
return "";
|
||||
@ -103,7 +103,7 @@ public static class UriExtensions
|
||||
}
|
||||
else
|
||||
{
|
||||
var startWithSlash = uri.OriginalString.StartsWith("/");
|
||||
var startWithSlash = uri.OriginalString.StartsWith('/');
|
||||
uri = new(FakeHost, uri);
|
||||
var builder = new UriBuilder(uri) { Query = value };
|
||||
var additionalStrip = startWithSlash ? 0 : 1;
|
||||
|
@ -47,11 +47,11 @@ public static class IrdParser
|
||||
result.FooterLength = reader.ReadInt32();
|
||||
result.Footer = reader.ReadBytes(result.FooterLength);
|
||||
result.RegionCount = reader.ReadByte();
|
||||
result.RegionMd5Checksums = new List<byte[]>(result.RegionCount);
|
||||
result.RegionMd5Checksums = new(result.RegionCount);
|
||||
for (var i = 0; i < result.RegionCount; i++)
|
||||
result.RegionMd5Checksums.Add(reader.ReadBytes(16));
|
||||
result.FileCount = reader.ReadInt32();
|
||||
result.Files = new List<IrdFile>(result.FileCount);
|
||||
result.Files = new(result.FileCount);
|
||||
for (var i = 0; i < result.FileCount; i++)
|
||||
{
|
||||
// ReSharper disable once UseObjectOrCollectionInitializer
|
||||
|
Loading…
Reference in New Issue
Block a user