feat: identify, presence update commands
This commit is contained in:
parent
b3bf3a7c16
commit
6c335568f5
11 changed files with 194 additions and 68 deletions
13
Foxcord/Gateway/Events/Commands/HeartbeatCommand.cs
Normal file
13
Foxcord/Gateway/Events/Commands/HeartbeatCommand.cs
Normal 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
|
||||
};
|
||||
}
|
||||
}
|
6
Foxcord/Gateway/Events/Commands/IGatewayCommand.cs
Normal file
6
Foxcord/Gateway/Events/Commands/IGatewayCommand.cs
Normal file
|
@ -0,0 +1,6 @@
|
|||
namespace Foxcord.Gateway.Events.Commands;
|
||||
|
||||
public interface IGatewayCommand
|
||||
{
|
||||
public GatewayPacket ToGatewayPacket();
|
||||
}
|
46
Foxcord/Gateway/Events/Commands/PresenceUpdateCommand.cs
Normal file
46
Foxcord/Gateway/Events/Commands/PresenceUpdateCommand.cs
Normal 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
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue