* First changes to the config * Lots of changes to fit the new version * Remove PermissionTargetConverterpull/1850/head
@@ -16,7 +16,7 @@ namespace Discord | |||||
/// <see href="https://discord.com/developers/docs/reference#api-versioning">Discord API documentation</see> | /// <see href="https://discord.com/developers/docs/reference#api-versioning">Discord API documentation</see> | ||||
/// .</para> | /// .</para> | ||||
/// </returns> | /// </returns> | ||||
public const int APIVersion = 6; | |||||
public const int APIVersion = 9; | |||||
/// <summary> | /// <summary> | ||||
/// Returns the Voice API version Discord.Net uses. | /// Returns the Voice API version Discord.Net uses. | ||||
/// </summary> | /// </summary> | ||||
@@ -43,7 +43,7 @@ namespace Discord | |||||
/// <returns> | /// <returns> | ||||
/// The user agent used in each Discord.Net request. | /// The user agent used in each Discord.Net request. | ||||
/// </returns> | /// </returns> | ||||
public static string UserAgent { get; } = $"DiscordBot (https://github.com/RogueException/Discord.Net, v{Version})"; | |||||
public static string UserAgent { get; } = $"DiscordBot (https://github.com/discord-net/Discord.Net, v{Version})"; | |||||
/// <summary> | /// <summary> | ||||
/// Returns the base Discord API URL. | /// Returns the base Discord API URL. | ||||
/// </summary> | /// </summary> | ||||
@@ -141,18 +141,6 @@ namespace Discord | |||||
/// </remarks> | /// </remarks> | ||||
internal bool DisplayInitialLog { get; set; } = true; | internal bool DisplayInitialLog { get; set; } = true; | ||||
/// <summary> | |||||
/// Gets or sets the level of precision of the rate limit reset response. | |||||
/// </summary> | |||||
/// <remarks> | |||||
/// If set to <see cref="RateLimitPrecision.Second"/>, this value will be rounded up to the | |||||
/// nearest second. | |||||
/// </remarks> | |||||
/// <returns> | |||||
/// The currently set <see cref="RateLimitPrecision"/>. | |||||
/// </returns> | |||||
public RateLimitPrecision RateLimitPrecision { get; set; } = RateLimitPrecision.Millisecond; | |||||
/// <summary> | /// <summary> | ||||
/// Gets or sets whether or not rate-limits should use the system clock. | /// Gets or sets whether or not rate-limits should use the system clock. | ||||
/// </summary> | /// </summary> | ||||
@@ -28,13 +28,6 @@ namespace Discord | |||||
/// </returns> | /// </returns> | ||||
int AFKTimeout { get; } | int AFKTimeout { get; } | ||||
/// <summary> | /// <summary> | ||||
/// Gets a value that indicates whether this guild is embeddable (i.e. can use widget). | |||||
/// </summary> | |||||
/// <returns> | |||||
/// <see langword="true" /> if this guild has a widget enabled; otherwise <see langword="false" />. | |||||
/// </returns> | |||||
bool IsEmbeddable { get; } | |||||
/// <summary> | |||||
/// Gets a value that indicates whether this guild has the widget enabled. | /// Gets a value that indicates whether this guild has the widget enabled. | ||||
/// </summary> | /// </summary> | ||||
/// <returns> | /// <returns> | ||||
@@ -147,14 +140,6 @@ namespace Discord | |||||
/// </returns> | /// </returns> | ||||
ulong DefaultChannelId { get; } | ulong DefaultChannelId { get; } | ||||
/// <summary> | /// <summary> | ||||
/// Gets the ID of the widget embed channel of this guild. | |||||
/// </summary> | |||||
/// <returns> | |||||
/// A <see langword="ulong"/> representing the snowflake identifier of the embedded channel found within the | |||||
/// widget settings of this guild; <see langword="null" /> if none is set. | |||||
/// </returns> | |||||
ulong? EmbedChannelId { get; } | |||||
/// <summary> | |||||
/// Gets the ID of the channel assigned to the widget of this guild. | /// Gets the ID of the channel assigned to the widget of this guild. | ||||
/// </summary> | /// </summary> | ||||
/// <returns> | /// <returns> | ||||
@@ -364,16 +349,6 @@ namespace Discord | |||||
/// </returns> | /// </returns> | ||||
Task ModifyAsync(Action<GuildProperties> func, RequestOptions options = null); | Task ModifyAsync(Action<GuildProperties> func, RequestOptions options = null); | ||||
/// <summary> | /// <summary> | ||||
/// Modifies this guild's embed channel. | |||||
/// </summary> | |||||
/// <param name="func">The delegate containing the properties to modify the guild widget with.</param> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous modification operation. | |||||
/// </returns> | |||||
[Obsolete("This endpoint is deprecated, use ModifyWidgetAsync instead.")] | |||||
Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null); | |||||
/// <summary> | |||||
/// Modifies this guild's widget. | /// Modifies this guild's widget. | ||||
/// </summary> | /// </summary> | ||||
/// <param name="func">The delegate containing the properties to modify the guild widget with.</param> | /// <param name="func">The delegate containing the properties to modify the guild widget with.</param> | ||||
@@ -592,17 +567,6 @@ namespace Discord | |||||
/// </returns> | /// </returns> | ||||
Task<ITextChannel> GetDefaultChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | Task<ITextChannel> GetDefaultChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | ||||
/// <summary> | /// <summary> | ||||
/// Gets the embed channel (i.e. the channel set in the guild's widget settings) in this guild. | |||||
/// </summary> | |||||
/// <param name="mode">The <see cref="CacheMode" /> that determines whether the object should be fetched from cache.</param> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous get operation. The task result contains the embed channel set | |||||
/// within the server's widget settings; <see langword="null" /> if none is set. | |||||
/// </returns> | |||||
[Obsolete("This endpoint is deprecated, use GetWidgetChannelAsync instead.")] | |||||
Task<IGuildChannel> GetEmbedChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||||
/// <summary> | |||||
/// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild. | /// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild. | ||||
/// </summary> | /// </summary> | ||||
/// <param name="mode">The <see cref="CacheMode" /> that determines whether the object should be fetched from cache.</param> | /// <param name="mode">The <see cref="CacheMode" /> that determines whether the object should be fetched from cache.</param> | ||||
@@ -8,10 +8,10 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// The target of the permission is a role. | /// The target of the permission is a role. | ||||
/// </summary> | /// </summary> | ||||
Role, | |||||
Role = 0, | |||||
/// <summary> | /// <summary> | ||||
/// The target of the permission is a user. | /// The target of the permission is a user. | ||||
/// </summary> | /// </summary> | ||||
User | |||||
User = 1, | |||||
} | } | ||||
} | } |
@@ -36,18 +36,6 @@ namespace Discord | |||||
/// </returns> | /// </returns> | ||||
Task ModifyAsync(Action<MessageProperties> func, RequestOptions options = null); | Task ModifyAsync(Action<MessageProperties> func, RequestOptions options = null); | ||||
/// <summary> | /// <summary> | ||||
/// Modifies the suppression of this message. | |||||
/// </summary> | |||||
/// <remarks> | |||||
/// This method modifies whether or not embeds in this message are suppressed (hidden). | |||||
/// </remarks> | |||||
/// <param name="suppressEmbeds">Whether or not embeds in this message should be suppressed.</param> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous modification operation. | |||||
/// </returns> | |||||
Task ModifySuppressionAsync(bool suppressEmbeds, RequestOptions options = null); | |||||
/// <summary> | |||||
/// Adds this message to its channel's pinned messages. | /// Adds this message to its channel's pinned messages. | ||||
/// </summary> | /// </summary> | ||||
/// <param name="options">The options to be used when sending the request.</param> | /// <param name="options">The options to be used when sending the request.</param> | ||||
@@ -60,9 +60,6 @@ namespace Discord | |||||
/// <summary> | /// <summary> | ||||
/// The message is an inline reply. | /// The message is an inline reply. | ||||
/// </summary> | /// </summary> | ||||
/// <remarks> | |||||
/// Only available in API v8. | |||||
/// </remarks> | |||||
Reply = 19, | Reply = 19, | ||||
} | } | ||||
} | } |
@@ -90,6 +90,9 @@ namespace Discord | |||||
/// <summary> Creates a new <see cref="GuildPermissions"/> with the provided packed value. </summary> | /// <summary> Creates a new <see cref="GuildPermissions"/> with the provided packed value. </summary> | ||||
public GuildPermissions(ulong rawValue) { RawValue = rawValue; } | public GuildPermissions(ulong rawValue) { RawValue = rawValue; } | ||||
/// <summary> Creates a new <see cref="GuildPermissions"/> with the provided packed value after converting to ulong. </summary> | |||||
public GuildPermissions(string rawValue) { RawValue = ulong.Parse(rawValue); } | |||||
private GuildPermissions(ulong initialValue, | private GuildPermissions(ulong initialValue, | ||||
bool? createInstantInvite = null, | bool? createInstantInvite = null, | ||||
bool? kickMembers = null, | bool? kickMembers = null, | ||||
@@ -93,6 +93,13 @@ namespace Discord | |||||
DenyValue = denyValue; | DenyValue = denyValue; | ||||
} | } | ||||
/// <summary> Creates a new OverwritePermissions with the provided allow and deny packed values after converting to ulong. </summary> | |||||
public OverwritePermissions(string allowValue, string denyValue) | |||||
{ | |||||
AllowValue = ulong.Parse(allowValue); | |||||
DenyValue = ulong.Parse(denyValue); | |||||
} | |||||
private OverwritePermissions(ulong allowValue, ulong denyValue, | private OverwritePermissions(ulong allowValue, ulong denyValue, | ||||
PermValue? createInstantInvite = null, | PermValue? createInstantInvite = null, | ||||
PermValue? manageChannel = null, | PermValue? manageChannel = null, | ||||
@@ -8,10 +8,6 @@ namespace Discord | |||||
public interface IPresence | public interface IPresence | ||||
{ | { | ||||
/// <summary> | /// <summary> | ||||
/// Gets the activity this user is currently doing. | |||||
/// </summary> | |||||
IActivity Activity { get; } | |||||
/// <summary> | |||||
/// Gets the current status of this user. | /// Gets the current status of this user. | ||||
/// </summary> | /// </summary> | ||||
UserStatus Status { get; } | UserStatus Status { get; } | ||||
@@ -39,5 +39,16 @@ namespace Discord | |||||
DirectMessageReactions = 1 << 13, | DirectMessageReactions = 1 << 13, | ||||
/// <summary> This intent includes TYPING_START </summary> | /// <summary> This intent includes TYPING_START </summary> | ||||
DirectMessageTyping = 1 << 14, | DirectMessageTyping = 1 << 14, | ||||
/// <summary> | |||||
/// This intent includes all but <see cref="GuildMembers"/> and <see cref="GuildMembers"/> | |||||
/// that are privileged must be enabled for the application. | |||||
/// </summary> | |||||
AllUnprivileged = Guilds | GuildBans | GuildEmojis | GuildIntegrations | GuildWebhooks | GuildInvites | | |||||
GuildVoiceStates | GuildMessages | GuildMessageReactions | GuildMessageTyping | DirectMessages | | |||||
DirectMessageReactions | DirectMessageTyping, | |||||
/// <summary> | |||||
/// This intent includes all of them, including privileged ones. | |||||
/// </summary> | |||||
All = AllUnprivileged | GuildMembers | GuildPresences | |||||
} | } | ||||
} | } |
@@ -1,18 +0,0 @@ | |||||
namespace Discord | |||||
{ | |||||
/// <summary> | |||||
/// Specifies the level of precision to request in the rate limit | |||||
/// response header. | |||||
/// </summary> | |||||
public enum RateLimitPrecision | |||||
{ | |||||
/// <summary> | |||||
/// Specifies precision rounded up to the nearest whole second | |||||
/// </summary> | |||||
Second, | |||||
/// <summary> | |||||
/// Specifies precision rounded to the nearest millisecond. | |||||
/// </summary> | |||||
Millisecond | |||||
} | |||||
} |
@@ -23,10 +23,6 @@ namespace Discord.API | |||||
public ulong? AFKChannelId { get; set; } | public ulong? AFKChannelId { get; set; } | ||||
[JsonProperty("afk_timeout")] | [JsonProperty("afk_timeout")] | ||||
public int AFKTimeout { get; set; } | public int AFKTimeout { get; set; } | ||||
[JsonProperty("embed_enabled")] | |||||
public Optional<bool> EmbedEnabled { get; set; } | |||||
[JsonProperty("embed_channel_id")] | |||||
public Optional<ulong?> EmbedChannelId { get; set; } | |||||
[JsonProperty("verification_level")] | [JsonProperty("verification_level")] | ||||
public VerificationLevel VerificationLevel { get; set; } | public VerificationLevel VerificationLevel { get; set; } | ||||
[JsonProperty("default_message_notifications")] | [JsonProperty("default_message_notifications")] | ||||
@@ -1,13 +0,0 @@ | |||||
#pragma warning disable CS1591 | |||||
using Newtonsoft.Json; | |||||
namespace Discord.API | |||||
{ | |||||
internal class GuildEmbed | |||||
{ | |||||
[JsonProperty("enabled")] | |||||
public bool Enabled { get; set; } | |||||
[JsonProperty("channel_id")] | |||||
public ulong? ChannelId { get; set; } | |||||
} | |||||
} |
@@ -10,8 +10,8 @@ namespace Discord.API | |||||
[JsonProperty("type")] | [JsonProperty("type")] | ||||
public PermissionTarget TargetType { get; set; } | public PermissionTarget TargetType { get; set; } | ||||
[JsonProperty("deny"), Int53] | [JsonProperty("deny"), Int53] | ||||
public ulong Deny { get; set; } | |||||
public string Deny { get; set; } | |||||
[JsonProperty("allow"), Int53] | [JsonProperty("allow"), Int53] | ||||
public ulong Allow { get; set; } | |||||
public string Allow { get; set; } | |||||
} | } | ||||
} | } |
@@ -13,8 +13,6 @@ namespace Discord.API | |||||
public Optional<ulong> GuildId { get; set; } | public Optional<ulong> GuildId { get; set; } | ||||
[JsonProperty("status")] | [JsonProperty("status")] | ||||
public UserStatus Status { get; set; } | public UserStatus Status { get; set; } | ||||
[JsonProperty("game")] | |||||
public Game Game { get; set; } | |||||
[JsonProperty("roles")] | [JsonProperty("roles")] | ||||
public Optional<ulong[]> Roles { get; set; } | public Optional<ulong[]> Roles { get; set; } | ||||
@@ -18,7 +18,7 @@ namespace Discord.API | |||||
[JsonProperty("position")] | [JsonProperty("position")] | ||||
public int Position { get; set; } | public int Position { get; set; } | ||||
[JsonProperty("permissions"), Int53] | [JsonProperty("permissions"), Int53] | ||||
public ulong Permissions { get; set; } | |||||
public string Permissions { get; set; } | |||||
[JsonProperty("managed")] | [JsonProperty("managed")] | ||||
public bool Managed { get; set; } | public bool Managed { get; set; } | ||||
[JsonProperty("tags")] | [JsonProperty("tags")] | ||||
@@ -1,4 +1,4 @@ | |||||
#pragma warning disable CS1591 | |||||
#pragma warning disable CS1591 | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
namespace Discord.API | namespace Discord.API | ||||
@@ -14,6 +14,6 @@ namespace Discord.API | |||||
[JsonProperty("owner")] | [JsonProperty("owner")] | ||||
public bool Owner { get; set; } | public bool Owner { get; set; } | ||||
[JsonProperty("permissions"), Int53] | [JsonProperty("permissions"), Int53] | ||||
public ulong Permissions { get; set; } | |||||
public string Permissions { get; set; } | |||||
} | } | ||||
} | } |
@@ -1,4 +1,4 @@ | |||||
#pragma warning disable CS1591 | |||||
#pragma warning disable CS1591 | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
@@ -7,13 +7,13 @@ namespace Discord.API.Rest | |||||
internal class ModifyChannelPermissionsParams | internal class ModifyChannelPermissionsParams | ||||
{ | { | ||||
[JsonProperty("type")] | [JsonProperty("type")] | ||||
public string Type { get; } | |||||
public int Type { get; } | |||||
[JsonProperty("allow")] | [JsonProperty("allow")] | ||||
public ulong Allow { get; } | |||||
public string Allow { get; } | |||||
[JsonProperty("deny")] | [JsonProperty("deny")] | ||||
public ulong Deny { get; } | |||||
public string Deny { get; } | |||||
public ModifyChannelPermissionsParams(string type, ulong allow, ulong deny) | |||||
public ModifyChannelPermissionsParams(int type, string allow, string deny) | |||||
{ | { | ||||
Type = type; | Type = type; | ||||
Allow = allow; | Allow = allow; | ||||
@@ -1,4 +1,4 @@ | |||||
#pragma warning disable CS1591 | |||||
#pragma warning disable CS1591 | |||||
using Newtonsoft.Json; | using Newtonsoft.Json; | ||||
namespace Discord.API.Rest | namespace Discord.API.Rest | ||||
@@ -9,7 +9,7 @@ namespace Discord.API.Rest | |||||
[JsonProperty("name")] | [JsonProperty("name")] | ||||
public Optional<string> Name { get; set; } | public Optional<string> Name { get; set; } | ||||
[JsonProperty("permissions")] | [JsonProperty("permissions")] | ||||
public Optional<ulong> Permissions { get; set; } | |||||
public Optional<string> Permissions { get; set; } | |||||
[JsonProperty("color")] | [JsonProperty("color")] | ||||
public Optional<uint> Color { get; set; } | public Optional<uint> Color { get; set; } | ||||
[JsonProperty("hoist")] | [JsonProperty("hoist")] | ||||
@@ -1,11 +0,0 @@ | |||||
using Newtonsoft.Json; | |||||
namespace Discord.API.Rest | |||||
{ | |||||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)] | |||||
internal class SuppressEmbedParams | |||||
{ | |||||
[JsonProperty("suppress")] | |||||
public bool Suppressed { get; set; } | |||||
} | |||||
} |
@@ -69,14 +69,6 @@ namespace Discord.Rest | |||||
return RestGuild.Create(client, model); | return RestGuild.Create(client, model); | ||||
return null; | return null; | ||||
} | } | ||||
public static async Task<RestGuildEmbed?> GetGuildEmbedAsync(BaseDiscordClient client, | |||||
ulong id, RequestOptions options) | |||||
{ | |||||
var model = await client.ApiClient.GetGuildEmbedAsync(id, options).ConfigureAwait(false); | |||||
if (model != null) | |||||
return RestGuildEmbed.Create(model); | |||||
return null; | |||||
} | |||||
public static async Task<RestGuildWidget?> GetGuildWidgetAsync(BaseDiscordClient client, | public static async Task<RestGuildWidget?> GetGuildWidgetAsync(BaseDiscordClient client, | ||||
ulong id, RequestOptions options) | ulong id, RequestOptions options) | ||||
{ | { | ||||
@@ -45,20 +45,18 @@ namespace Discord.API | |||||
internal string AuthToken { get; private set; } | internal string AuthToken { get; private set; } | ||||
internal IRestClient RestClient { get; private set; } | internal IRestClient RestClient { get; private set; } | ||||
internal ulong? CurrentUserId { get; set; } | internal ulong? CurrentUserId { get; set; } | ||||
public RateLimitPrecision RateLimitPrecision { get; private set; } | |||||
internal bool UseSystemClock { get; set; } | internal bool UseSystemClock { get; set; } | ||||
internal JsonSerializer Serializer => _serializer; | internal JsonSerializer Serializer => _serializer; | ||||
/// <exception cref="ArgumentException">Unknown OAuth token type.</exception> | /// <exception cref="ArgumentException">Unknown OAuth token type.</exception> | ||||
public DiscordRestApiClient(RestClientProvider restClientProvider, string userAgent, RetryMode defaultRetryMode = RetryMode.AlwaysRetry, | public DiscordRestApiClient(RestClientProvider restClientProvider, string userAgent, RetryMode defaultRetryMode = RetryMode.AlwaysRetry, | ||||
JsonSerializer serializer = null, RateLimitPrecision rateLimitPrecision = RateLimitPrecision.Second, bool useSystemClock = true) | |||||
JsonSerializer serializer = null, bool useSystemClock = true) | |||||
{ | { | ||||
_restClientProvider = restClientProvider; | _restClientProvider = restClientProvider; | ||||
UserAgent = userAgent; | UserAgent = userAgent; | ||||
DefaultRetryMode = defaultRetryMode; | DefaultRetryMode = defaultRetryMode; | ||||
_serializer = serializer ?? new JsonSerializer { ContractResolver = new DiscordContractResolver() }; | _serializer = serializer ?? new JsonSerializer { ContractResolver = new DiscordContractResolver() }; | ||||
RateLimitPrecision = rateLimitPrecision; | |||||
UseSystemClock = useSystemClock; | UseSystemClock = useSystemClock; | ||||
RequestQueue = new RequestQueue(); | RequestQueue = new RequestQueue(); | ||||
@@ -75,7 +73,6 @@ namespace Discord.API | |||||
RestClient.SetHeader("accept", "*/*"); | RestClient.SetHeader("accept", "*/*"); | ||||
RestClient.SetHeader("user-agent", UserAgent); | RestClient.SetHeader("user-agent", UserAgent); | ||||
RestClient.SetHeader("authorization", GetPrefixedToken(AuthTokenType, AuthToken)); | RestClient.SetHeader("authorization", GetPrefixedToken(AuthTokenType, AuthToken)); | ||||
RestClient.SetHeader("X-RateLimit-Precision", RateLimitPrecision.ToString().ToLower()); | |||||
} | } | ||||
/// <exception cref="ArgumentException">Unknown OAuth token type.</exception> | /// <exception cref="ArgumentException">Unknown OAuth token type.</exception> | ||||
internal static string GetPrefixedToken(TokenType tokenType, string token) | internal static string GetPrefixedToken(TokenType tokenType, string token) | ||||
@@ -645,16 +642,6 @@ namespace Discord.API | |||||
return await SendJsonAsync<Message>("PATCH", () => $"channels/{channelId}/messages/{messageId}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); | return await SendJsonAsync<Message>("PATCH", () => $"channels/{channelId}/messages/{messageId}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); | ||||
} | } | ||||
public async Task SuppressEmbedAsync(ulong channelId, ulong messageId, Rest.SuppressEmbedParams args, RequestOptions options = null) | |||||
{ | |||||
Preconditions.NotEqual(channelId, 0, nameof(channelId)); | |||||
Preconditions.NotEqual(messageId, 0, nameof(messageId)); | |||||
options = RequestOptions.CreateOrClone(options); | |||||
var ids = new BucketIds(channelId: channelId); | |||||
await SendJsonAsync("POST", () => $"channels/{channelId}/messages/{messageId}/suppress-embeds", args, ids, options: options).ConfigureAwait(false); | |||||
} | |||||
public async Task AddReactionAsync(ulong channelId, ulong messageId, string emoji, RequestOptions options = null) | public async Task AddReactionAsync(ulong channelId, ulong messageId, string emoji, RequestOptions options = null) | ||||
{ | { | ||||
Preconditions.NotEqual(channelId, 0, nameof(channelId)); | Preconditions.NotEqual(channelId, 0, nameof(channelId)); | ||||
@@ -936,7 +923,7 @@ namespace Discord.API | |||||
var ids = new BucketIds(guildId: guildId); | var ids = new BucketIds(guildId: guildId); | ||||
string reason = string.IsNullOrWhiteSpace(args.Reason) ? "" : $"&reason={Uri.EscapeDataString(args.Reason)}"; | string reason = string.IsNullOrWhiteSpace(args.Reason) ? "" : $"&reason={Uri.EscapeDataString(args.Reason)}"; | ||||
await SendAsync("PUT", () => $"guilds/{guildId}/bans/{userId}?delete-message-days={args.DeleteMessageDays}{reason}", ids, options: options).ConfigureAwait(false); | |||||
await SendAsync("PUT", () => $"guilds/{guildId}/bans/{userId}?delete_message_days={args.DeleteMessageDays}{reason}", ids, options: options).ConfigureAwait(false); | |||||
} | } | ||||
/// <exception cref="ArgumentException"><paramref name="guildId"/> and <paramref name="userId"/> must not be equal to zero.</exception> | /// <exception cref="ArgumentException"><paramref name="guildId"/> and <paramref name="userId"/> must not be equal to zero.</exception> | ||||
public async Task RemoveGuildBanAsync(ulong guildId, ulong userId, RequestOptions options = null) | public async Task RemoveGuildBanAsync(ulong guildId, ulong userId, RequestOptions options = null) | ||||
@@ -949,32 +936,6 @@ namespace Discord.API | |||||
await SendAsync("DELETE", () => $"guilds/{guildId}/bans/{userId}", ids, options: options).ConfigureAwait(false); | await SendAsync("DELETE", () => $"guilds/{guildId}/bans/{userId}", ids, options: options).ConfigureAwait(false); | ||||
} | } | ||||
//Guild Embeds | |||||
/// <exception cref="ArgumentException"><paramref name="guildId"/> must not be equal to zero.</exception> | |||||
public async Task<GuildEmbed> GetGuildEmbedAsync(ulong guildId, RequestOptions options = null) | |||||
{ | |||||
Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||||
options = RequestOptions.CreateOrClone(options); | |||||
try | |||||
{ | |||||
var ids = new BucketIds(guildId: guildId); | |||||
return await SendAsync<GuildEmbed>("GET", () => $"guilds/{guildId}/embed", ids, options: options).ConfigureAwait(false); | |||||
} | |||||
catch (HttpException ex) when (ex.HttpCode == HttpStatusCode.NotFound) { return null; } | |||||
} | |||||
/// <exception cref="ArgumentException"><paramref name="guildId"/> must not be equal to zero.</exception> | |||||
/// <exception cref="ArgumentNullException"><paramref name="args"/> must not be <see langword="null"/>.</exception> | |||||
public async Task<GuildEmbed> ModifyGuildEmbedAsync(ulong guildId, Rest.ModifyGuildEmbedParams args, RequestOptions options = null) | |||||
{ | |||||
Preconditions.NotNull(args, nameof(args)); | |||||
Preconditions.NotEqual(guildId, 0, nameof(guildId)); | |||||
options = RequestOptions.CreateOrClone(options); | |||||
var ids = new BucketIds(guildId: guildId); | |||||
return await SendJsonAsync<GuildEmbed>("PATCH", () => $"guilds/{guildId}/embed", args, ids, options: options).ConfigureAwait(false); | |||||
} | |||||
//Guild Widget | //Guild Widget | ||||
/// <exception cref="ArgumentException"><paramref name="guildId"/> must not be equal to zero.</exception> | /// <exception cref="ArgumentException"><paramref name="guildId"/> must not be equal to zero.</exception> | ||||
public async Task<GuildWidget> GetGuildWidgetAsync(ulong guildId, RequestOptions options = null) | public async Task<GuildWidget> GetGuildWidgetAsync(ulong guildId, RequestOptions options = null) | ||||
@@ -29,10 +29,7 @@ namespace Discord.Rest | |||||
internal DiscordRestClient(DiscordRestConfig config, API.DiscordRestApiClient api) : base(config, api) { } | internal DiscordRestClient(DiscordRestConfig config, API.DiscordRestApiClient api) : base(config, api) { } | ||||
private static API.DiscordRestApiClient CreateApiClient(DiscordRestConfig config) | private static API.DiscordRestApiClient CreateApiClient(DiscordRestConfig config) | ||||
=> new API.DiscordRestApiClient(config.RestClientProvider, | |||||
DiscordRestConfig.UserAgent, | |||||
rateLimitPrecision: config.RateLimitPrecision, | |||||
useSystemClock: config.UseSystemClock); | |||||
=> new API.DiscordRestApiClient(config.RestClientProvider, DiscordRestConfig.UserAgent, useSystemClock: config.UseSystemClock); | |||||
internal override void Dispose(bool disposing) | internal override void Dispose(bool disposing) | ||||
{ | { | ||||
@@ -80,9 +77,6 @@ namespace Discord.Rest | |||||
=> ClientHelper.GetGuildAsync(this, id, false, options); | => ClientHelper.GetGuildAsync(this, id, false, options); | ||||
public Task<RestGuild> GetGuildAsync(ulong id, bool withCounts, RequestOptions options = null) | public Task<RestGuild> GetGuildAsync(ulong id, bool withCounts, RequestOptions options = null) | ||||
=> ClientHelper.GetGuildAsync(this, id, withCounts, options); | => ClientHelper.GetGuildAsync(this, id, withCounts, options); | ||||
[Obsolete("This endpoint is deprecated, use GetGuildWidgetAsync instead.")] | |||||
public Task<RestGuildEmbed?> GetGuildEmbedAsync(ulong id, RequestOptions options = null) | |||||
=> ClientHelper.GetGuildEmbedAsync(this, id, options); | |||||
public Task<RestGuildWidget?> GetGuildWidgetAsync(ulong id, RequestOptions options = null) | public Task<RestGuildWidget?> GetGuildWidgetAsync(ulong id, RequestOptions options = null) | ||||
=> ClientHelper.GetGuildWidgetAsync(this, id, options); | => ClientHelper.GetGuildWidgetAsync(this, id, options); | ||||
public IAsyncEnumerable<IReadOnlyCollection<RestUserGuild>> GetGuildSummariesAsync(RequestOptions options = null) | public IAsyncEnumerable<IReadOnlyCollection<RestUserGuild>> GetGuildSummariesAsync(RequestOptions options = null) | ||||
@@ -33,8 +33,8 @@ namespace Discord.Rest | |||||
{ | { | ||||
TargetId = overwrite.TargetId, | TargetId = overwrite.TargetId, | ||||
TargetType = overwrite.TargetType, | TargetType = overwrite.TargetType, | ||||
Allow = overwrite.Permissions.AllowValue, | |||||
Deny = overwrite.Permissions.DenyValue | |||||
Allow = overwrite.Permissions.AllowValue.ToString(), | |||||
Deny = overwrite.Permissions.DenyValue.ToString() | |||||
}).ToArray() | }).ToArray() | ||||
: Optional.Create<API.Overwrite[]>(), | : Optional.Create<API.Overwrite[]>(), | ||||
}; | }; | ||||
@@ -59,8 +59,8 @@ namespace Discord.Rest | |||||
{ | { | ||||
TargetId = overwrite.TargetId, | TargetId = overwrite.TargetId, | ||||
TargetType = overwrite.TargetType, | TargetType = overwrite.TargetType, | ||||
Allow = overwrite.Permissions.AllowValue, | |||||
Deny = overwrite.Permissions.DenyValue | |||||
Allow = overwrite.Permissions.AllowValue.ToString(), | |||||
Deny = overwrite.Permissions.DenyValue.ToString() | |||||
}).ToArray() | }).ToArray() | ||||
: Optional.Create<API.Overwrite[]>(), | : Optional.Create<API.Overwrite[]>(), | ||||
}; | }; | ||||
@@ -84,8 +84,8 @@ namespace Discord.Rest | |||||
{ | { | ||||
TargetId = overwrite.TargetId, | TargetId = overwrite.TargetId, | ||||
TargetType = overwrite.TargetType, | TargetType = overwrite.TargetType, | ||||
Allow = overwrite.Permissions.AllowValue, | |||||
Deny = overwrite.Permissions.DenyValue | |||||
Allow = overwrite.Permissions.AllowValue.ToString(), | |||||
Deny = overwrite.Permissions.DenyValue.ToString() | |||||
}).ToArray() | }).ToArray() | ||||
: Optional.Create<API.Overwrite[]>(), | : Optional.Create<API.Overwrite[]>(), | ||||
}; | }; | ||||
@@ -328,13 +328,13 @@ namespace Discord.Rest | |||||
public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, | public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, | ||||
IUser user, OverwritePermissions perms, RequestOptions options) | IUser user, OverwritePermissions perms, RequestOptions options) | ||||
{ | { | ||||
var args = new ModifyChannelPermissionsParams("member", perms.AllowValue, perms.DenyValue); | |||||
var args = new ModifyChannelPermissionsParams((int)PermissionTarget.User, perms.AllowValue.ToString(), perms.DenyValue.ToString()); | |||||
await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, user.Id, args, options).ConfigureAwait(false); | await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, user.Id, args, options).ConfigureAwait(false); | ||||
} | } | ||||
public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, | public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, | ||||
IRole role, OverwritePermissions perms, RequestOptions options) | IRole role, OverwritePermissions perms, RequestOptions options) | ||||
{ | { | ||||
var args = new ModifyChannelPermissionsParams("role", perms.AllowValue, perms.DenyValue); | |||||
var args = new ModifyChannelPermissionsParams((int)PermissionTarget.Role, perms.AllowValue.ToString(), perms.DenyValue.ToString()); | |||||
await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, role.Id, args, options).ConfigureAwait(false); | await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, role.Id, args, options).ConfigureAwait(false); | ||||
} | } | ||||
public static async Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, | public static async Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client, | ||||
@@ -450,8 +450,8 @@ namespace Discord.Rest | |||||
{ | { | ||||
TargetId = overwrite.TargetId, | TargetId = overwrite.TargetId, | ||||
TargetType = overwrite.TargetType, | TargetType = overwrite.TargetType, | ||||
Allow = overwrite.Permissions.AllowValue, | |||||
Deny = overwrite.Permissions.DenyValue | |||||
Allow = overwrite.Permissions.AllowValue.ToString(), | |||||
Deny = overwrite.Permissions.DenyValue.ToString() | |||||
}).ToArray() | }).ToArray() | ||||
}; | }; | ||||
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); | await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); | ||||
@@ -4,7 +4,6 @@ using System.Collections.Generic; | |||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using EmbedModel = Discord.API.GuildEmbed; | |||||
using WidgetModel = Discord.API.GuildWidget; | using WidgetModel = Discord.API.GuildWidget; | ||||
using Model = Discord.API.Guild; | using Model = Discord.API.Guild; | ||||
using RoleModel = Discord.API.Role; | using RoleModel = Discord.API.Role; | ||||
@@ -81,26 +80,6 @@ namespace Discord.Rest | |||||
return await client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options).ConfigureAwait(false); | return await client.ApiClient.ModifyGuildAsync(guild.Id, apiArgs, options).ConfigureAwait(false); | ||||
} | } | ||||
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> | /// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> | ||||
public static async Task<EmbedModel> ModifyEmbedAsync(IGuild guild, BaseDiscordClient client, | |||||
Action<GuildEmbedProperties> func, RequestOptions options) | |||||
{ | |||||
if (func == null) throw new ArgumentNullException(nameof(func)); | |||||
var args = new GuildEmbedProperties(); | |||||
func(args); | |||||
var apiArgs = new API.Rest.ModifyGuildEmbedParams | |||||
{ | |||||
Enabled = args.Enabled | |||||
}; | |||||
if (args.Channel.IsSpecified) | |||||
apiArgs.ChannelId = args.Channel.Value?.Id; | |||||
else if (args.ChannelId.IsSpecified) | |||||
apiArgs.ChannelId = args.ChannelId.Value; | |||||
return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, apiArgs, options).ConfigureAwait(false); | |||||
} | |||||
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <c>null</c>.</exception> | |||||
public static async Task<WidgetModel> ModifyWidgetAsync(IGuild guild, BaseDiscordClient client, | public static async Task<WidgetModel> ModifyWidgetAsync(IGuild guild, BaseDiscordClient client, | ||||
Action<GuildWidgetProperties> func, RequestOptions options) | Action<GuildWidgetProperties> func, RequestOptions options) | ||||
{ | { | ||||
@@ -205,8 +184,8 @@ namespace Discord.Rest | |||||
{ | { | ||||
TargetId = overwrite.TargetId, | TargetId = overwrite.TargetId, | ||||
TargetType = overwrite.TargetType, | TargetType = overwrite.TargetType, | ||||
Allow = overwrite.Permissions.AllowValue, | |||||
Deny = overwrite.Permissions.DenyValue | |||||
Allow = overwrite.Permissions.AllowValue.ToString(), | |||||
Deny = overwrite.Permissions.DenyValue.ToString() | |||||
}).ToArray() | }).ToArray() | ||||
: Optional.Create<API.Overwrite[]>(), | : Optional.Create<API.Overwrite[]>(), | ||||
}; | }; | ||||
@@ -233,8 +212,8 @@ namespace Discord.Rest | |||||
{ | { | ||||
TargetId = overwrite.TargetId, | TargetId = overwrite.TargetId, | ||||
TargetType = overwrite.TargetType, | TargetType = overwrite.TargetType, | ||||
Allow = overwrite.Permissions.AllowValue, | |||||
Deny = overwrite.Permissions.DenyValue | |||||
Allow = overwrite.Permissions.AllowValue.ToString(), | |||||
Deny = overwrite.Permissions.DenyValue.ToString() | |||||
}).ToArray() | }).ToArray() | ||||
: Optional.Create<API.Overwrite[]>(), | : Optional.Create<API.Overwrite[]>(), | ||||
}; | }; | ||||
@@ -258,8 +237,8 @@ namespace Discord.Rest | |||||
{ | { | ||||
TargetId = overwrite.TargetId, | TargetId = overwrite.TargetId, | ||||
TargetType = overwrite.TargetType, | TargetType = overwrite.TargetType, | ||||
Allow = overwrite.Permissions.AllowValue, | |||||
Deny = overwrite.Permissions.DenyValue | |||||
Allow = overwrite.Permissions.AllowValue.ToString(), | |||||
Deny = overwrite.Permissions.DenyValue.ToString() | |||||
}).ToArray() | }).ToArray() | ||||
: Optional.Create<API.Overwrite[]>(), | : Optional.Create<API.Overwrite[]>(), | ||||
}; | }; | ||||
@@ -320,7 +299,7 @@ namespace Discord.Rest | |||||
Hoist = isHoisted, | Hoist = isHoisted, | ||||
Mentionable = isMentionable, | Mentionable = isMentionable, | ||||
Name = name, | Name = name, | ||||
Permissions = permissions?.RawValue ?? Optional.Create<ulong>() | |||||
Permissions = permissions?.RawValue.ToString() ?? Optional.Create<string>() | |||||
}; | }; | ||||
var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, createGuildRoleParams, options).ConfigureAwait(false); | var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, createGuildRoleParams, options).ConfigureAwait(false); | ||||
@@ -6,7 +6,6 @@ using System.Diagnostics; | |||||
using System.Globalization; | using System.Globalization; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using EmbedModel = Discord.API.GuildEmbed; | |||||
using WidgetModel = Discord.API.GuildWidget; | using WidgetModel = Discord.API.GuildWidget; | ||||
using Model = Discord.API.Guild; | using Model = Discord.API.Guild; | ||||
@@ -27,8 +26,6 @@ namespace Discord.Rest | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public int AFKTimeout { get; private set; } | public int AFKTimeout { get; private set; } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public bool IsEmbeddable { get; private set; } | |||||
/// <inheritdoc /> | |||||
public bool IsWidgetEnabled { get; private set; } | public bool IsWidgetEnabled { get; private set; } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public VerificationLevel VerificationLevel { get; private set; } | public VerificationLevel VerificationLevel { get; private set; } | ||||
@@ -42,8 +39,6 @@ namespace Discord.Rest | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public ulong? AFKChannelId { get; private set; } | public ulong? AFKChannelId { get; private set; } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public ulong? EmbedChannelId { get; private set; } | |||||
/// <inheritdoc /> | |||||
public ulong? WidgetChannelId { get; private set; } | public ulong? WidgetChannelId { get; private set; } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public ulong? SystemChannelId { get; private set; } | public ulong? SystemChannelId { get; private set; } | ||||
@@ -133,16 +128,12 @@ namespace Discord.Rest | |||||
internal void Update(Model model) | internal void Update(Model model) | ||||
{ | { | ||||
AFKChannelId = model.AFKChannelId; | AFKChannelId = model.AFKChannelId; | ||||
if (model.EmbedChannelId.IsSpecified) | |||||
EmbedChannelId = model.EmbedChannelId.Value; | |||||
if (model.WidgetChannelId.IsSpecified) | if (model.WidgetChannelId.IsSpecified) | ||||
WidgetChannelId = model.WidgetChannelId.Value; | WidgetChannelId = model.WidgetChannelId.Value; | ||||
SystemChannelId = model.SystemChannelId; | SystemChannelId = model.SystemChannelId; | ||||
RulesChannelId = model.RulesChannelId; | RulesChannelId = model.RulesChannelId; | ||||
PublicUpdatesChannelId = model.PublicUpdatesChannelId; | PublicUpdatesChannelId = model.PublicUpdatesChannelId; | ||||
AFKTimeout = model.AFKTimeout; | AFKTimeout = model.AFKTimeout; | ||||
if (model.EmbedEnabled.IsSpecified) | |||||
IsEmbeddable = model.EmbedEnabled.Value; | |||||
if (model.WidgetEnabled.IsSpecified) | if (model.WidgetEnabled.IsSpecified) | ||||
IsWidgetEnabled = model.WidgetEnabled.Value; | IsWidgetEnabled = model.WidgetEnabled.Value; | ||||
IconId = model.Icon; | IconId = model.Icon; | ||||
@@ -200,11 +191,6 @@ namespace Discord.Rest | |||||
Available = true; | Available = true; | ||||
} | } | ||||
internal void Update(EmbedModel model) | |||||
{ | |||||
EmbedChannelId = model.ChannelId; | |||||
IsEmbeddable = model.Enabled; | |||||
} | |||||
internal void Update(WidgetModel model) | internal void Update(WidgetModel model) | ||||
{ | { | ||||
WidgetChannelId = model.ChannelId; | WidgetChannelId = model.ChannelId; | ||||
@@ -243,15 +229,6 @@ namespace Discord.Rest | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception> | /// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception> | ||||
[Obsolete("This endpoint is deprecated, use ModifyWidgetAsync instead.")] | |||||
public async Task ModifyEmbedAsync(Action<GuildEmbedProperties> func, RequestOptions options = null) | |||||
{ | |||||
var model = await GuildHelper.ModifyEmbedAsync(this, Discord, func, options).ConfigureAwait(false); | |||||
Update(model); | |||||
} | |||||
/// <inheritdoc /> | |||||
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception> | |||||
public async Task ModifyWidgetAsync(Action<GuildWidgetProperties> func, RequestOptions options = null) | public async Task ModifyWidgetAsync(Action<GuildWidgetProperties> func, RequestOptions options = null) | ||||
{ | { | ||||
var model = await GuildHelper.ModifyWidgetAsync(this, Discord, func, options).ConfigureAwait(false); | var model = await GuildHelper.ModifyWidgetAsync(this, Discord, func, options).ConfigureAwait(false); | ||||
@@ -464,23 +441,6 @@ namespace Discord.Rest | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// Gets the embed channel (i.e. the channel set in the guild's widget settings) in this guild. | |||||
/// </summary> | |||||
/// <param name="options">The options to be used when sending the request.</param> | |||||
/// <returns> | |||||
/// A task that represents the asynchronous get operation. The task result contains the embed channel set | |||||
/// within the server's widget settings; <see langword="null"/> if none is set. | |||||
/// </returns> | |||||
[Obsolete("This endpoint is deprecated, use GetWidgetChannelAsync instead.")] | |||||
public async Task<RestGuildChannel> GetEmbedChannelAsync(RequestOptions options = null) | |||||
{ | |||||
var embedId = EmbedChannelId; | |||||
if (embedId.HasValue) | |||||
return await GuildHelper.GetChannelAsync(this, Discord, embedId.Value, options).ConfigureAwait(false); | |||||
return null; | |||||
} | |||||
/// <summary> | |||||
/// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild. | /// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild. | ||||
/// </summary> | /// </summary> | ||||
/// <param name="options">The options to be used when sending the request.</param> | /// <param name="options">The options to be used when sending the request.</param> | ||||
@@ -937,15 +897,6 @@ namespace Discord.Rest | |||||
return null; | return null; | ||||
} | } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
[Obsolete("This endpoint is deprecated, use GetWidgetChannelAsync instead.")] | |||||
async Task<IGuildChannel> IGuild.GetEmbedChannelAsync(CacheMode mode, RequestOptions options) | |||||
{ | |||||
if (mode == CacheMode.AllowDownload) | |||||
return await GetEmbedChannelAsync(options).ConfigureAwait(false); | |||||
else | |||||
return null; | |||||
} | |||||
/// <inheritdoc /> | |||||
async Task<IGuildChannel> IGuild.GetWidgetChannelAsync(CacheMode mode, RequestOptions options) | async Task<IGuildChannel> IGuild.GetWidgetChannelAsync(CacheMode mode, RequestOptions options) | ||||
{ | { | ||||
if (mode == CacheMode.AllowDownload) | if (mode == CacheMode.AllowDownload) | ||||
@@ -1,25 +0,0 @@ | |||||
using System.Diagnostics; | |||||
using Model = Discord.API.GuildEmbed; | |||||
namespace Discord.Rest | |||||
{ | |||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")] | |||||
public struct RestGuildEmbed | |||||
{ | |||||
public bool IsEnabled { get; private set; } | |||||
public ulong? ChannelId { get; private set; } | |||||
internal RestGuildEmbed(bool isEnabled, ulong? channelId) | |||||
{ | |||||
ChannelId = channelId; | |||||
IsEnabled = isEnabled; | |||||
} | |||||
internal static RestGuildEmbed Create(Model model) | |||||
{ | |||||
return new RestGuildEmbed(model.Enabled, model.ChannelId); | |||||
} | |||||
public override string ToString() => ChannelId?.ToString() ?? "Unknown"; | |||||
private string DebuggerDisplay => $"{ChannelId} ({(IsEnabled ? "Enabled" : "Disabled")})"; | |||||
} | |||||
} |
@@ -122,15 +122,6 @@ namespace Discord.Rest | |||||
await client.ApiClient.DeleteMessageAsync(channelId, msgId, options).ConfigureAwait(false); | await client.ApiClient.DeleteMessageAsync(channelId, msgId, options).ConfigureAwait(false); | ||||
} | } | ||||
public static async Task SuppressEmbedsAsync(IMessage msg, BaseDiscordClient client, bool suppress, RequestOptions options) | |||||
{ | |||||
var apiArgs = new API.Rest.SuppressEmbedParams | |||||
{ | |||||
Suppressed = suppress | |||||
}; | |||||
await client.ApiClient.SuppressEmbedAsync(msg.Channel.Id, msg.Id, apiArgs, options).ConfigureAwait(false); | |||||
} | |||||
public static async Task AddReactionAsync(ulong channelId, ulong messageId, IEmote emote, BaseDiscordClient client, RequestOptions options) | public static async Task AddReactionAsync(ulong channelId, ulong messageId, IEmote emote, BaseDiscordClient client, RequestOptions options) | ||||
{ | { | ||||
await client.ApiClient.AddReactionAsync(channelId, messageId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); | await client.ApiClient.AddReactionAsync(channelId, messageId, emote is Emote e ? $"{e.Name}:{e.Id}" : UrlEncode(emote.Name), options).ConfigureAwait(false); | ||||
@@ -164,9 +164,6 @@ namespace Discord.Rest | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public Task UnpinAsync(RequestOptions options = null) | public Task UnpinAsync(RequestOptions options = null) | ||||
=> MessageHelper.UnpinAsync(this, Discord, options); | => 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, | 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) | TagHandling roleHandling = TagHandling.Name, TagHandling everyoneHandling = TagHandling.Ignore, TagHandling emojiHandling = TagHandling.Name) | ||||
@@ -1,4 +1,4 @@ | |||||
using System; | |||||
using System; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
using Model = Discord.API.Role; | using Model = Discord.API.Role; | ||||
using BulkParams = Discord.API.Rest.ModifyGuildRolesParams; | using BulkParams = Discord.API.Rest.ModifyGuildRolesParams; | ||||
@@ -24,7 +24,7 @@ namespace Discord.Rest | |||||
Hoist = args.Hoist, | Hoist = args.Hoist, | ||||
Mentionable = args.Mentionable, | Mentionable = args.Mentionable, | ||||
Name = args.Name, | Name = args.Name, | ||||
Permissions = args.Permissions.IsSpecified ? args.Permissions.Value.RawValue : Optional.Create<ulong>() | |||||
Permissions = args.Permissions.IsSpecified ? args.Permissions.Value.RawValue.ToString() : Optional.Create<string>() | |||||
}; | }; | ||||
var model = await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, apiArgs, options).ConfigureAwait(false); | var model = await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, apiArgs, options).ConfigureAwait(false); | ||||
@@ -73,8 +73,6 @@ namespace Discord.Net.Converters | |||||
} | } | ||||
//Enums | //Enums | ||||
if (type == typeof(PermissionTarget)) | |||||
return PermissionTargetConverter.Instance; | |||||
if (type == typeof(UserStatus)) | if (type == typeof(UserStatus)) | ||||
return UserStatusConverter.Instance; | return UserStatusConverter.Instance; | ||||
if (type == typeof(EmbedType)) | if (type == typeof(EmbedType)) | ||||
@@ -1,44 +0,0 @@ | |||||
using Newtonsoft.Json; | |||||
using System; | |||||
namespace Discord.Net.Converters | |||||
{ | |||||
internal class PermissionTargetConverter : JsonConverter | |||||
{ | |||||
public static readonly PermissionTargetConverter Instance = new PermissionTargetConverter(); | |||||
public override bool CanConvert(Type objectType) => true; | |||||
public override bool CanRead => true; | |||||
public override bool CanWrite => true; | |||||
/// <exception cref="JsonSerializationException">Unknown permission target.</exception> | |||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | |||||
{ | |||||
switch ((string)reader.Value) | |||||
{ | |||||
case "member": | |||||
return PermissionTarget.User; | |||||
case "role": | |||||
return PermissionTarget.Role; | |||||
default: | |||||
throw new JsonSerializationException("Unknown permission target."); | |||||
} | |||||
} | |||||
/// <exception cref="JsonSerializationException">Invalid permission target.</exception> | |||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) | |||||
{ | |||||
switch ((PermissionTarget)value) | |||||
{ | |||||
case PermissionTarget.User: | |||||
writer.WriteValue("member"); | |||||
break; | |||||
case PermissionTarget.Role: | |||||
writer.WriteValue("role"); | |||||
break; | |||||
default: | |||||
throw new JsonSerializationException("Invalid permission target."); | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -17,8 +17,6 @@ namespace Discord.API.Gateway | |||||
public Optional<int[]> ShardingParams { get; set; } | public Optional<int[]> ShardingParams { get; set; } | ||||
[JsonProperty("presence")] | [JsonProperty("presence")] | ||||
public Optional<StatusUpdateParams> Presence { get; set; } | public Optional<StatusUpdateParams> Presence { get; set; } | ||||
[JsonProperty("guild_subscriptions")] | |||||
public Optional<bool> GuildSubscriptions { get; set; } | |||||
[JsonProperty("intents")] | [JsonProperty("intents")] | ||||
public Optional<int> Intents { get; set; } | public Optional<int> Intents { get; set; } | ||||
} | } | ||||
@@ -83,7 +83,6 @@ namespace Discord.WebSocket | |||||
: base(config, client) => BaseConfig = config; | : base(config, client) => BaseConfig = config; | ||||
private static DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config) | private static DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config) | ||||
=> new DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent, | => new DiscordSocketApiClient(config.RestClientProvider, config.WebSocketProvider, DiscordRestConfig.UserAgent, | ||||
rateLimitPrecision: config.RateLimitPrecision, | |||||
useSystemClock: config.UseSystemClock); | useSystemClock: config.UseSystemClock); | ||||
/// <summary> | /// <summary> | ||||
@@ -91,8 +91,7 @@ namespace Discord.WebSocket | |||||
} | } | ||||
} | } | ||||
private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config) | 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) | internal async Task AcquireIdentifyLockAsync(int shardId, CancellationToken token) | ||||
{ | { | ||||
@@ -40,9 +40,8 @@ namespace Discord.API | |||||
public DiscordSocketApiClient(RestClientProvider restClientProvider, WebSocketProvider webSocketProvider, string userAgent, | public DiscordSocketApiClient(RestClientProvider restClientProvider, WebSocketProvider webSocketProvider, string userAgent, | ||||
string url = null, RetryMode defaultRetryMode = RetryMode.AlwaysRetry, JsonSerializer serializer = null, | string url = null, RetryMode defaultRetryMode = RetryMode.AlwaysRetry, JsonSerializer serializer = null, | ||||
RateLimitPrecision rateLimitPrecision = RateLimitPrecision.Second, | |||||
bool useSystemClock = true) | bool useSystemClock = true) | ||||
: base(restClientProvider, userAgent, defaultRetryMode, serializer, rateLimitPrecision, useSystemClock) | |||||
: base(restClientProvider, userAgent, defaultRetryMode, serializer, useSystemClock) | |||||
{ | { | ||||
_gatewayUrl = url; | _gatewayUrl = url; | ||||
if (url != null) | if (url != null) | ||||
@@ -216,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, 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); | options = RequestOptions.CreateOrClone(options); | ||||
var props = new Dictionary<string, string> | var props = new Dictionary<string, string> | ||||
@@ -234,10 +233,7 @@ namespace Discord.API | |||||
options.BucketId = GatewayBucket.Get(GatewayBucketType.Identify).Id; | 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) | if (presence.HasValue) | ||||
{ | { | ||||
@@ -43,8 +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; | |||||
private GatewayIntents? _gatewayIntents; | |||||
private GatewayIntents _gatewayIntents; | |||||
/// <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. | ||||
@@ -140,7 +139,6 @@ 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; | |||||
_gatewayIntents = config.GatewayIntents; | _gatewayIntents = config.GatewayIntents; | ||||
_stateLock = new SemaphoreSlim(1, 1); | _stateLock = new SemaphoreSlim(1, 1); | ||||
@@ -182,8 +180,7 @@ namespace Discord.WebSocket | |||||
_largeGuilds = new ConcurrentQueue<ulong>(); | _largeGuilds = new ConcurrentQueue<ulong>(); | ||||
} | } | ||||
private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config) | 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 /> | /// <inheritdoc /> | ||||
internal override void Dispose(bool disposing) | internal override void Dispose(bool disposing) | ||||
{ | { | ||||
@@ -243,7 +240,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, guildSubscriptions: _guildSubscriptions, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false); | |||||
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false); | |||||
} | } | ||||
} | } | ||||
finally | finally | ||||
@@ -335,7 +332,7 @@ namespace Discord.WebSocket | |||||
{ | { | ||||
var user = SocketGlobalUser.Create(this, state, model); | var user = SocketGlobalUser.Create(this, state, model); | ||||
user.GlobalUser.AddRef(); | user.GlobalUser.AddRef(); | ||||
user.Presence = new SocketPresence(UserStatus.Online, null, null, null); | |||||
user.Presence = new SocketPresence(UserStatus.Online, null, null); | |||||
return user; | return user; | ||||
}); | }); | ||||
} | } | ||||
@@ -469,7 +466,8 @@ namespace Discord.WebSocket | |||||
{ | { | ||||
if (CurrentUser == null) | if (CurrentUser == null) | ||||
return; | 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); | var presence = BuildCurrentStatus() ?? (UserStatus.Online, false, null, null); | ||||
@@ -564,7 +562,7 @@ namespace Discord.WebSocket | |||||
await _shardedClient.AcquireIdentifyLockAsync(ShardId, _connection.CancelToken).ConfigureAwait(false); | await _shardedClient.AcquireIdentifyLockAsync(ShardId, _connection.CancelToken).ConfigureAwait(false); | ||||
try | 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 | finally | ||||
{ | { | ||||
@@ -572,7 +570,7 @@ namespace Discord.WebSocket | |||||
} | } | ||||
} | } | ||||
else | 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; | break; | ||||
case GatewayOpCode.Reconnect: | case GatewayOpCode.Reconnect: | ||||
@@ -595,7 +593,8 @@ namespace Discord.WebSocket | |||||
var state = new ClientState(data.Guilds.Length, data.PrivateChannels.Length); | var state = new ClientState(data.Guilds.Length, data.PrivateChannels.Length); | ||||
var currentUser = SocketSelfUser.Create(this, state, data.User); | 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; | ApiClient.CurrentUserId = currentUser.Id; | ||||
int unavailableGuilds = 0; | int unavailableGuilds = 0; | ||||
for (int i = 0; i < data.Guilds.Length; i++) | for (int i = 0; i < data.Guilds.Length; i++) | ||||
@@ -128,12 +128,6 @@ namespace Discord.WebSocket | |||||
public bool? ExclusiveBulkDelete { get; set; } = null; | public bool? ExclusiveBulkDelete { get; set; } = null; | ||||
/// <summary> | /// <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. | /// Gets or sets the maximum identify concurrency. | ||||
/// </summary> | /// </summary> | ||||
/// <remarks> | /// <remarks> | ||||
@@ -172,14 +166,15 @@ namespace Discord.WebSocket | |||||
private int maxWaitForGuildAvailable = 10000; | private int maxWaitForGuildAvailable = 10000; | ||||
/// <summary> | /// <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> | /// </summary> | ||||
/// <remarks> | /// <remarks> | ||||
/// For more information, please see | /// For more information, please see | ||||
/// <see href="https://discord.com/developers/docs/topics/gateway#gateway-intents">GatewayIntents</see> | /// <see href="https://discord.com/developers/docs/topics/gateway#gateway-intents">GatewayIntents</see> | ||||
/// on the official Discord API documentation. | /// on the official Discord API documentation. | ||||
/// </remarks> | /// </remarks> | ||||
public GatewayIntents? GatewayIntents { get; set; } | |||||
public GatewayIntents GatewayIntents { get; set; } = GatewayIntents.AllUnprivileged; | |||||
/// <summary> | /// <summary> | ||||
/// Initializes a new instance of the <see cref="DiscordSocketConfig"/> class with the default configuration. | /// Initializes a new instance of the <see cref="DiscordSocketConfig"/> class with the default configuration. | ||||
@@ -46,8 +46,6 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public int AFKTimeout { get; private set; } | public int AFKTimeout { get; private set; } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public bool IsEmbeddable { get; private set; } | |||||
/// <inheritdoc /> | |||||
public bool IsWidgetEnabled { get; private set; } | public bool IsWidgetEnabled { get; private set; } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public VerificationLevel VerificationLevel { get; private set; } | public VerificationLevel VerificationLevel { get; private set; } | ||||
@@ -84,7 +82,6 @@ namespace Discord.WebSocket | |||||
public ulong? ApplicationId { get; internal set; } | public ulong? ApplicationId { get; internal set; } | ||||
internal ulong? AFKChannelId { get; private set; } | internal ulong? AFKChannelId { get; private set; } | ||||
internal ulong? EmbedChannelId { get; private set; } | |||||
internal ulong? WidgetChannelId { get; private set; } | internal ulong? WidgetChannelId { get; private set; } | ||||
internal ulong? SystemChannelId { get; private set; } | internal ulong? SystemChannelId { get; private set; } | ||||
internal ulong? RulesChannelId { get; private set; } | internal ulong? RulesChannelId { get; private set; } | ||||
@@ -198,21 +195,6 @@ namespace Discord.WebSocket | |||||
} | } | ||||
} | } | ||||
/// <summary> | /// <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. | /// Gets the widget channel (i.e. the channel set in the guild's widget settings) in this guild. | ||||
/// </summary> | /// </summary> | ||||
/// <returns> | /// <returns> | ||||
@@ -440,16 +422,12 @@ namespace Discord.WebSocket | |||||
internal void Update(ClientState state, Model model) | internal void Update(ClientState state, Model model) | ||||
{ | { | ||||
AFKChannelId = model.AFKChannelId; | AFKChannelId = model.AFKChannelId; | ||||
if (model.EmbedChannelId.IsSpecified) | |||||
EmbedChannelId = model.EmbedChannelId.Value; | |||||
if (model.WidgetChannelId.IsSpecified) | if (model.WidgetChannelId.IsSpecified) | ||||
WidgetChannelId = model.WidgetChannelId.Value; | WidgetChannelId = model.WidgetChannelId.Value; | ||||
SystemChannelId = model.SystemChannelId; | SystemChannelId = model.SystemChannelId; | ||||
RulesChannelId = model.RulesChannelId; | RulesChannelId = model.RulesChannelId; | ||||
PublicUpdatesChannelId = model.PublicUpdatesChannelId; | PublicUpdatesChannelId = model.PublicUpdatesChannelId; | ||||
AFKTimeout = model.AFKTimeout; | AFKTimeout = model.AFKTimeout; | ||||
if (model.EmbedEnabled.IsSpecified) | |||||
IsEmbeddable = model.EmbedEnabled.Value; | |||||
if (model.WidgetEnabled.IsSpecified) | if (model.WidgetEnabled.IsSpecified) | ||||
IsWidgetEnabled = model.WidgetEnabled.Value; | IsWidgetEnabled = model.WidgetEnabled.Value; | ||||
IconId = model.Icon; | IconId = model.Icon; | ||||
@@ -548,11 +526,6 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
/// <exception cref="ArgumentNullException"><paramref name="func"/> is <see langword="null"/>.</exception> | /// <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) | public Task ModifyWidgetAsync(Action<GuildWidgetProperties> func, RequestOptions options = null) | ||||
=> GuildHelper.ModifyWidgetAsync(this, Discord, func, options); | => GuildHelper.ModifyWidgetAsync(this, Discord, func, options); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
@@ -1234,8 +1207,6 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
ulong IGuild.DefaultChannelId => DefaultChannel?.Id ?? 0; | ulong IGuild.DefaultChannelId => DefaultChannel?.Id ?? 0; | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
ulong? IGuild.EmbedChannelId => EmbedChannelId; | |||||
/// <inheritdoc /> | |||||
ulong? IGuild.WidgetChannelId => WidgetChannelId; | ulong? IGuild.WidgetChannelId => WidgetChannelId; | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
ulong? IGuild.SystemChannelId => SystemChannelId; | ulong? IGuild.SystemChannelId => SystemChannelId; | ||||
@@ -1290,10 +1261,6 @@ namespace Discord.WebSocket | |||||
Task<ITextChannel> IGuild.GetDefaultChannelAsync(CacheMode mode, RequestOptions options) | Task<ITextChannel> IGuild.GetDefaultChannelAsync(CacheMode mode, RequestOptions options) | ||||
=> Task.FromResult<ITextChannel>(DefaultChannel); | => Task.FromResult<ITextChannel>(DefaultChannel); | ||||
/// <inheritdoc /> | /// <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<IGuildChannel> IGuild.GetWidgetChannelAsync(CacheMode mode, RequestOptions options) | ||||
=> Task.FromResult<IGuildChannel>(WidgetChannel); | => Task.FromResult<IGuildChannel>(WidgetChannel); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
@@ -189,9 +189,6 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public Task UnpinAsync(RequestOptions options = null) | public Task UnpinAsync(RequestOptions options = null) | ||||
=> MessageHelper.UnpinAsync(this, Discord, options); | => 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, | 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) | 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.Generic; | ||||
using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
using System.Diagnostics; | using System.Diagnostics; | ||||
using System.Linq; | |||||
using Model = Discord.API.Presence; | using Model = Discord.API.Presence; | ||||
namespace Discord.WebSocket | namespace Discord.WebSocket | ||||
@@ -15,15 +16,12 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public UserStatus Status { get; } | public UserStatus Status { get; } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public IActivity Activity { get; } | |||||
/// <inheritdoc /> | |||||
public IImmutableSet<ClientType> ActiveClients { get; } | public IImmutableSet<ClientType> ActiveClients { get; } | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public IImmutableList<IActivity> Activities { get; } | 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; | Status = status; | ||||
Activity = activity; | |||||
ActiveClients = activeClients ?? ImmutableHashSet<ClientType>.Empty; | ActiveClients = activeClients ?? ImmutableHashSet<ClientType>.Empty; | ||||
Activities = activities ?? ImmutableList<IActivity>.Empty; | Activities = activities ?? ImmutableList<IActivity>.Empty; | ||||
} | } | ||||
@@ -31,7 +29,7 @@ namespace Discord.WebSocket | |||||
{ | { | ||||
var clients = ConvertClientTypesDict(model.ClientStatus.GetValueOrDefault()); | var clients = ConvertClientTypesDict(model.ClientStatus.GetValueOrDefault()); | ||||
var activities = ConvertActivitiesList(model.Activities); | var activities = ConvertActivitiesList(model.Activities); | ||||
return new SocketPresence(model.Status, model.Game?.ToEntity(), clients, activities); | |||||
return new SocketPresence(model.Status, clients, activities); | |||||
} | } | ||||
/// <summary> | /// <summary> | ||||
/// Creates a new <see cref="IReadOnlyCollection{T}"/> containing all of the client types | /// 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" />. | /// A string that resolves to <see cref="Discord.WebSocket.SocketPresence.Status" />. | ||||
/// </returns> | /// </returns> | ||||
public override string ToString() => Status.ToString(); | 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; | internal SocketPresence Clone() => this; | ||||
} | } | ||||
@@ -25,7 +25,7 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override bool IsWebhook => false; | public override bool IsWebhook => false; | ||||
/// <inheritdoc /> | /// <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 /> | /// <inheritdoc /> | ||||
/// <exception cref="NotSupportedException">This field is not supported for an unknown user.</exception> | /// <exception cref="NotSupportedException">This field is not supported for an unknown user.</exception> | ||||
internal override SocketGlobalUser GlobalUser => | internal override SocketGlobalUser GlobalUser => | ||||
@@ -38,8 +38,6 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public string Mention => MentionUtils.MentionUser(Id); | public string Mention => MentionUtils.MentionUser(Id); | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public IActivity Activity => Presence.Activity; | |||||
/// <inheritdoc /> | |||||
public UserStatus Status => Presence.Status; | public UserStatus Status => Presence.Status; | ||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public IImmutableSet<ClientType> ActiveClients => Presence.ActiveClients ?? ImmutableHashSet<ClientType>.Empty; | public IImmutableSet<ClientType> ActiveClients => Presence.ActiveClients ?? ImmutableHashSet<ClientType>.Empty; | ||||
@@ -30,7 +30,7 @@ namespace Discord.WebSocket | |||||
/// <inheritdoc /> | /// <inheritdoc /> | ||||
public override bool IsWebhook => true; | public override bool IsWebhook => true; | ||||
/// <inheritdoc /> | /// <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 => | internal override SocketGlobalUser GlobalUser => | ||||
throw new NotSupportedException(); | throw new NotSupportedException(); | ||||