Added Message pinning

This commit is contained in:
RogueException
2016-06-25 00:55:39 -03:00
parent febd9636f7
commit 250a7deba7
4 changed files with 50 additions and 4 deletions

View File

@@ -20,12 +20,14 @@ namespace Discord.API
[JsonProperty("tts")]
public Optional<bool> IsTextToSpeech { get; set; }
[JsonProperty("mention_everyone")]
public Optional<bool> IsMentioningEveryone { get; set; }
public Optional<bool> MentionEveryone { get; set; }
[JsonProperty("mentions")]
public Optional<User[]> Mentions { get; set; }
[JsonProperty("attachments")]
public Optional<Attachment[]> Attachments { get; set; }
[JsonProperty("embeds")]
public Optional<Embed[]> Embeds { get; set; }
[JsonProperty("pinned")]
public Optional<bool> Pinned { get; set; }
}
}

View File

@@ -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<Guild> GetGuildAsync(ulong guildId, RequestOptions options = null)
{

View File

@@ -11,6 +11,8 @@ namespace Discord
DateTimeOffset? EditedTimestamp { get; }
/// <summary> Returns true if this message was sent as a text-to-speech message. </summary>
bool IsTTS { get; }
/// <summary> Returns true if this message was added to its channel's pinned messages. </summary>
bool IsPinned { get; }
/// <summary> Returns the original, unprocessed text for this message. </summary>
string RawText { get; }
/// <summary> Returns the text for this message after mention processing. </summary>
@@ -35,5 +37,9 @@ namespace Discord
/// <summary> Modifies this message. </summary>
Task ModifyAsync(Action<ModifyMessageParams> func);
/// <summary> Adds this message to its channel's pinned messages. </summary>
Task PinAsync();
/// <summary> Removes this message from its channel's pinned messages. </summary>
Task UnpinAsync();
}
}

View File

@@ -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);
}
/// <summary> Adds this message to its channel's pinned messages. </summary>
public async Task PinAsync()
{
await Discord.ApiClient.AddPinAsync(Channel.Id, Id).ConfigureAwait(false);
}
/// <summary> Removes this message from its channel's pinned messages. </summary>
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]" : "")}";