run dotnet format
This commit is contained in:
parent
05989242f9
commit
ac2671452d
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Myriad.Types;
|
||||
|
||||
@ -11,66 +11,71 @@ namespace Myriad.Builders
|
||||
|
||||
public EmbedBuilder Title(string? title)
|
||||
{
|
||||
_embed = _embed with {Title = title};
|
||||
_embed = _embed with { Title = title };
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedBuilder Description(string? description)
|
||||
{
|
||||
_embed = _embed with { Description = description};
|
||||
_embed = _embed with { Description = description };
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedBuilder Url(string? url)
|
||||
{
|
||||
_embed = _embed with {Url = url};
|
||||
_embed = _embed with { Url = url };
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedBuilder Color(uint? color)
|
||||
{
|
||||
_embed = _embed with {Color = color};
|
||||
_embed = _embed with { Color = color };
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedBuilder Footer(Embed.EmbedFooter? footer)
|
||||
{
|
||||
_embed = _embed with {
|
||||
_embed = _embed with
|
||||
{
|
||||
Footer = footer
|
||||
};
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedBuilder Image(Embed.EmbedImage? image)
|
||||
{
|
||||
_embed = _embed with {
|
||||
_embed = _embed with
|
||||
{
|
||||
Image = image
|
||||
};
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public EmbedBuilder Thumbnail(Embed.EmbedThumbnail? thumbnail)
|
||||
{
|
||||
_embed = _embed with {
|
||||
_embed = _embed with
|
||||
{
|
||||
Thumbnail = thumbnail
|
||||
};
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedBuilder Author(Embed.EmbedAuthor? author)
|
||||
{
|
||||
_embed = _embed with {
|
||||
_embed = _embed with
|
||||
{
|
||||
Author = author
|
||||
};
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedBuilder Timestamp(string? timestamp)
|
||||
{
|
||||
_embed = _embed with {
|
||||
_embed = _embed with
|
||||
{
|
||||
Timestamp = timestamp
|
||||
};
|
||||
};
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Myriad.Gateway;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Myriad.Types;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -70,9 +70,11 @@ namespace Myriad.Cache
|
||||
|
||||
if (!found)
|
||||
{
|
||||
_guilds[guildId] = guild with {
|
||||
Guild = guild.Guild with {
|
||||
Roles = guild.Guild.Roles.Concat(new[] { role}).ToArray()
|
||||
_guilds[guildId] = guild with
|
||||
{
|
||||
Guild = guild.Guild with
|
||||
{
|
||||
Roles = guild.Guild.Roles.Concat(new[] { role }).ToArray()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Myriad.Cache;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Extensions
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Extensions
|
||||
namespace Myriad.Extensions
|
||||
{
|
||||
public static class GuildExtensions
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Gateway;
|
||||
using Myriad.Gateway;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Extensions
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
using Myriad.Types;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Extensions
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Gateway
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
public record GuildDeleteEvent(ulong Id, bool Unavailable): IGatewayEvent;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Gateway
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
public record GuildRoleDeleteEvent(ulong GuildId, ulong RoleId): IGatewayEvent;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
@ -7,33 +7,33 @@ namespace Myriad.Gateway
|
||||
{
|
||||
public static readonly Dictionary<string, Type> EventTypes = new()
|
||||
{
|
||||
{"READY", typeof(ReadyEvent)},
|
||||
{"RESUMED", typeof(ResumedEvent)},
|
||||
{"GUILD_CREATE", typeof(GuildCreateEvent)},
|
||||
{"GUILD_UPDATE", typeof(GuildUpdateEvent)},
|
||||
{"GUILD_DELETE", typeof(GuildDeleteEvent)},
|
||||
{"GUILD_MEMBER_ADD", typeof(GuildMemberAddEvent)},
|
||||
{"GUILD_MEMBER_REMOVE", typeof(GuildMemberRemoveEvent)},
|
||||
{"GUILD_MEMBER_UPDATE", typeof(GuildMemberUpdateEvent)},
|
||||
{"GUILD_ROLE_CREATE", typeof(GuildRoleCreateEvent)},
|
||||
{"GUILD_ROLE_UPDATE", typeof(GuildRoleUpdateEvent)},
|
||||
{"GUILD_ROLE_DELETE", typeof(GuildRoleDeleteEvent)},
|
||||
{"CHANNEL_CREATE", typeof(ChannelCreateEvent)},
|
||||
{"CHANNEL_UPDATE", typeof(ChannelUpdateEvent)},
|
||||
{"CHANNEL_DELETE", typeof(ChannelDeleteEvent)},
|
||||
{"THREAD_CREATE", typeof(ThreadCreateEvent)},
|
||||
{"THREAD_UPDATE", typeof(ThreadUpdateEvent)},
|
||||
{"THREAD_DELETE", typeof(ThreadDeleteEvent)},
|
||||
{"THREAD_LIST_SYNC", typeof(ThreadListSyncEvent)},
|
||||
{"MESSAGE_CREATE", typeof(MessageCreateEvent)},
|
||||
{"MESSAGE_UPDATE", typeof(MessageUpdateEvent)},
|
||||
{"MESSAGE_DELETE", typeof(MessageDeleteEvent)},
|
||||
{"MESSAGE_DELETE_BULK", typeof(MessageDeleteBulkEvent)},
|
||||
{"MESSAGE_REACTION_ADD", typeof(MessageReactionAddEvent)},
|
||||
{"MESSAGE_REACTION_REMOVE", typeof(MessageReactionRemoveEvent)},
|
||||
{"MESSAGE_REACTION_REMOVE_ALL", typeof(MessageReactionRemoveAllEvent)},
|
||||
{"MESSAGE_REACTION_REMOVE_EMOJI", typeof(MessageReactionRemoveEmojiEvent)},
|
||||
{"INTERACTION_CREATE", typeof(InteractionCreateEvent)}
|
||||
{ "READY", typeof(ReadyEvent) },
|
||||
{ "RESUMED", typeof(ResumedEvent) },
|
||||
{ "GUILD_CREATE", typeof(GuildCreateEvent) },
|
||||
{ "GUILD_UPDATE", typeof(GuildUpdateEvent) },
|
||||
{ "GUILD_DELETE", typeof(GuildDeleteEvent) },
|
||||
{ "GUILD_MEMBER_ADD", typeof(GuildMemberAddEvent) },
|
||||
{ "GUILD_MEMBER_REMOVE", typeof(GuildMemberRemoveEvent) },
|
||||
{ "GUILD_MEMBER_UPDATE", typeof(GuildMemberUpdateEvent) },
|
||||
{ "GUILD_ROLE_CREATE", typeof(GuildRoleCreateEvent) },
|
||||
{ "GUILD_ROLE_UPDATE", typeof(GuildRoleUpdateEvent) },
|
||||
{ "GUILD_ROLE_DELETE", typeof(GuildRoleDeleteEvent) },
|
||||
{ "CHANNEL_CREATE", typeof(ChannelCreateEvent) },
|
||||
{ "CHANNEL_UPDATE", typeof(ChannelUpdateEvent) },
|
||||
{ "CHANNEL_DELETE", typeof(ChannelDeleteEvent) },
|
||||
{ "THREAD_CREATE", typeof(ThreadCreateEvent) },
|
||||
{ "THREAD_UPDATE", typeof(ThreadUpdateEvent) },
|
||||
{ "THREAD_DELETE", typeof(ThreadDeleteEvent) },
|
||||
{ "THREAD_LIST_SYNC", typeof(ThreadListSyncEvent) },
|
||||
{ "MESSAGE_CREATE", typeof(MessageCreateEvent) },
|
||||
{ "MESSAGE_UPDATE", typeof(MessageUpdateEvent) },
|
||||
{ "MESSAGE_DELETE", typeof(MessageDeleteEvent) },
|
||||
{ "MESSAGE_DELETE_BULK", typeof(MessageDeleteBulkEvent) },
|
||||
{ "MESSAGE_REACTION_ADD", typeof(MessageReactionAddEvent) },
|
||||
{ "MESSAGE_REACTION_REMOVE", typeof(MessageReactionRemoveEvent) },
|
||||
{ "MESSAGE_REACTION_REMOVE_ALL", typeof(MessageReactionRemoveAllEvent) },
|
||||
{ "MESSAGE_REACTION_REMOVE_EMOJI", typeof(MessageReactionRemoveEmojiEvent) },
|
||||
{ "INTERACTION_CREATE", typeof(InteractionCreateEvent) }
|
||||
};
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Gateway
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
public record MessageDeleteBulkEvent(ulong[] Ids, ulong ChannelId, ulong? GuildId): IGatewayEvent;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Gateway
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
public record MessageDeleteEvent(ulong Id, ulong ChannelId, ulong? GuildId): IGatewayEvent;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Gateway
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
public record MessageReactionRemoveAllEvent(ulong ChannelId, ulong MessageId, ulong? GuildId): IGatewayEvent;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
using Myriad.Utils;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using Myriad.Types;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Gateway
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
public record ResumedEvent: IGatewayEvent;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
// TODO: unused?
|
||||
public class GatewayCloseException: Exception
|
||||
{
|
||||
public GatewayCloseException(int closeCode, string closeReason): base($"{closeCode}: {closeReason}")
|
||||
public GatewayCloseException(int closeCode, string closeReason) : base($"{closeCode}: {closeReason}")
|
||||
{
|
||||
CloseCode = closeCode;
|
||||
CloseReason = closeReason;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
@ -7,10 +7,12 @@ namespace Myriad.Gateway
|
||||
[JsonPropertyName("op")] public GatewayOpcode Opcode { 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; }
|
||||
|
||||
[JsonPropertyName("t")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
[JsonPropertyName("t")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? EventType { get; init; }
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Gateway
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
public record GatewaySettings
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Myriad.Gateway.Limit
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Gateway
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
public record GatewayHello(int HeartbeatInterval);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Gateway
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
public record GatewayResume(string Token, string SessionId, int Seq);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using Myriad.Serialization;
|
||||
using Myriad.Types;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
@ -187,7 +187,7 @@ namespace Myriad.Gateway
|
||||
|
||||
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)
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
@ -40,7 +40,7 @@ namespace Myriad.Gateway
|
||||
public async Task Send(GatewayPacket packet)
|
||||
{
|
||||
// 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;
|
||||
|
||||
try
|
||||
@ -62,7 +62,7 @@ namespace Myriad.Gateway
|
||||
public async Task<GatewayPacket?> Read()
|
||||
{
|
||||
// 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;
|
||||
|
||||
try
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Gateway
|
||||
namespace Myriad.Gateway
|
||||
{
|
||||
public record ShardInfo(int ShardId, int NumShards);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
using System.Net.WebSockets;
|
||||
@ -51,7 +51,7 @@ namespace Myriad.Gateway
|
||||
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(
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Gateway.State
|
||||
namespace Myriad.Gateway.State
|
||||
{
|
||||
public enum ShardState
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Net.WebSockets;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
@ -77,22 +77,22 @@ namespace Myriad.Gateway
|
||||
break;
|
||||
|
||||
case GatewayOpcode.Reconnect:
|
||||
{
|
||||
await HandleReconnect();
|
||||
break;
|
||||
}
|
||||
{
|
||||
await HandleReconnect();
|
||||
break;
|
||||
}
|
||||
|
||||
case GatewayOpcode.InvalidSession:
|
||||
{
|
||||
var canResume = DeserializePayload<bool>(packet);
|
||||
await HandleInvalidSession(canResume);
|
||||
break;
|
||||
}
|
||||
{
|
||||
var canResume = DeserializePayload<bool>(packet);
|
||||
await HandleInvalidSession(canResume);
|
||||
break;
|
||||
}
|
||||
|
||||
case GatewayOpcode.Dispatch:
|
||||
_lastSeq = packet.Sequence;
|
||||
|
||||
var evt = DeserializeEvent(packet.EventType!, (JsonElement) packet.Payload!);
|
||||
var evt = DeserializeEvent(packet.EventType!, (JsonElement)packet.Payload!);
|
||||
if (evt != null)
|
||||
{
|
||||
if (evt is ReadyEvent ready)
|
||||
@ -218,7 +218,7 @@ namespace Myriad.Gateway
|
||||
|
||||
private T DeserializePayload<T>(GatewayPacket packet)
|
||||
{
|
||||
var packetPayload = (JsonElement) packet.Payload!;
|
||||
var packetPayload = (JsonElement)packet.Payload!;
|
||||
return JsonSerializer.Deserialize<T>(packetPayload.GetRawText(), _jsonSerializerOptions)!;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
@ -52,7 +52,7 @@ namespace Myriad.Rest
|
||||
var waitPolicy = Policy
|
||||
.Handle<RatelimitBucketExhaustedException>()
|
||||
.WaitAndRetryAsync(3,
|
||||
(_, e, _) => ((RatelimitBucketExhaustedException) e).RetryAfter,
|
||||
(_, e, _) => ((RatelimitBucketExhaustedException)e).RetryAfter,
|
||||
(_, _, _, _) => Task.CompletedTask)
|
||||
.AsAsyncPolicy<HttpResponseMessage>();
|
||||
|
||||
@ -68,7 +68,7 @@ namespace Myriad.Rest
|
||||
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),
|
||||
ratelimitParams, true);
|
||||
@ -81,7 +81,7 @@ namespace Myriad.Rest
|
||||
}
|
||||
|
||||
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(() =>
|
||||
{
|
||||
@ -93,7 +93,7 @@ namespace Myriad.Rest
|
||||
}
|
||||
|
||||
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(() =>
|
||||
{
|
||||
@ -105,7 +105,7 @@ namespace Myriad.Rest
|
||||
}
|
||||
|
||||
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(() =>
|
||||
{
|
||||
@ -117,7 +117,7 @@ namespace Myriad.Rest
|
||||
}
|
||||
|
||||
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(() =>
|
||||
{
|
||||
@ -160,7 +160,7 @@ namespace Myriad.Rest
|
||||
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)
|
||||
return null;
|
||||
@ -189,7 +189,7 @@ namespace Myriad.Rest
|
||||
|
||||
_logger.Debug(
|
||||
"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);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Myriad.Rest
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
|
||||
@ -29,43 +29,49 @@ namespace Myriad.Rest.Exceptions
|
||||
|
||||
public class NotFoundException: DiscordRequestException
|
||||
{
|
||||
public NotFoundException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||
response, responseBody, apiError) { }
|
||||
public NotFoundException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
|
||||
response, responseBody, apiError)
|
||||
{ }
|
||||
}
|
||||
|
||||
public class UnauthorizedException: DiscordRequestException
|
||||
{
|
||||
public UnauthorizedException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||
response, responseBody, apiError) { }
|
||||
public UnauthorizedException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
|
||||
response, responseBody, apiError)
|
||||
{ }
|
||||
}
|
||||
|
||||
public class ForbiddenException: DiscordRequestException
|
||||
{
|
||||
public ForbiddenException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||
response, responseBody, apiError) { }
|
||||
public ForbiddenException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
|
||||
response, responseBody, apiError)
|
||||
{ }
|
||||
}
|
||||
|
||||
public class ConflictException: DiscordRequestException
|
||||
{
|
||||
public ConflictException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||
response, responseBody, apiError) { }
|
||||
public ConflictException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
|
||||
response, responseBody, apiError)
|
||||
{ }
|
||||
}
|
||||
|
||||
public class BadRequestException: DiscordRequestException
|
||||
{
|
||||
public BadRequestException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError): base(
|
||||
response, responseBody, apiError) { }
|
||||
public BadRequestException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) : base(
|
||||
response, responseBody, apiError)
|
||||
{ }
|
||||
}
|
||||
|
||||
public class TooManyRequestsException: DiscordRequestException
|
||||
{
|
||||
public TooManyRequestsException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError):
|
||||
base(response, responseBody, apiError) { }
|
||||
public TooManyRequestsException(HttpResponseMessage response, string responseBody, DiscordApiError? apiError) :
|
||||
base(response, responseBody, apiError)
|
||||
{ }
|
||||
}
|
||||
|
||||
public class UnknownDiscordRequestException: DiscordRequestException
|
||||
{
|
||||
public UnknownDiscordRequestException(HttpResponseMessage response, string responseBody,
|
||||
DiscordApiError? apiError): base(response, responseBody, apiError) { }
|
||||
DiscordApiError? apiError) : base(response, responseBody, apiError) { }
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
using Myriad.Rest.Ratelimit;
|
||||
|
||||
@ -6,12 +6,12 @@ namespace Myriad.Rest.Exceptions
|
||||
{
|
||||
public class RatelimitException: Exception
|
||||
{
|
||||
public RatelimitException(string? message): base(message) { }
|
||||
public RatelimitException(string? message) : base(message) { }
|
||||
}
|
||||
|
||||
public class RatelimitBucketExhaustedException: RatelimitException
|
||||
{
|
||||
public RatelimitBucketExhaustedException(Bucket bucket, TimeSpan retryAfter): base(
|
||||
public RatelimitBucketExhaustedException(Bucket bucket, TimeSpan retryAfter) : base(
|
||||
"Rate limit bucket exhausted, request blocked")
|
||||
{
|
||||
Bucket = bucket;
|
||||
@ -24,6 +24,6 @@ namespace Myriad.Rest.Exceptions
|
||||
|
||||
public class GloballyRatelimitedException: RatelimitException
|
||||
{
|
||||
public GloballyRatelimitedException(): base("Global rate limit hit") { }
|
||||
public GloballyRatelimitedException() : base("Global rate limit hit") { }
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
using Serilog;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
@ -41,7 +41,7 @@ namespace Myriad.Rest.Ratelimit
|
||||
|
||||
var resetTimestamp = TryGetDouble(response, ResetHeader);
|
||||
if (resetTimestamp != null)
|
||||
headers.Reset = DateTimeOffset.FromUnixTimeMilliseconds((long) (resetTimestamp.Value * 1000));
|
||||
headers.Reset = DateTimeOffset.FromUnixTimeMilliseconds((long)(resetTimestamp.Value * 1000));
|
||||
|
||||
var resetAfterSeconds = TryGetDouble(response, ResetAfterHeader);
|
||||
if (resetAfterSeconds != null)
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
|
||||
using Myriad.Rest.Exceptions;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using Myriad.Serialization;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
|
||||
namespace Myriad.Rest.Types
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Myriad.Types;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Rest.Types.Requests
|
||||
namespace Myriad.Rest.Types.Requests
|
||||
{
|
||||
public record CreateDmRequest(ulong RecipientId);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Rest.Types.Requests
|
||||
namespace Myriad.Rest.Types.Requests
|
||||
{
|
||||
public record CreateWebhookRequest(string Name);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Rest.Types.Requests
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using Myriad.Types;
|
||||
using Myriad.Utils;
|
||||
|
@ -1,4 +1,4 @@
|
||||
using Myriad.Types;
|
||||
using Myriad.Types;
|
||||
|
||||
namespace Myriad.Rest.Types.Requests
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Rest.Types
|
||||
namespace Myriad.Rest.Types
|
||||
{
|
||||
public record ModifyGuildMemberRequest
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using Myriad.Utils;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Myriad.Serialization
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
@ -26,7 +26,7 @@ namespace Myriad.Serialization
|
||||
public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var innerType = typeToConvert.GetGenericArguments()[0];
|
||||
return (JsonConverter?) Activator.CreateInstance(
|
||||
return (JsonConverter?)Activator.CreateInstance(
|
||||
typeof(Inner<>).MakeGenericType(innerType),
|
||||
BindingFlags.Instance | BindingFlags.Public,
|
||||
null,
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
@ -13,12 +13,12 @@ namespace Myriad.Serialization
|
||||
var str = reader.GetString();
|
||||
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)
|
||||
{
|
||||
writer.WriteStringValue(((ulong) value).ToString());
|
||||
writer.WriteStringValue(((ulong)value).ToString());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record Activity: ActivityPartial
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record Application: ApplicationPartial
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record ApplicationCommand
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record ApplicationCommandInteractionData
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record ApplicationCommandInteractionDataOption
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record ApplicationCommandOption(ApplicationCommandOption.OptionType Type, string Name, string Description)
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record Interaction
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
using Myriad.Rest.Types;
|
||||
using Myriad.Utils;
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record InteractionResponse
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record Channel
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record Embed
|
||||
{
|
||||
@ -16,44 +16,44 @@
|
||||
public EmbedAuthor? Author { get; init; }
|
||||
public Field[]? Fields { get; init; }
|
||||
|
||||
public record EmbedFooter (
|
||||
public record EmbedFooter(
|
||||
string Text,
|
||||
string? IconUrl = null,
|
||||
string? ProxyIconUrl = null
|
||||
);
|
||||
|
||||
public record EmbedImage (
|
||||
public record EmbedImage(
|
||||
string? Url,
|
||||
uint? Width = null,
|
||||
uint? Height = null
|
||||
);
|
||||
|
||||
public record EmbedThumbnail (
|
||||
public record EmbedThumbnail(
|
||||
string? Url,
|
||||
string? ProxyUrl = null,
|
||||
uint? Width = null,
|
||||
uint? Height = null
|
||||
);
|
||||
|
||||
public record EmbedVideo (
|
||||
public record EmbedVideo(
|
||||
string? Url,
|
||||
uint? Width = null,
|
||||
uint? Height = null
|
||||
);
|
||||
|
||||
public record EmbedProvider (
|
||||
public record EmbedProvider(
|
||||
string? Name,
|
||||
string? Url
|
||||
);
|
||||
|
||||
public record EmbedAuthor (
|
||||
public record EmbedAuthor(
|
||||
string? Name = null,
|
||||
string? Url = null,
|
||||
string? IconUrl = null,
|
||||
string? ProxyIconUrl = null
|
||||
);
|
||||
|
||||
public record Field (
|
||||
public record Field(
|
||||
string Name,
|
||||
string Value,
|
||||
bool Inline = false
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record Emoji
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record GatewayInfo
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record SessionStartLimit
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace Myriad.Types
|
||||
namespace Myriad.Types
|
||||
{
|
||||
public record Guild
|
||||
{
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user