feature: support guild subscription opt-out (#1386)
This commit is contained in:
committed by
Christopher F
parent
3d39704c6c
commit
0d54207a27
@@ -15,5 +15,7 @@ namespace Discord.API.Gateway
|
|||||||
public int LargeThreshold { get; set; }
|
public int LargeThreshold { get; set; }
|
||||||
[JsonProperty("shard")]
|
[JsonProperty("shard")]
|
||||||
public Optional<int[]> ShardingParams { get; set; }
|
public Optional<int[]> ShardingParams { get; set; }
|
||||||
|
[JsonProperty("guild_subscriptions")]
|
||||||
|
public Optional<bool> GuildSubscriptions { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ namespace Discord.API
|
|||||||
await _sentGatewayMessageEvent.InvokeAsync(opCode).ConfigureAwait(false);
|
await _sentGatewayMessageEvent.InvokeAsync(opCode).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, RequestOptions options = null)
|
public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, bool guildSubscriptions = true, RequestOptions options = null)
|
||||||
{
|
{
|
||||||
options = RequestOptions.CreateOrClone(options);
|
options = RequestOptions.CreateOrClone(options);
|
||||||
var props = new Dictionary<string, string>
|
var props = new Dictionary<string, string>
|
||||||
@@ -226,7 +226,8 @@ namespace Discord.API
|
|||||||
{
|
{
|
||||||
Token = AuthToken,
|
Token = AuthToken,
|
||||||
Properties = props,
|
Properties = props,
|
||||||
LargeThreshold = largeThreshold
|
LargeThreshold = largeThreshold,
|
||||||
|
GuildSubscriptions = guildSubscriptions
|
||||||
};
|
};
|
||||||
if (totalShards > 1)
|
if (totalShards > 1)
|
||||||
msg.ShardingParams = new int[] { shardID, totalShards };
|
msg.ShardingParams = new int[] { shardID, totalShards };
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ namespace Discord.WebSocket
|
|||||||
private DateTimeOffset? _statusSince;
|
private DateTimeOffset? _statusSince;
|
||||||
private RestApplication _applicationInfo;
|
private RestApplication _applicationInfo;
|
||||||
private bool _isDisposed;
|
private bool _isDisposed;
|
||||||
|
private bool _guildSubscriptions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides access to a REST-only client with a shared state from this client.
|
/// Provides access to a REST-only client with a shared state from this client.
|
||||||
@@ -135,6 +136,7 @@ namespace Discord.WebSocket
|
|||||||
State = new ClientState(0, 0);
|
State = new ClientState(0, 0);
|
||||||
Rest = new DiscordSocketRestClient(config, ApiClient);
|
Rest = new DiscordSocketRestClient(config, ApiClient);
|
||||||
_heartbeatTimes = new ConcurrentQueue<long>();
|
_heartbeatTimes = new ConcurrentQueue<long>();
|
||||||
|
_guildSubscriptions = config.GuildSubscriptions;
|
||||||
|
|
||||||
_stateLock = new SemaphoreSlim(1, 1);
|
_stateLock = new SemaphoreSlim(1, 1);
|
||||||
_gatewayLogger = LogManager.CreateLogger(ShardId == 0 && TotalShards == 1 ? "Gateway" : $"Shard #{ShardId}");
|
_gatewayLogger = LogManager.CreateLogger(ShardId == 0 && TotalShards == 1 ? "Gateway" : $"Shard #{ShardId}");
|
||||||
@@ -240,7 +242,7 @@ namespace Discord.WebSocket
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _gatewayLogger.DebugAsync("Identifying").ConfigureAwait(false);
|
await _gatewayLogger.DebugAsync("Identifying").ConfigureAwait(false);
|
||||||
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards).ConfigureAwait(false);
|
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, guildSubscriptions: _guildSubscriptions).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Wait for READY
|
//Wait for READY
|
||||||
|
|||||||
@@ -119,6 +119,11 @@ namespace Discord.WebSocket
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool? ExclusiveBulkDelete { get; set; } = null;
|
public bool? ExclusiveBulkDelete { get; set; } = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets enabling dispatching of guild subscription events e.g. presence and typing events.
|
||||||
|
/// </summary>
|
||||||
|
public bool GuildSubscriptions { get; set; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a default configuration.
|
/// Initializes a default configuration.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user