feat: set initial presence when connecting
This commit is contained in:
@@ -389,7 +389,18 @@ internal sealed class DiscordGatewayClient : IDiscordGatewayClient
|
|||||||
{
|
{
|
||||||
var identify = new IdentifyDiscordEvent(
|
var identify = new IdentifyDiscordEvent(
|
||||||
_options.AppToken,
|
_options.AppToken,
|
||||||
_options.Intents
|
DiscordIntents.All,
|
||||||
|
new UpdatePresenceData
|
||||||
|
{
|
||||||
|
Status = PresenceStatus.Online,
|
||||||
|
Activities = [
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Name = "Helping Stevan",
|
||||||
|
State = "Helping Stevan"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
await SendJsonAsync(identify, cancellationToken);
|
await SendJsonAsync(identify, cancellationToken);
|
||||||
|
|||||||
@@ -5,30 +5,34 @@ internal sealed record IdentifyDiscordEvent : DiscordEvent
|
|||||||
[JsonPropertyName("d")]
|
[JsonPropertyName("d")]
|
||||||
public new IdentifyData Data { get; init; } = new IdentifyData();
|
public new IdentifyData Data { get; init; } = new IdentifyData();
|
||||||
|
|
||||||
public IdentifyDiscordEvent(string token, long intents)
|
public IdentifyDiscordEvent(string token, long intents, UpdatePresenceData presence)
|
||||||
{
|
{
|
||||||
OpCode = DiscordOpCodes.Identify;
|
OpCode = DiscordOpCodes.Identify;
|
||||||
Data = new IdentifyData
|
Data = new IdentifyData
|
||||||
{
|
{
|
||||||
Token = token,
|
Token = token,
|
||||||
Intents = intents,
|
Intents = intents,
|
||||||
|
Presence = presence,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal record IdentifyData
|
internal sealed record IdentifyData
|
||||||
{
|
{
|
||||||
[JsonPropertyName("token")]
|
[JsonPropertyName("token")]
|
||||||
public string Token { get; init; } = string.Empty;
|
public string Token { get; init; } = string.Empty;
|
||||||
|
|
||||||
[JsonPropertyName("properties")]
|
[JsonPropertyName("properties")]
|
||||||
public IdentifyProperties Properties { get; init; } = new IdentifyProperties();
|
public IdentifyProperties Properties { get; init; } = new();
|
||||||
|
|
||||||
|
[JsonPropertyName("presence")]
|
||||||
|
public UpdatePresenceData Presence { get; init; } = new();
|
||||||
|
|
||||||
[JsonPropertyName("intents")]
|
[JsonPropertyName("intents")]
|
||||||
public long Intents { get; init; }
|
public long Intents { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal record IdentifyProperties
|
internal sealed record IdentifyProperties
|
||||||
{
|
{
|
||||||
[JsonPropertyName("os")]
|
[JsonPropertyName("os")]
|
||||||
public string Os { get; init; } = Environment.OSVersion.ToString();
|
public string Os { get; init; } = Environment.OSVersion.ToString();
|
||||||
@@ -39,3 +43,42 @@ internal 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;
|
||||||
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
namespace StevesBot.Worker.Discord.Events;
|
namespace StevesBot.Worker.Discord.Events;
|
||||||
|
|
||||||
internal record ReadyDiscordEvent : DispatchDiscordEvent
|
internal sealed record ReadyDiscordEvent : DispatchDiscordEvent
|
||||||
{
|
{
|
||||||
[JsonPropertyName("d")]
|
[JsonPropertyName("d")]
|
||||||
public new ReadyData Data { get; init; } = new ReadyData();
|
public new ReadyData Data { get; init; } = new ReadyData();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal record ReadyData
|
internal sealed record ReadyData
|
||||||
{
|
{
|
||||||
[JsonPropertyName("v")]
|
[JsonPropertyName("v")]
|
||||||
public int Version { get; init; }
|
public int Version { get; init; }
|
||||||
|
|||||||
Reference in New Issue
Block a user