feat: implement update presence event
This commit is contained in:
@@ -5,6 +5,7 @@ internal static class DiscordOpCodes
|
|||||||
public const int Dispatch = 0;
|
public const int Dispatch = 0;
|
||||||
public const int Heartbeat = 1;
|
public const int Heartbeat = 1;
|
||||||
public const int Identify = 2;
|
public const int Identify = 2;
|
||||||
|
public const int PresenceUpdate = 3;
|
||||||
public const int Resume = 6;
|
public const int Resume = 6;
|
||||||
public const int Reconnect = 7;
|
public const int Reconnect = 7;
|
||||||
public const int InvalidSession = 9;
|
public const int InvalidSession = 9;
|
||||||
|
|||||||
@@ -43,42 +43,3 @@ internal sealed record IdentifyProperties
|
|||||||
[JsonPropertyName("device")]
|
[JsonPropertyName("device")]
|
||||||
public string Device { get; init; } = Assembly.GetExecutingAssembly().GetName().FullName;
|
public string Device { get; init; } = Assembly.GetExecutingAssembly().GetName().FullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Move this to an update presence event file
|
|
||||||
|
|
||||||
internal sealed record UpdatePresenceData
|
|
||||||
{
|
|
||||||
[JsonPropertyName("since")]
|
|
||||||
public long? Since { get; init; } = null;
|
|
||||||
|
|
||||||
[JsonPropertyName("activities")]
|
|
||||||
public List<Activity> Activities { get; init; } = [];
|
|
||||||
|
|
||||||
[JsonPropertyName("status")]
|
|
||||||
public string Status { get; init; } = PresenceStatus.Online;
|
|
||||||
|
|
||||||
[JsonPropertyName("afk")]
|
|
||||||
public bool Afk { get; init; }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static class PresenceStatus
|
|
||||||
{
|
|
||||||
public const string Online = "online";
|
|
||||||
}
|
|
||||||
|
|
||||||
internal sealed record Activity
|
|
||||||
{
|
|
||||||
[JsonPropertyName("name")]
|
|
||||||
public string Name { get; init; } = string.Empty;
|
|
||||||
|
|
||||||
[JsonPropertyName("type")]
|
|
||||||
public int Type { get; init; } = ActivityType.Custom;
|
|
||||||
|
|
||||||
[JsonPropertyName("state")]
|
|
||||||
public string? State { get; init; }
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static class ActivityType
|
|
||||||
{
|
|
||||||
public const int Custom = 4;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
namespace StevesBot.Worker.Discord.Events;
|
||||||
|
|
||||||
|
internal sealed record UpdatePresenceDiscordEvent : DiscordEvent
|
||||||
|
{
|
||||||
|
[JsonPropertyName("d")]
|
||||||
|
public new UpdatePresenceData Data { get; init; } = new UpdatePresenceData();
|
||||||
|
|
||||||
|
public UpdatePresenceDiscordEvent(long? since, List<Activity> activities, string status, bool afk)
|
||||||
|
{
|
||||||
|
OpCode = DiscordOpCodes.PresenceUpdate;
|
||||||
|
Data = new UpdatePresenceData
|
||||||
|
{
|
||||||
|
Since = since,
|
||||||
|
Activities = activities,
|
||||||
|
Status = status,
|
||||||
|
Afk = afk,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed record UpdatePresenceData
|
||||||
|
{
|
||||||
|
[JsonPropertyName("since")]
|
||||||
|
public long? Since { get; init; } = null;
|
||||||
|
|
||||||
|
[JsonPropertyName("activities")]
|
||||||
|
public List<Activity> Activities { get; init; } = [];
|
||||||
|
|
||||||
|
[JsonPropertyName("status")]
|
||||||
|
public string Status { get; init; } = PresenceStatus.Online;
|
||||||
|
|
||||||
|
[JsonPropertyName("afk")]
|
||||||
|
public bool Afk { get; init; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class PresenceStatus
|
||||||
|
{
|
||||||
|
public const string Online = "online";
|
||||||
|
}
|
||||||
|
|
||||||
|
internal sealed record Activity
|
||||||
|
{
|
||||||
|
[JsonPropertyName("name")]
|
||||||
|
public string Name { get; init; } = string.Empty;
|
||||||
|
|
||||||
|
[JsonPropertyName("type")]
|
||||||
|
public int Type { get; init; } = ActivityType.Custom;
|
||||||
|
|
||||||
|
[JsonPropertyName("state")]
|
||||||
|
public string? State { get; init; }
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static class ActivityType
|
||||||
|
{
|
||||||
|
public const int Custom = 4;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user