feat: identify, presence update commands

This commit is contained in:
sam 2024-09-03 02:11:11 +02:00
parent b3bf3a7c16
commit 6c335568f5
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
11 changed files with 194 additions and 68 deletions

View file

@ -0,0 +1,13 @@
namespace Foxcord.Gateway.Events.Commands;
public record HeartbeatCommand(long? Sequence) : IGatewayCommand
{
public GatewayPacket ToGatewayPacket()
{
return new GatewayPacket
{
Opcode = GatewayOpcode.Heartbeat,
Payload = Sequence
};
}
}

View file

@ -0,0 +1,6 @@
namespace Foxcord.Gateway.Events.Commands;
public interface IGatewayCommand
{
public GatewayPacket ToGatewayPacket();
}

View file

@ -0,0 +1,46 @@
using Foxcord.Models;
namespace Foxcord.Gateway.Events.Commands;
public class PresenceUpdateCommand : IGatewayCommand
{
public long? Since { get; init; }
public Activity[] Activities { get; init; } = [];
public PresenceStatusType Status { get; init; }
public bool Afk { get; init; }
public GatewayPacket ToGatewayPacket()
{
return new GatewayPacket
{
Opcode = GatewayOpcode.PresenceUpdate,
Payload = ToPayload()
};
}
public PresenceUpdatePayload ToPayload()
{
var status = Status switch
{
PresenceStatusType.Online => "online",
PresenceStatusType.Dnd => "dnd",
PresenceStatusType.Idle => "idle",
PresenceStatusType.Invisible => "invisible",
PresenceStatusType.Offline => "offline",
_ => throw new ArgumentOutOfRangeException()
};
return new PresenceUpdatePayload(Since, Activities, status, Afk);
}
public record PresenceUpdatePayload(long? Since, Activity[] Activities, string Status, bool Afk);
}
public enum PresenceStatusType
{
Online,
Dnd,
Idle,
Invisible,
Offline
}

View file

@ -1,3 +1,6 @@
using System.Text.Json.Serialization;
using Foxcord.Gateway.Events.Commands;
namespace Foxcord.Gateway.Events;
public class IdentifyEvent : IGatewayEvent
@ -5,6 +8,10 @@ public class IdentifyEvent : IGatewayEvent
public required string Token { get; init; }
public IdentifyProperties Properties { get; init; } = new();
public GatewayIntent Intents { get; init; }
public PresenceUpdateCommand.PresenceUpdatePayload? Presence { get; init; }
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public int[]? Shards { get; init; }
}
public class IdentifyProperties