diff --git a/src/Discord.Net/API/Common/Message.cs b/src/Discord.Net/API/Common/Message.cs index 3e6d69af9..be5305114 100644 --- a/src/Discord.Net/API/Common/Message.cs +++ b/src/Discord.Net/API/Common/Message.cs @@ -20,12 +20,14 @@ namespace Discord.API [JsonProperty("tts")] public Optional IsTextToSpeech { get; set; } [JsonProperty("mention_everyone")] - public Optional IsMentioningEveryone { get; set; } + public Optional MentionEveryone { get; set; } [JsonProperty("mentions")] public Optional Mentions { get; set; } [JsonProperty("attachments")] public Optional Attachments { get; set; } [JsonProperty("embeds")] public Optional Embeds { get; set; } + [JsonProperty("pinned")] + public Optional Pinned { get; set; } } } diff --git a/src/Discord.Net/API/DiscordAPIClient.cs b/src/Discord.Net/API/DiscordAPIClient.cs index 41e59e12f..c138e455f 100644 --- a/src/Discord.Net/API/DiscordAPIClient.cs +++ b/src/Discord.Net/API/DiscordAPIClient.cs @@ -494,15 +494,37 @@ namespace Discord.API //Channel Permissions public async Task ModifyChannelPermissionsAsync(ulong channelId, ulong targetId, ModifyChannelPermissionsParams args, RequestOptions options = null) { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(targetId, 0, nameof(targetId)); Preconditions.NotNull(args, nameof(args)); await SendAsync("PUT", $"channels/{channelId}/permissions/{targetId}", args, options: options).ConfigureAwait(false); } public async Task DeleteChannelPermissionAsync(ulong channelId, ulong targetId, RequestOptions options = null) { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(targetId, 0, nameof(targetId)); + await SendAsync("DELETE", $"channels/{channelId}/permissions/{targetId}", options: options).ConfigureAwait(false); } + //Channel Pins + public async Task AddPinAsync(ulong channelId, ulong messageId, RequestOptions options = null) + { + Preconditions.GreaterThan(channelId, 0, nameof(channelId)); + Preconditions.GreaterThan(messageId, 0, nameof(messageId)); + + await SendAsync("PUT", $"channels/{channelId}/pins/{messageId}", options: options).ConfigureAwait(false); + + } + public async Task RemovePinAsync(ulong channelId, ulong messageId, RequestOptions options = null) + { + Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(messageId, 0, nameof(messageId)); + + await SendAsync("DELETE", $"channels/{channelId}/pins/{messageId}", options: options).ConfigureAwait(false); + } + //Guilds public async Task GetGuildAsync(ulong guildId, RequestOptions options = null) { diff --git a/src/Discord.Net/Entities/Messages/IMessage.cs b/src/Discord.Net/Entities/Messages/IMessage.cs index 0faf0837e..3a91336d2 100644 --- a/src/Discord.Net/Entities/Messages/IMessage.cs +++ b/src/Discord.Net/Entities/Messages/IMessage.cs @@ -11,6 +11,8 @@ namespace Discord DateTimeOffset? EditedTimestamp { get; } /// Returns true if this message was sent as a text-to-speech message. bool IsTTS { get; } + /// Returns true if this message was added to its channel's pinned messages. + bool IsPinned { get; } /// Returns the original, unprocessed text for this message. string RawText { get; } /// Returns the text for this message after mention processing. @@ -35,5 +37,9 @@ namespace Discord /// Modifies this message. Task ModifyAsync(Action func); + /// Adds this message to its channel's pinned messages. + Task PinAsync(); + /// Removes this message from its channel's pinned messages. + Task UnpinAsync(); } } \ No newline at end of file diff --git a/src/Discord.Net/Entities/Messages/Message.cs b/src/Discord.Net/Entities/Messages/Message.cs index f737ede44..bd91de78a 100644 --- a/src/Discord.Net/Entities/Messages/Message.cs +++ b/src/Discord.Net/Entities/Messages/Message.cs @@ -18,6 +18,7 @@ namespace Discord public bool IsTTS { get; private set; } public string RawText { get; private set; } public string Text { get; private set; } + public bool IsPinned { get; private set; } public IMessageChannel Channel { get; } public IUser Author { get; } @@ -57,13 +58,15 @@ namespace Discord if (model.IsTextToSpeech.IsSpecified) IsTTS = model.IsTextToSpeech.Value; + if (model.Pinned.IsSpecified) + IsPinned = model.Pinned.Value; if (model.Timestamp.IsSpecified) _timestampTicks = model.Timestamp.Value.UtcTicks; if (model.EditedTimestamp.IsSpecified) _editedTimestampTicks = model.EditedTimestamp.Value?.UtcTicks; - if (model.IsMentioningEveryone.IsSpecified) - _isMentioningEveryone = model.IsMentioningEveryone.Value; - + if (model.MentionEveryone.IsSpecified) + _isMentioningEveryone = model.MentionEveryone.Value; + if (model.Attachments.IsSpecified) { var value = model.Attachments.Value; @@ -144,6 +147,9 @@ namespace Discord model = await Discord.ApiClient.ModifyMessageAsync(guildChannel.Guild.Id, Channel.Id, Id, args).ConfigureAwait(false); else model = await Discord.ApiClient.ModifyDMMessageAsync(Channel.Id, Id, args).ConfigureAwait(false); + { + await Discord.ApiClient.AddPinAsync(Channel.Id, Id).ConfigureAwait(false); + } Update(model, UpdateSource.Rest); } public async Task DeleteAsync() @@ -154,6 +160,16 @@ namespace Discord else await Discord.ApiClient.DeleteDMMessageAsync(Channel.Id, Id).ConfigureAwait(false); } + /// Adds this message to its channel's pinned messages. + public async Task PinAsync() + { + await Discord.ApiClient.AddPinAsync(Channel.Id, Id).ConfigureAwait(false); + } + /// Removes this message from its channel's pinned messages. + public async Task UnpinAsync() + { + await Discord.ApiClient.RemovePinAsync(Channel.Id, Id).ConfigureAwait(false); + } public override string ToString() => Text; private string DebuggerDisplay => $"{Author}: {Text}{(Attachments.Length > 0 ? $" [{Attachments.Length} Attachments]" : "")}";