feature: Bump API version to 9 (#1847)
* First changes to the config * Lots of changes to fit the new version * Remove PermissionTargetConverter
This commit is contained in:
@@ -17,8 +17,6 @@ namespace Discord.API.Gateway
|
||||
public Optional<int[]> ShardingParams { get; set; }
|
||||
[JsonProperty("presence")]
|
||||
public Optional<StatusUpdateParams> Presence { get; set; }
|
||||
[JsonProperty("guild_subscriptions")]
|
||||
public Optional<bool> GuildSubscriptions { get; set; }
|
||||
[JsonProperty("intents")]
|
||||
public Optional<int> Intents { get; set; }
|
||||
}
|
||||
|
||||
@@ -83,7 +83,6 @@ namespace Discord.WebSocket
|
||||
: base(config, client) => BaseConfig = config;
|
||||
private static DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config)
|
||||
=> new DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent,
|
||||
rateLimitPrecision: config.RateLimitPrecision,
|
||||
useSystemClock: config.UseSystemClock);
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -91,8 +91,7 @@ namespace Discord.WebSocket
|
||||
}
|
||||
}
|
||||
private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config)
|
||||
=> new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent,
|
||||
rateLimitPrecision: config.RateLimitPrecision);
|
||||
=> new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent);
|
||||
|
||||
internal async Task AcquireIdentifyLockAsync(int shardId, CancellationToken token)
|
||||
{
|
||||
|
||||
@@ -40,9 +40,8 @@ namespace Discord.API
|
||||
|
||||
public DiscordSocketApiClient(RestClientProvider restClientProvider, WebSocketProvider webSocketProvider, string userAgent,
|
||||
string url = null, RetryMode defaultRetryMode = RetryMode.AlwaysRetry, JsonSerializer serializer = null,
|
||||
RateLimitPrecision rateLimitPrecision = RateLimitPrecision.Second,
|
||||
bool useSystemClock = true)
|
||||
: base(restClientProvider, userAgent, defaultRetryMode, serializer, rateLimitPrecision, useSystemClock)
|
||||
: base(restClientProvider, userAgent, defaultRetryMode, serializer, useSystemClock)
|
||||
{
|
||||
_gatewayUrl = url;
|
||||
if (url != null)
|
||||
@@ -216,7 +215,7 @@ namespace Discord.API
|
||||
await _sentGatewayMessageEvent.InvokeAsync(opCode).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, bool guildSubscriptions = true, GatewayIntents? gatewayIntents = null, (UserStatus, bool, long?, GameModel)? presence = null, RequestOptions options = null)
|
||||
public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, GatewayIntents gatewayIntents = GatewayIntents.AllUnprivileged, (UserStatus, bool, long?, GameModel)? presence = null, RequestOptions options = null)
|
||||
{
|
||||
options = RequestOptions.CreateOrClone(options);
|
||||
var props = new Dictionary<string, string>
|
||||
@@ -234,10 +233,7 @@ namespace Discord.API
|
||||
|
||||
options.BucketId = GatewayBucket.Get(GatewayBucketType.Identify).Id;
|
||||
|
||||
if (gatewayIntents.HasValue)
|
||||
msg.Intents = (int)gatewayIntents.Value;
|
||||
else
|
||||
msg.GuildSubscriptions = guildSubscriptions;
|
||||
msg.Intents = (int)gatewayIntents;
|
||||
|
||||
if (presence.HasValue)
|
||||
{
|
||||
|
||||
@@ -43,8 +43,7 @@ namespace Discord.WebSocket
|
||||
private DateTimeOffset? _statusSince;
|
||||
private RestApplication _applicationInfo;
|
||||
private bool _isDisposed;
|
||||
private bool _guildSubscriptions;
|
||||
private GatewayIntents? _gatewayIntents;
|
||||
private GatewayIntents _gatewayIntents;
|
||||
|
||||
/// <summary>
|
||||
/// Provides access to a REST-only client with a shared state from this client.
|
||||
@@ -140,7 +139,6 @@ namespace Discord.WebSocket
|
||||
State = new ClientState(0, 0);
|
||||
Rest = new DiscordSocketRestClient(config, ApiClient);
|
||||
_heartbeatTimes = new ConcurrentQueue<long>();
|
||||
_guildSubscriptions = config.GuildSubscriptions;
|
||||
_gatewayIntents = config.GatewayIntents;
|
||||
|
||||
_stateLock = new SemaphoreSlim(1, 1);
|
||||
@@ -182,8 +180,7 @@ namespace Discord.WebSocket
|
||||
_largeGuilds = new ConcurrentQueue<ulong>();
|
||||
}
|
||||
private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config)
|
||||
=> new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent, config.GatewayHost,
|
||||
rateLimitPrecision: config.RateLimitPrecision);
|
||||
=> new API.DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent, config.GatewayHost);
|
||||
/// <inheritdoc />
|
||||
internal override void Dispose(bool disposing)
|
||||
{
|
||||
@@ -243,7 +240,7 @@ namespace Discord.WebSocket
|
||||
else
|
||||
{
|
||||
await _gatewayLogger.DebugAsync("Identifying").ConfigureAwait(false);
|
||||
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, guildSubscriptions: _guildSubscriptions, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false);
|
||||
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
finally
|
||||
@@ -335,7 +332,7 @@ namespace Discord.WebSocket
|
||||
{
|
||||
var user = SocketGlobalUser.Create(this, state, model);
|
||||
user.GlobalUser.AddRef();
|
||||
user.Presence = new SocketPresence(UserStatus.Online, null, null, null);
|
||||
user.Presence = new SocketPresence(UserStatus.Online, null, null);
|
||||
return user;
|
||||
});
|
||||
}
|
||||
@@ -469,7 +466,8 @@ namespace Discord.WebSocket
|
||||
{
|
||||
if (CurrentUser == null)
|
||||
return;
|
||||
CurrentUser.Presence = new SocketPresence(Status, Activity, null, null);
|
||||
var activities = _activity.IsSpecified ? ImmutableList.Create(_activity.Value) : null;
|
||||
CurrentUser.Presence = new SocketPresence(Status, null, activities);
|
||||
|
||||
var presence = BuildCurrentStatus() ?? (UserStatus.Online, false, null, null);
|
||||
|
||||
@@ -564,7 +562,7 @@ namespace Discord.WebSocket
|
||||
await _shardedClient.AcquireIdentifyLockAsync(ShardId, _connection.CancelToken).ConfigureAwait(false);
|
||||
try
|
||||
{
|
||||
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, guildSubscriptions: _guildSubscriptions, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false);
|
||||
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -572,7 +570,7 @@ namespace Discord.WebSocket
|
||||
}
|
||||
}
|
||||
else
|
||||
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, guildSubscriptions: _guildSubscriptions, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false);
|
||||
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false);
|
||||
}
|
||||
break;
|
||||
case GatewayOpCode.Reconnect:
|
||||
@@ -595,7 +593,8 @@ namespace Discord.WebSocket
|
||||
var state = new ClientState(data.Guilds.Length, data.PrivateChannels.Length);
|
||||
|
||||
var currentUser = SocketSelfUser.Create(this, state, data.User);
|
||||
currentUser.Presence = new SocketPresence(Status, Activity, null, null);
|
||||
var activities = _activity.IsSpecified ? ImmutableList.Create(_activity.Value) : null;
|
||||
currentUser.Presence = new SocketPresence(Status, null, activities);
|
||||
ApiClient.CurrentUserId = currentUser.Id;
|
||||
int unavailableGuilds = 0;
|
||||
for (int i = 0; i < data.Guilds.Length; i++)
|
||||
|
||||
@@ -127,12 +127,6 @@ namespace Discord.WebSocket
|
||||
/// </remarks>
|
||||
public bool? ExclusiveBulkDelete { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets enabling dispatching of guild subscription events e.g. presence and typing events.
|
||||
/// This is not used if <see cref="GatewayIntents"/> are provided.
|
||||
/// </summary>
|
||||
public bool GuildSubscriptions { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the maximum identify concurrency.
|
||||
/// </summary>
|
||||
@@ -172,14 +166,15 @@ namespace Discord.WebSocket
|
||||
private int maxWaitForGuildAvailable = 10000;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets gateway intents to limit what events are sent from Discord. Allows for more granular control than the <see cref="GuildSubscriptions"/> property.
|
||||
/// Gets or sets gateway intents to limit what events are sent from Discord.
|
||||
/// The default is <see cref="GatewayIntents.AllUnprivileged"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For more information, please see
|
||||
/// <see href="https://discord.com/developers/docs/topics/gateway#gateway-intents">GatewayIntents</see>
|
||||
/// on the official Discord API documentation.
|
||||
/// </remarks>
|
||||
public GatewayIntents? GatewayIntents { get; set; }
|
||||
public GatewayIntents GatewayIntents { get; set; } = GatewayIntents.AllUnprivileged;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DiscordSocketConfig"/> class with the default configuration.
|
||||
|
||||
@@ -46,8 +46,6 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public int AFKTimeout { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public bool IsEmbeddable { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public bool IsWidgetEnabled { get; private set; }
|
||||
/// <inheritdoc />
|
||||
public VerificationLevel VerificationLevel { get; private set; }
|
||||
@@ -84,7 +82,6 @@ namespace Discord.WebSocket
|
||||
public ulong? ApplicationId { get; internal set; }
|
||||
|
||||
internal ulong? AFKChannelId { get; private set; }
|
||||
internal ulong? EmbedChannelId { get; private set; }
|
||||
internal ulong? WidgetChannelId { get; private set; }
|
||||
internal ulong? SystemChannelId { get; private set; }
|
||||
internal ulong? RulesChannelId { get; private set; }
|
||||
@@ -198,21 +195,6 @@ namespace Discord.WebSocket
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the embed channel (i.e. the channel set in the guild's widget settings) in this guild.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// A channel set within the server's widget settings; <see langword="null"/> if none is set.
|
||||
/// </returns>
|
||||
[Obsolete("This property is deprecated, use WidgetChannel instead.")]
|
||||
public SocketGuildChannel EmbedChannel
|
||||
{
|
||||
get
|
||||
{
|
||||
var id = EmbedChannelId;
|
||||
return id.HasValue ? GetChannel(id.Value) : null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild.
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
@@ -440,16 +422,12 @@ namespace Discord.WebSocket
|
||||
internal void Update(ClientState state, Model model)
|
||||
{
|
||||
AFKChannelId = model.AFKChannelId;
|
||||
if (model.EmbedChannelId.IsSpecified)
|
||||
EmbedChannelId = model.EmbedChannelId.Value;
|
||||
if (model.WidgetChannelId.IsSpecified)
|
||||
WidgetChannelId = model.WidgetChannelId.Value;
|
||||
SystemChannelId = model.SystemChannelId;
|
||||
RulesChannelId = model.RulesChannelId;
|
||||
PublicUpdatesChannelId = model.PublicUpdatesChannelId;
|
||||
AFKTimeout = model.AFKTimeout;
|
||||
if (model.EmbedEnabled.IsSpecified)
|
||||
IsEmbeddable = model.EmbedEnabled.Value;
|
||||
if (model.WidgetEnabled.IsSpecified)
|
||||
IsWidgetEnabled = model.WidgetEnabled.Value;
|
||||
IconId = model.Icon;
|
||||
@@ -548,11 +526,6 @@ namespace Discord.WebSocket
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
|
||||
[Obsolete("This endpoint is deprecated, use ModifyWidgetAsync instead.")]
|
||||
public Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null)
|
||||
=> GuildHelper.ModifyEmbedAsync(this, Discord, func, options);
|
||||
/// <inheritdoc />
|
||||
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception>
|
||||
public Task ModifyWidgetAsync(Action<GuildWidgetProperties> func, RequestOptions options = null)
|
||||
=> GuildHelper.ModifyWidgetAsync(this, Discord, func, options);
|
||||
/// <inheritdoc />
|
||||
@@ -1234,8 +1207,6 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
ulong IGuild.DefaultChannelId => DefaultChannel?.Id ?? 0;
|
||||
/// <inheritdoc />
|
||||
ulong? IGuild.EmbedChannelId => EmbedChannelId;
|
||||
/// <inheritdoc />
|
||||
ulong? IGuild.WidgetChannelId => WidgetChannelId;
|
||||
/// <inheritdoc />
|
||||
ulong? IGuild.SystemChannelId => SystemChannelId;
|
||||
@@ -1290,10 +1261,6 @@ namespace Discord.WebSocket
|
||||
Task<ITextChannel> IGuild.GetDefaultChannelAsync(CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<ITextChannel>(DefaultChannel);
|
||||
/// <inheritdoc />
|
||||
[Obsolete("This method is deprecated, use GetWidgetChannelAsync instead.")]
|
||||
Task<IGuildChannel> IGuild.GetEmbedChannelAsync(CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<IGuildChannel>(EmbedChannel);
|
||||
/// <inheritdoc />
|
||||
Task<IGuildChannel> IGuild.GetWidgetChannelAsync(CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<IGuildChannel>(WidgetChannel);
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -189,9 +189,6 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public Task UnpinAsync(RequestOptions options = null)
|
||||
=> MessageHelper.UnpinAsync(this, Discord, options);
|
||||
/// <inheritdoc />
|
||||
public Task ModifySuppressionAsync(bool suppressEmbeds, RequestOptions options = null)
|
||||
=> MessageHelper.SuppressEmbedsAsync(this, Discord, suppressEmbeds, options);
|
||||
|
||||
public string Resolve(int startIndex, TagHandling userHandling = TagHandling.Name, TagHandling channelHandling = TagHandling.Name,
|
||||
TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name)
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Model = Discord.API.Presence;
|
||||
|
||||
namespace Discord.WebSocket
|
||||
@@ -15,15 +16,12 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public UserStatus Status { get; }
|
||||
/// <inheritdoc />
|
||||
public IActivity Activity { get; }
|
||||
/// <inheritdoc />
|
||||
public IImmutableSet<ClientType> ActiveClients { get; }
|
||||
/// <inheritdoc />
|
||||
public IImmutableList<IActivity> Activities { get; }
|
||||
internal SocketPresence(UserStatus status, IActivity activity, IImmutableSet<ClientType> activeClients, IImmutableList<IActivity> activities)
|
||||
internal SocketPresence(UserStatus status, IImmutableSet<ClientType> activeClients, IImmutableList<IActivity> activities)
|
||||
{
|
||||
Status = status;
|
||||
Activity = activity;
|
||||
ActiveClients = activeClients ?? ImmutableHashSet<ClientType>.Empty;
|
||||
Activities = activities ?? ImmutableList<IActivity>.Empty;
|
||||
}
|
||||
@@ -31,7 +29,7 @@ namespace Discord.WebSocket
|
||||
{
|
||||
var clients = ConvertClientTypesDict(model.ClientStatus.GetValueOrDefault());
|
||||
var activities = ConvertActivitiesList(model.Activities);
|
||||
return new SocketPresence(model.Status, model.Game?.ToEntity(), clients, activities);
|
||||
return new SocketPresence(model.Status, clients, activities);
|
||||
}
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="IReadOnlyCollection{T}"/> containing all of the client types
|
||||
@@ -84,7 +82,7 @@ namespace Discord.WebSocket
|
||||
/// A string that resolves to <see cref="Discord.WebSocket.SocketPresence.Status" />.
|
||||
/// </returns>
|
||||
public override string ToString() => Status.ToString();
|
||||
private string DebuggerDisplay => $"{Status}{(Activity != null ? $", {Activity.Name}": "")}";
|
||||
private string DebuggerDisplay => $"{Status}{(Activities?.FirstOrDefault()?.Name ?? "")}";
|
||||
|
||||
internal SocketPresence Clone() => this;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public override bool IsWebhook => false;
|
||||
/// <inheritdoc />
|
||||
internal override SocketPresence Presence { get { return new SocketPresence(UserStatus.Offline, null, null, null); } set { } }
|
||||
internal override SocketPresence Presence { get { return new SocketPresence(UserStatus.Offline, null, null); } set { } }
|
||||
/// <inheritdoc />
|
||||
/// <exception cref="NotSupportedException">This field is not supported for an unknown user.</exception>
|
||||
internal override SocketGlobalUser GlobalUser =>
|
||||
|
||||
@@ -38,8 +38,6 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public string Mention => MentionUtils.MentionUser(Id);
|
||||
/// <inheritdoc />
|
||||
public IActivity Activity => Presence.Activity;
|
||||
/// <inheritdoc />
|
||||
public UserStatus Status => Presence.Status;
|
||||
/// <inheritdoc />
|
||||
public IImmutableSet<ClientType> ActiveClients => Presence.ActiveClients ?? ImmutableHashSet<ClientType>.Empty;
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace Discord.WebSocket
|
||||
/// <inheritdoc />
|
||||
public override bool IsWebhook => true;
|
||||
/// <inheritdoc />
|
||||
internal override SocketPresence Presence { get { return new SocketPresence(UserStatus.Offline, null, null, null); } set { } }
|
||||
internal override SocketPresence Presence { get { return new SocketPresence(UserStatus.Offline, null, null); } set { } }
|
||||
internal override SocketGlobalUser GlobalUser =>
|
||||
throw new NotSupportedException();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user