run dotnet format

This commit is contained in:
spiral 2021-08-27 11:03:47 -04:00
parent 05989242f9
commit ac2671452d
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
278 changed files with 1913 additions and 1808 deletions

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using Myriad.Types; using Myriad.Types;
@ -11,66 +11,71 @@ namespace Myriad.Builders
public EmbedBuilder Title(string? title) public EmbedBuilder Title(string? title)
{ {
_embed = _embed with {Title = title}; _embed = _embed with { Title = title };
return this; return this;
} }
public EmbedBuilder Description(string? description) public EmbedBuilder Description(string? description)
{ {
_embed = _embed with { Description = description}; _embed = _embed with { Description = description };
return this; return this;
} }
public EmbedBuilder Url(string? url) public EmbedBuilder Url(string? url)
{ {
_embed = _embed with {Url = url}; _embed = _embed with { Url = url };
return this; return this;
} }
public EmbedBuilder Color(uint? color) public EmbedBuilder Color(uint? color)
{ {
_embed = _embed with {Color = color}; _embed = _embed with { Color = color };
return this; return this;
} }
public EmbedBuilder Footer(Embed.EmbedFooter? footer) public EmbedBuilder Footer(Embed.EmbedFooter? footer)
{ {
_embed = _embed with { _embed = _embed with
{
Footer = footer Footer = footer
}; };
return this; return this;
} }
public EmbedBuilder Image(Embed.EmbedImage? image) public EmbedBuilder Image(Embed.EmbedImage? image)
{ {
_embed = _embed with { _embed = _embed with
{
Image = image Image = image
}; };
return this; return this;
} }
public EmbedBuilder Thumbnail(Embed.EmbedThumbnail? thumbnail) public EmbedBuilder Thumbnail(Embed.EmbedThumbnail? thumbnail)
{ {
_embed = _embed with { _embed = _embed with
{
Thumbnail = thumbnail Thumbnail = thumbnail
}; };
return this; return this;
} }
public EmbedBuilder Author(Embed.EmbedAuthor? author) public EmbedBuilder Author(Embed.EmbedAuthor? author)
{ {
_embed = _embed with { _embed = _embed with
{
Author = author Author = author
}; };
return this; return this;
} }
public EmbedBuilder Timestamp(string? timestamp) public EmbedBuilder Timestamp(string? timestamp)
{ {
_embed = _embed with { _embed = _embed with
{
Timestamp = timestamp Timestamp = timestamp
}; };
return this; return this;
} }

View File

@ -1,4 +1,4 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Myriad.Gateway; using Myriad.Gateway;

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Myriad.Types; using Myriad.Types;

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -70,9 +70,11 @@ namespace Myriad.Cache
if (!found) if (!found)
{ {
_guilds[guildId] = guild with { _guilds[guildId] = guild with
Guild = guild.Guild with { {
Roles = guild.Guild.Roles.Concat(new[] { role}).ToArray() Guild = guild.Guild with
{
Roles = guild.Guild.Roles.Concat(new[] { role }).ToArray()
} }
}; };
} }

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Myriad.Cache; using Myriad.Cache;

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Extensions namespace Myriad.Extensions
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Extensions namespace Myriad.Extensions
{ {
public static class GuildExtensions public static class GuildExtensions
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Gateway; using Myriad.Gateway;
using Myriad.Types; using Myriad.Types;
namespace Myriad.Extensions namespace Myriad.Extensions

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View File

@ -1,4 +1,4 @@
using System; using System;
using Myriad.Types; using Myriad.Types;

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Extensions namespace Myriad.Extensions
{ {

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Gateway namespace Myriad.Gateway
{ {
public record GuildDeleteEvent(ulong Id, bool Unavailable): IGatewayEvent; public record GuildDeleteEvent(ulong Id, bool Unavailable): IGatewayEvent;
} }

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Gateway namespace Myriad.Gateway
{ {
public record GuildRoleDeleteEvent(ulong GuildId, ulong RoleId): IGatewayEvent; public record GuildRoleDeleteEvent(ulong GuildId, ulong RoleId): IGatewayEvent;
} }

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace Myriad.Gateway namespace Myriad.Gateway
@ -7,33 +7,33 @@ namespace Myriad.Gateway
{ {
public static readonly Dictionary<string, Type> EventTypes = new() public static readonly Dictionary<string, Type> EventTypes = new()
{ {
{"READY", typeof(ReadyEvent)}, { "READY", typeof(ReadyEvent) },
{"RESUMED", typeof(ResumedEvent)}, { "RESUMED", typeof(ResumedEvent) },
{"GUILD_CREATE", typeof(GuildCreateEvent)}, { "GUILD_CREATE", typeof(GuildCreateEvent) },
{"GUILD_UPDATE", typeof(GuildUpdateEvent)}, { "GUILD_UPDATE", typeof(GuildUpdateEvent) },
{"GUILD_DELETE", typeof(GuildDeleteEvent)}, { "GUILD_DELETE", typeof(GuildDeleteEvent) },
{"GUILD_MEMBER_ADD", typeof(GuildMemberAddEvent)}, { "GUILD_MEMBER_ADD", typeof(GuildMemberAddEvent) },
{"GUILD_MEMBER_REMOVE", typeof(GuildMemberRemoveEvent)}, { "GUILD_MEMBER_REMOVE", typeof(GuildMemberRemoveEvent) },
{"GUILD_MEMBER_UPDATE", typeof(GuildMemberUpdateEvent)}, { "GUILD_MEMBER_UPDATE", typeof(GuildMemberUpdateEvent) },
{"GUILD_ROLE_CREATE", typeof(GuildRoleCreateEvent)}, { "GUILD_ROLE_CREATE", typeof(GuildRoleCreateEvent) },
{"GUILD_ROLE_UPDATE", typeof(GuildRoleUpdateEvent)}, { "GUILD_ROLE_UPDATE", typeof(GuildRoleUpdateEvent) },
{"GUILD_ROLE_DELETE", typeof(GuildRoleDeleteEvent)}, { "GUILD_ROLE_DELETE", typeof(GuildRoleDeleteEvent) },
{"CHANNEL_CREATE", typeof(ChannelCreateEvent)}, { "CHANNEL_CREATE", typeof(ChannelCreateEvent) },
{"CHANNEL_UPDATE", typeof(ChannelUpdateEvent)}, { "CHANNEL_UPDATE", typeof(ChannelUpdateEvent) },
{"CHANNEL_DELETE", typeof(ChannelDeleteEvent)}, { "CHANNEL_DELETE", typeof(ChannelDeleteEvent) },
{"THREAD_CREATE", typeof(ThreadCreateEvent)}, { "THREAD_CREATE", typeof(ThreadCreateEvent) },
{"THREAD_UPDATE", typeof(ThreadUpdateEvent)}, { "THREAD_UPDATE", typeof(ThreadUpdateEvent) },
{"THREAD_DELETE", typeof(ThreadDeleteEvent)}, { "THREAD_DELETE", typeof(ThreadDeleteEvent) },
{"THREAD_LIST_SYNC", typeof(ThreadListSyncEvent)}, { "THREAD_LIST_SYNC", typeof(ThreadListSyncEvent) },
{"MESSAGE_CREATE", typeof(MessageCreateEvent)}, { "MESSAGE_CREATE", typeof(MessageCreateEvent) },
{"MESSAGE_UPDATE", typeof(MessageUpdateEvent)}, { "MESSAGE_UPDATE", typeof(MessageUpdateEvent) },
{"MESSAGE_DELETE", typeof(MessageDeleteEvent)}, { "MESSAGE_DELETE", typeof(MessageDeleteEvent) },
{"MESSAGE_DELETE_BULK", typeof(MessageDeleteBulkEvent)}, { "MESSAGE_DELETE_BULK", typeof(MessageDeleteBulkEvent) },
{"MESSAGE_REACTION_ADD", typeof(MessageReactionAddEvent)}, { "MESSAGE_REACTION_ADD", typeof(MessageReactionAddEvent) },
{"MESSAGE_REACTION_REMOVE", typeof(MessageReactionRemoveEvent)}, { "MESSAGE_REACTION_REMOVE", typeof(MessageReactionRemoveEvent) },
{"MESSAGE_REACTION_REMOVE_ALL", typeof(MessageReactionRemoveAllEvent)}, { "MESSAGE_REACTION_REMOVE_ALL", typeof(MessageReactionRemoveAllEvent) },
{"MESSAGE_REACTION_REMOVE_EMOJI", typeof(MessageReactionRemoveEmojiEvent)}, { "MESSAGE_REACTION_REMOVE_EMOJI", typeof(MessageReactionRemoveEmojiEvent) },
{"INTERACTION_CREATE", typeof(InteractionCreateEvent)} { "INTERACTION_CREATE", typeof(InteractionCreateEvent) }
}; };
} }
} }

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Gateway namespace Myriad.Gateway
{ {
public record MessageDeleteBulkEvent(ulong[] Ids, ulong ChannelId, ulong? GuildId): IGatewayEvent; public record MessageDeleteBulkEvent(ulong[] Ids, ulong ChannelId, ulong? GuildId): IGatewayEvent;
} }

View File

@ -1,4 +1,4 @@
namespace Myriad.Gateway namespace Myriad.Gateway
{ {
public record MessageDeleteEvent(ulong Id, ulong ChannelId, ulong? GuildId): IGatewayEvent; public record MessageDeleteEvent(ulong Id, ulong ChannelId, ulong? GuildId): IGatewayEvent;
} }

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Gateway namespace Myriad.Gateway
{ {
public record MessageReactionRemoveAllEvent(ulong ChannelId, ulong MessageId, ulong? GuildId): IGatewayEvent; public record MessageReactionRemoveAllEvent(ulong ChannelId, ulong MessageId, ulong? GuildId): IGatewayEvent;
} }

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
using Myriad.Utils; using Myriad.Utils;
namespace Myriad.Gateway namespace Myriad.Gateway

View File

@ -1,4 +1,4 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Myriad.Types; using Myriad.Types;

View File

@ -1,4 +1,4 @@
namespace Myriad.Gateway namespace Myriad.Gateway
{ {
public record ResumedEvent: IGatewayEvent; public record ResumedEvent: IGatewayEvent;
} }

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,11 +1,11 @@
using System; using System;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {
// TODO: unused? // TODO: unused?
public class GatewayCloseException: Exception public class GatewayCloseException: Exception
{ {
public GatewayCloseException(int closeCode, string closeReason): base($"{closeCode}: {closeReason}") public GatewayCloseException(int closeCode, string closeReason) : base($"{closeCode}: {closeReason}")
{ {
CloseCode = closeCode; CloseCode = closeCode;
CloseReason = closeReason; CloseReason = closeReason;

View File

@ -1,4 +1,4 @@
using System; using System;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {
@ -7,10 +7,12 @@ namespace Myriad.Gateway
[JsonPropertyName("op")] public GatewayOpcode Opcode { get; init; } [JsonPropertyName("op")] public GatewayOpcode Opcode { get; init; }
[JsonPropertyName("d")] public object? Payload { get; init; } [JsonPropertyName("d")] public object? Payload { get; init; }
[JsonPropertyName("s")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("s")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public int? Sequence { get; init; } public int? Sequence { get; init; }
[JsonPropertyName("t")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("t")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? EventType { get; init; } public string? EventType { get; init; }
} }

View File

@ -1,4 +1,4 @@
namespace Myriad.Gateway namespace Myriad.Gateway
{ {
public record GatewaySettings public record GatewaySettings
{ {

View File

@ -1,4 +1,4 @@
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Myriad.Gateway.Limit namespace Myriad.Gateway.Limit
{ {

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -1,4 +1,4 @@
namespace Myriad.Gateway namespace Myriad.Gateway
{ {
public record GatewayHello(int HeartbeatInterval); public record GatewayHello(int HeartbeatInterval);
} }

View File

@ -1,4 +1,4 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace Myriad.Gateway namespace Myriad.Gateway
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Gateway namespace Myriad.Gateway
{ {
public record GatewayResume(string Token, string SessionId, int Seq); public record GatewayResume(string Token, string SessionId, int Seq);
} }

View File

@ -1,4 +1,4 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Myriad.Serialization; using Myriad.Serialization;
using Myriad.Types; using Myriad.Types;

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Net.WebSockets; using System.Net.WebSockets;
using System.Text.Json; using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -187,7 +187,7 @@ namespace Myriad.Gateway
private async Task SendHeartbeat(int? lastSeq) private async Task SendHeartbeat(int? lastSeq)
{ {
await _conn.Send(new GatewayPacket {Opcode = GatewayOpcode.Heartbeat, Payload = lastSeq}); await _conn.Send(new GatewayPacket { Opcode = GatewayOpcode.Heartbeat, Payload = lastSeq });
} }
private async Task Reconnect(WebSocketCloseStatus closeStatus, TimeSpan delay) private async Task Reconnect(WebSocketCloseStatus closeStatus, TimeSpan delay)

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Net.WebSockets; using System.Net.WebSockets;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
@ -40,7 +40,7 @@ namespace Myriad.Gateway
public async Task Send(GatewayPacket packet) public async Task Send(GatewayPacket packet)
{ {
// from `ManagedWebSocket.s_validSendStates` // from `ManagedWebSocket.s_validSendStates`
if (_client is not {State: WebSocketState.Open or WebSocketState.CloseReceived}) if (_client is not { State: WebSocketState.Open or WebSocketState.CloseReceived })
return; return;
try try
@ -62,7 +62,7 @@ namespace Myriad.Gateway
public async Task<GatewayPacket?> Read() public async Task<GatewayPacket?> Read()
{ {
// from `ManagedWebSocket.s_validReceiveStates` // from `ManagedWebSocket.s_validReceiveStates`
if (_client is not {State: WebSocketState.Open or WebSocketState.CloseSent}) if (_client is not { State: WebSocketState.Open or WebSocketState.CloseSent })
return null; return null;
try try

View File

@ -1,4 +1,4 @@
namespace Myriad.Gateway namespace Myriad.Gateway
{ {
public record ShardInfo(int ShardId, int NumShards); public record ShardInfo(int ShardId, int NumShards);
} }

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Buffers; using System.Buffers;
using System.IO; using System.IO;
using System.Net.WebSockets; using System.Net.WebSockets;
@ -51,7 +51,7 @@ namespace Myriad.Gateway
stream.Write(buf.Memory.Span.Slice(0, res.Count)); stream.Write(buf.Memory.Span.Slice(0, res.Count));
} }
return DeserializeObject(res, stream.GetBuffer().AsSpan(0, (int) stream.Length)); return DeserializeObject(res, stream.GetBuffer().AsSpan(0, (int)stream.Length));
} }
private (WebSocketMessageType type, GatewayPacket packet) DeserializeSingleBuffer( private (WebSocketMessageType type, GatewayPacket packet) DeserializeSingleBuffer(

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -1,4 +1,4 @@
namespace Myriad.Gateway.State namespace Myriad.Gateway.State
{ {
public enum ShardState public enum ShardState
{ {

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Net.WebSockets; using System.Net.WebSockets;
using System.Text.Json; using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -77,22 +77,22 @@ namespace Myriad.Gateway
break; break;
case GatewayOpcode.Reconnect: case GatewayOpcode.Reconnect:
{ {
await HandleReconnect(); await HandleReconnect();
break; break;
} }
case GatewayOpcode.InvalidSession: case GatewayOpcode.InvalidSession:
{ {
var canResume = DeserializePayload<bool>(packet); var canResume = DeserializePayload<bool>(packet);
await HandleInvalidSession(canResume); await HandleInvalidSession(canResume);
break; break;
} }
case GatewayOpcode.Dispatch: case GatewayOpcode.Dispatch:
_lastSeq = packet.Sequence; _lastSeq = packet.Sequence;
var evt = DeserializeEvent(packet.EventType!, (JsonElement) packet.Payload!); var evt = DeserializeEvent(packet.EventType!, (JsonElement)packet.Payload!);
if (evt != null) if (evt != null)
{ {
if (evt is ReadyEvent ready) if (evt is ReadyEvent ready)
@ -218,7 +218,7 @@ namespace Myriad.Gateway
private T DeserializePayload<T>(GatewayPacket packet) private T DeserializePayload<T>(GatewayPacket packet)
{ {
var packetPayload = (JsonElement) packet.Payload!; var packetPayload = (JsonElement)packet.Payload!;
return JsonSerializer.Deserialize<T>(packetPayload.GetRawText(), _jsonSerializerOptions)!; return JsonSerializer.Deserialize<T>(packetPayload.GetRawText(), _jsonSerializerOptions)!;
} }

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Net; using System.Net;
@ -52,7 +52,7 @@ namespace Myriad.Rest
var waitPolicy = Policy var waitPolicy = Policy
.Handle<RatelimitBucketExhaustedException>() .Handle<RatelimitBucketExhaustedException>()
.WaitAndRetryAsync(3, .WaitAndRetryAsync(3,
(_, e, _) => ((RatelimitBucketExhaustedException) e).RetryAfter, (_, e, _) => ((RatelimitBucketExhaustedException)e).RetryAfter,
(_, _, _, _) => Task.CompletedTask) (_, _, _, _) => Task.CompletedTask)
.AsAsyncPolicy<HttpResponseMessage>(); .AsAsyncPolicy<HttpResponseMessage>();
@ -68,7 +68,7 @@ namespace Myriad.Rest
return default; return default;
} }
public async Task<T?> Get<T>(string path, (string endpointName, ulong major) ratelimitParams) where T: class public async Task<T?> Get<T>(string path, (string endpointName, ulong major) ratelimitParams) where T : class
{ {
using var response = await Send(() => new HttpRequestMessage(HttpMethod.Get, ApiBaseUrl + path), using var response = await Send(() => new HttpRequestMessage(HttpMethod.Get, ApiBaseUrl + path),
ratelimitParams, true); ratelimitParams, true);
@ -81,7 +81,7 @@ namespace Myriad.Rest
} }
public async Task<T?> Post<T>(string path, (string endpointName, ulong major) ratelimitParams, object? body) public async Task<T?> Post<T>(string path, (string endpointName, ulong major) ratelimitParams, object? body)
where T: class where T : class
{ {
using var response = await Send(() => using var response = await Send(() =>
{ {
@ -93,7 +93,7 @@ namespace Myriad.Rest
} }
public async Task<T?> PostMultipart<T>(string path, (string endpointName, ulong major) ratelimitParams, object? payload, MultipartFile[]? files) public async Task<T?> PostMultipart<T>(string path, (string endpointName, ulong major) ratelimitParams, object? payload, MultipartFile[]? files)
where T: class where T : class
{ {
using var response = await Send(() => using var response = await Send(() =>
{ {
@ -105,7 +105,7 @@ namespace Myriad.Rest
} }
public async Task<T?> Patch<T>(string path, (string endpointName, ulong major) ratelimitParams, object? body) public async Task<T?> Patch<T>(string path, (string endpointName, ulong major) ratelimitParams, object? body)
where T: class where T : class
{ {
using var response = await Send(() => using var response = await Send(() =>
{ {
@ -117,7 +117,7 @@ namespace Myriad.Rest
} }
public async Task<T?> Put<T>(string path, (string endpointName, ulong major) ratelimitParams, object? body) public async Task<T?> Put<T>(string path, (string endpointName, ulong major) ratelimitParams, object? body)
where T: class where T : class
{ {
using var response = await Send(() => using var response = await Send(() =>
{ {
@ -160,7 +160,7 @@ namespace Myriad.Rest
request.Content = mfd; request.Content = mfd;
} }
private async Task<T?> ReadResponse<T>(HttpResponseMessage response) where T: class private async Task<T?> ReadResponse<T>(HttpResponseMessage response) where T : class
{ {
if (response.StatusCode == HttpStatusCode.NoContent) if (response.StatusCode == HttpStatusCode.NoContent)
return null; return null;
@ -189,7 +189,7 @@ namespace Myriad.Rest
_logger.Debug( _logger.Debug(
"Response: {RequestMethod} {RequestPath} -> {StatusCode} {ReasonPhrase} (in {ResponseDurationMs} ms)", "Response: {RequestMethod} {RequestPath} -> {StatusCode} {ReasonPhrase} (in {ResponseDurationMs} ms)",
request.Method, request.RequestUri, (int) response.StatusCode, response.ReasonPhrase, stopwatch.ElapsedMilliseconds); request.Method, request.RequestUri, (int)response.StatusCode, response.ReasonPhrase, stopwatch.ElapsedMilliseconds);
await HandleApiError(response, ignoreNotFound); await HandleApiError(response, ignoreNotFound);

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Net; using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -1,4 +1,4 @@
using System.Text.Json; using System.Text.Json;
namespace Myriad.Rest namespace Myriad.Rest
{ {

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
@ -29,43 +29,49 @@ namespace Myriad.Rest.Exceptions
public class NotFoundException: DiscordRequestException public class NotFoundException: DiscordRequestException
{ {
public NotFoundException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base( public NotFoundException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
response, responseBody, apiError) { } response, responseBody, apiError)
{ }
} }
public class UnauthorizedException: DiscordRequestException public class UnauthorizedException: DiscordRequestException
{ {
public UnauthorizedException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base( public UnauthorizedException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
response, responseBody, apiError) { } response, responseBody, apiError)
{ }
} }
public class ForbiddenException: DiscordRequestException public class ForbiddenException: DiscordRequestException
{ {
public ForbiddenException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base( public ForbiddenException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
response, responseBody, apiError) { } response, responseBody, apiError)
{ }
} }
public class ConflictException: DiscordRequestException public class ConflictException: DiscordRequestException
{ {
public ConflictException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base( public ConflictException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
response, responseBody, apiError) { } response, responseBody, apiError)
{ }
} }
public class BadRequestException: DiscordRequestException public class BadRequestException: DiscordRequestException
{ {
public BadRequestException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base( public BadRequestException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
response, responseBody, apiError) { } response, responseBody, apiError)
{ }
} }
public class TooManyRequestsException: DiscordRequestException public class TooManyRequestsException: DiscordRequestException
{ {
public TooManyRequestsException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): public TooManyRequestsException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) :
base(response, responseBody, apiError) { } base(response, responseBody, apiError)
{ }
} }
public class UnknownDiscordRequestException: DiscordRequestException public class UnknownDiscordRequestException: DiscordRequestException
{ {
public UnknownDiscordRequestException(HttpResponseMessage response, string responseBody, public UnknownDiscordRequestException(HttpResponseMessage response, string responseBody,
DiscordApiError? apiError): base(response, responseBody, apiError) { } DiscordApiError? apiError) : base(response, responseBody, apiError) { }
} }
} }

View File

@ -1,4 +1,4 @@
using System; using System;
using Myriad.Rest.Ratelimit; using Myriad.Rest.Ratelimit;
@ -6,12 +6,12 @@ namespace Myriad.Rest.Exceptions
{ {
public class RatelimitException: Exception public class RatelimitException: Exception
{ {
public RatelimitException(string? message): base(message) { } public RatelimitException(string? message) : base(message) { }
} }
public class RatelimitBucketExhaustedException: RatelimitException public class RatelimitBucketExhaustedException: RatelimitException
{ {
public RatelimitBucketExhaustedException(Bucket bucket, TimeSpan retryAfter): base( public RatelimitBucketExhaustedException(Bucket bucket, TimeSpan retryAfter) : base(
"Rate limit bucket exhausted, request blocked") "Rate limit bucket exhausted, request blocked")
{ {
Bucket = bucket; Bucket = bucket;
@ -24,6 +24,6 @@ namespace Myriad.Rest.Exceptions
public class GloballyRatelimitedException: RatelimitException public class GloballyRatelimitedException: RatelimitException
{ {
public GloballyRatelimitedException(): base("Global rate limit hit") { } public GloballyRatelimitedException() : base("Global rate limit hit") { }
} }
} }

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Threading; using System.Threading;
using Serilog; using Serilog;

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Net.Http; using System.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
@ -41,7 +41,7 @@ namespace Myriad.Rest.Ratelimit
var resetTimestamp = TryGetDouble(response, ResetHeader); var resetTimestamp = TryGetDouble(response, ResetHeader);
if (resetTimestamp != null) if (resetTimestamp != null)
headers.Reset = DateTimeOffset.FromUnixTimeMilliseconds((long) (resetTimestamp.Value * 1000)); headers.Reset = DateTimeOffset.FromUnixTimeMilliseconds((long)(resetTimestamp.Value * 1000));
var resetAfterSeconds = TryGetDouble(response, ResetAfterHeader); var resetAfterSeconds = TryGetDouble(response, ResetAfterHeader);
if (resetAfterSeconds != null) if (resetAfterSeconds != null)

View File

@ -1,4 +1,4 @@
using System; using System;
using Myriad.Rest.Exceptions; using Myriad.Rest.Exceptions;

View File

@ -1,4 +1,4 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Myriad.Serialization; using Myriad.Serialization;

View File

@ -1,4 +1,4 @@
using System.IO; using System.IO;
namespace Myriad.Rest.Types namespace Myriad.Rest.Types
{ {

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using Myriad.Types; using Myriad.Types;

View File

@ -1,4 +1,4 @@
namespace Myriad.Rest.Types.Requests namespace Myriad.Rest.Types.Requests
{ {
public record CreateDmRequest(ulong RecipientId); public record CreateDmRequest(ulong RecipientId);
} }

View File

@ -1,4 +1,4 @@
namespace Myriad.Rest.Types.Requests namespace Myriad.Rest.Types.Requests
{ {
public record CreateWebhookRequest(string Name); public record CreateWebhookRequest(string Name);
} }

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Rest.Types.Requests namespace Myriad.Rest.Types.Requests
{ {

View File

@ -1,4 +1,4 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Myriad.Types; using Myriad.Types;
using Myriad.Utils; using Myriad.Utils;

View File

@ -1,4 +1,4 @@
using Myriad.Types; using Myriad.Types;
namespace Myriad.Rest.Types.Requests namespace Myriad.Rest.Types.Requests
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Rest.Types namespace Myriad.Rest.Types
{ {
public record ModifyGuildMemberRequest public record ModifyGuildMemberRequest
{ {

View File

@ -1,4 +1,4 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Myriad.Utils; using Myriad.Utils;

View File

@ -1,4 +1,4 @@
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
namespace Myriad.Serialization namespace Myriad.Serialization

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Reflection; using System.Reflection;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
@ -26,7 +26,7 @@ namespace Myriad.Serialization
public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options) public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options)
{ {
var innerType = typeToConvert.GetGenericArguments()[0]; var innerType = typeToConvert.GetGenericArguments()[0];
return (JsonConverter?) Activator.CreateInstance( return (JsonConverter?)Activator.CreateInstance(
typeof(Inner<>).MakeGenericType(innerType), typeof(Inner<>).MakeGenericType(innerType),
BindingFlags.Instance | BindingFlags.Public, BindingFlags.Instance | BindingFlags.Public,
null, null,

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
@ -13,12 +13,12 @@ namespace Myriad.Serialization
var str = reader.GetString(); var str = reader.GetString();
if (str == null) return default; if (str == null) return default;
return (PermissionSet) ulong.Parse(str); return (PermissionSet)ulong.Parse(str);
} }
public override void Write(Utf8JsonWriter writer, PermissionSet value, JsonSerializerOptions options) public override void Write(Utf8JsonWriter writer, PermissionSet value, JsonSerializerOptions options)
{ {
writer.WriteStringValue(((ulong) value).ToString()); writer.WriteStringValue(((ulong)value).ToString());
} }
} }
} }

View File

@ -1,4 +1,4 @@
using System; using System;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record Activity: ActivityPartial public record Activity: ActivityPartial
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record Application: ApplicationPartial public record Application: ApplicationPartial
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record ApplicationCommand public record ApplicationCommand
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record ApplicationCommandInteractionData public record ApplicationCommandInteractionData
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record ApplicationCommandInteractionDataOption public record ApplicationCommandInteractionDataOption
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record ApplicationCommandOption(ApplicationCommandOption.OptionType Type, string Name, string Description) public record ApplicationCommandOption(ApplicationCommandOption.OptionType Type, string Name, string Description)
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record Interaction public record Interaction
{ {

View File

@ -1,4 +1,4 @@
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Myriad.Rest.Types; using Myriad.Rest.Types;
using Myriad.Utils; using Myriad.Utils;

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record InteractionResponse public record InteractionResponse
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record Channel public record Channel
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record Embed public record Embed
{ {
@ -16,44 +16,44 @@
public EmbedAuthor? Author { get; init; } public EmbedAuthor? Author { get; init; }
public Field[]? Fields { get; init; } public Field[]? Fields { get; init; }
public record EmbedFooter ( public record EmbedFooter(
string Text, string Text,
string? IconUrl = null, string? IconUrl = null,
string? ProxyIconUrl = null string? ProxyIconUrl = null
); );
public record EmbedImage ( public record EmbedImage(
string? Url, string? Url,
uint? Width = null, uint? Width = null,
uint? Height = null uint? Height = null
); );
public record EmbedThumbnail ( public record EmbedThumbnail(
string? Url, string? Url,
string? ProxyUrl = null, string? ProxyUrl = null,
uint? Width = null, uint? Width = null,
uint? Height = null uint? Height = null
); );
public record EmbedVideo ( public record EmbedVideo(
string? Url, string? Url,
uint? Width = null, uint? Width = null,
uint? Height = null uint? Height = null
); );
public record EmbedProvider ( public record EmbedProvider(
string? Name, string? Name,
string? Url string? Url
); );
public record EmbedAuthor ( public record EmbedAuthor(
string? Name = null, string? Name = null,
string? Url = null, string? Url = null,
string? IconUrl = null, string? IconUrl = null,
string? ProxyIconUrl = null string? ProxyIconUrl = null
); );
public record Field ( public record Field(
string Name, string Name,
string Value, string Value,
bool Inline = false bool Inline = false

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record Emoji public record Emoji
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record GatewayInfo public record GatewayInfo
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record SessionStartLimit public record SessionStartLimit
{ {

View File

@ -1,4 +1,4 @@
namespace Myriad.Types namespace Myriad.Types
{ {
public record Guild public record Guild
{ {

Some files were not shown because too many files have changed in this diff Show More