chore: begin porting code from playground
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
namespace StevesBot.Worker.Discord;
|
||||
|
||||
internal class DiscordClientException : Exception
|
||||
{
|
||||
public DiscordClientException()
|
||||
{
|
||||
}
|
||||
|
||||
public DiscordClientException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public DiscordClientException(string message, Exception innerException) : base(message, innerException)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace StevesBot.Worker.Discord;
|
||||
|
||||
internal class DiscordClientOptions
|
||||
{
|
||||
public string ApiUrl { get; init; } = string.Empty;
|
||||
public string AppToken { get; init; } = string.Empty;
|
||||
public int Intents { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace StevesBot.Worker.Discord.Events;
|
||||
|
||||
internal record DiscordEvent
|
||||
{
|
||||
[JsonPropertyName("op")]
|
||||
public int Op { get; init; }
|
||||
|
||||
[JsonPropertyName("s")]
|
||||
public int? Sequence { get; init; }
|
||||
|
||||
[JsonPropertyName("t")]
|
||||
public string? Type { get; init; }
|
||||
|
||||
[JsonPropertyName("d")]
|
||||
public object? Data { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace StevesBot.Worker.Discord.Events;
|
||||
|
||||
internal class DiscordEventConverter : JsonConverter<DiscordEvent>
|
||||
{
|
||||
private const string OpPropertyName = "op";
|
||||
|
||||
public override DiscordEvent? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
using var jsonDoc = JsonDocument.ParseValue(ref reader);
|
||||
var root = jsonDoc.RootElement;
|
||||
var op = root.GetProperty(OpPropertyName).GetInt32();
|
||||
|
||||
return op switch
|
||||
{
|
||||
DiscordOpCodes.Hello => JsonSerializer.Deserialize<HelloDiscordEvent>(root.GetRawText(), options),
|
||||
_ => JsonSerializer.Deserialize<DiscordEvent>(root.GetRawText(), options)
|
||||
};
|
||||
}
|
||||
|
||||
public override void Write(Utf8JsonWriter writer, DiscordEvent value, JsonSerializerOptions options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace StevesBot.Worker.Discord.Events;
|
||||
|
||||
internal static class DiscordOpCodes
|
||||
{
|
||||
public const int Hello = 10;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace StevesBot.Worker.Discord.Events;
|
||||
|
||||
internal record HelloDiscordEvent : DiscordEvent
|
||||
{
|
||||
[JsonPropertyName("d")]
|
||||
public new HelloData? Data { get; init; }
|
||||
}
|
||||
|
||||
internal record HelloData
|
||||
{
|
||||
[JsonPropertyName("heartbeat_interval")]
|
||||
public int HeartbeatInterval { get; init; }
|
||||
}
|
||||
Reference in New Issue
Block a user