@@ -0,0 +1,20 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Threading.Tasks; | |||
using Newtonsoft.Json; | |||
namespace Discord.API.Common | |||
{ | |||
public class Reaction | |||
{ | |||
[JsonProperty("user_id")] | |||
public ulong UserId { get; set; } | |||
[JsonProperty("message_id")] | |||
public ulong MessageId { get; set; } | |||
[JsonProperty("emoji")] | |||
public Emoji Emoji { get; set; } | |||
[JsonProperty("channel_id")] | |||
public ulong ChannelId { get; set; } | |||
} | |||
} |
@@ -512,6 +512,48 @@ namespace Discord.API | |||
var ids = new BucketIds(channelId: channelId); | |||
return await SendJsonAsync<Message>("PATCH", () => $"channels/{channelId}/messages/{messageId}", args, ids, clientBucketId: ClientBucket.SendEditId, options: options).ConfigureAwait(false); | |||
} | |||
public async Task AddReactionAsync(ulong channelId, ulong messageId, string emoji, RequestOptions options = null) | |||
{ | |||
Preconditions.NotEqual(channelId, 0, nameof(channelId)); | |||
Preconditions.NotEqual(messageId, 0, nameof(messageId)); | |||
Preconditions.NotNullOrWhitespace(emoji, nameof(emoji)); | |||
options = RequestOptions.CreateOrClone(options); | |||
var ids = new BucketIds(channelId: channelId); | |||
await SendAsync("PUT", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/@me", ids, options: options).ConfigureAwait(false); | |||
} | |||
public async Task RemoveReactionAsync(ulong channelId, ulong messageId, ulong userId, string emoji, RequestOptions options = null) | |||
{ | |||
Preconditions.NotEqual(channelId, 0, nameof(channelId)); | |||
Preconditions.NotEqual(messageId, 0, nameof(messageId)); | |||
Preconditions.NotNullOrWhitespace(emoji, nameof(emoji)); | |||
options = RequestOptions.CreateOrClone(options); | |||
var ids = new BucketIds(channelId: channelId); | |||
await SendAsync("DELETE", () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}/{userId}", ids, options: options).ConfigureAwait(false); | |||
} | |||
public async Task<IReadOnlyCollection<User>> GetReactionUsersAsync(ulong channelId, ulong messageId, string emoji, GetReactionUsersParams args, RequestOptions options = null) | |||
{ | |||
Preconditions.NotEqual(channelId, 0, nameof(channelId)); | |||
Preconditions.NotEqual(messageId, 0, nameof(messageId)); | |||
Preconditions.NotNullOrWhitespace(emoji, nameof(emoji)); | |||
Preconditions.NotNull(args, nameof(args)); | |||
Preconditions.GreaterThan(args.Limit, 0, nameof(args.Limit)); | |||
Preconditions.AtMost(args.Limit, DiscordConfig.MaxUsersPerBatch, nameof(args.Limit)); | |||
Preconditions.GreaterThan(args.AfterUserId, 0, nameof(args.AfterUserId)); | |||
options = RequestOptions.CreateOrClone(options); | |||
int limit = args.Limit.GetValueOrDefault(int.MaxValue); | |||
ulong afterUserId = args.AfterUserId.GetValueOrDefault(0); | |||
var ids = new BucketIds(channelId: channelId); | |||
Expression<Func<string>> endpoint = () => $"channels/{channelId}/messages/{messageId}/reactions/{emoji}"; | |||
return await SendAsync<IReadOnlyCollection<User>>("GET", endpoint, ids, options: options).ConfigureAwait(false); | |||
} | |||
public async Task AckMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) | |||
{ | |||
Preconditions.NotEqual(channelId, 0, nameof(channelId)); | |||
@@ -0,0 +1,8 @@ | |||
namespace Discord.API.Rest | |||
{ | |||
public class GetReactionUsersParams | |||
{ | |||
public Optional<int> Limit { get; set; } | |||
public Optional<ulong> AfterUserId { get; set; } | |||
} | |||
} |
@@ -1,5 +1,6 @@ | |||
using Discord.API.Rest; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Threading.Tasks; | |||
namespace Discord | |||
@@ -12,7 +13,17 @@ namespace Discord | |||
Task PinAsync(RequestOptions options = null); | |||
/// <summary> Removes this message from its channel's pinned messages. </summary> | |||
Task UnpinAsync(RequestOptions options = null); | |||
/// <summary> Adds a reaction to this message. </summary> | |||
Task AddReactionAsync(Emoji emoji, RequestOptions options = null); | |||
/// <summary> Adds a reaction to this message. </summary> | |||
Task AddReactionAsync(string emoji, RequestOptions options = null); | |||
/// <summary> Removes a reaction from message. </summary> | |||
Task RemoveReactionAsync(Emoji emoji, IUser user, RequestOptions options = null); | |||
/// <summary> Removes a reaction from this message. </summary> | |||
Task RemoveReactionAsync(string emoji, IUser user, RequestOptions options = null); | |||
Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(string emoji, Action<GetReactionUsersParams> func, RequestOptions options = null); | |||
/// <summary> Transforms this message's text into a human readable form by resolving its tags. </summary> | |||
string Resolve( | |||
TagHandling userHandling = TagHandling.Name, | |||
@@ -45,6 +45,7 @@ namespace Discord | |||
throw new ArgumentException("Argument cannot be blank.", name); | |||
} | |||
} | |||
//Numerics | |||
public static void NotEqual(sbyte obj, sbyte value, string name) { if (obj == value) throw new ArgumentOutOfRangeException(name); } | |||
@@ -23,6 +23,29 @@ namespace Discord.Rest | |||
await client.ApiClient.DeleteMessageAsync(msg.Channel.Id, msg.Id, options).ConfigureAwait(false); | |||
} | |||
public static async Task AddReactionAsync(IMessage msg, Emoji emoji, BaseDiscordClient client, RequestOptions options) | |||
=> await AddReactionAsync(msg, $"{emoji.Name}:{emoji.Id}", client, options).ConfigureAwait(false); | |||
public static async Task AddReactionAsync(IMessage msg, string emoji, BaseDiscordClient client, RequestOptions options) | |||
{ | |||
await client.ApiClient.AddReactionAsync(msg.Channel.Id, msg.Id, emoji, options).ConfigureAwait(false); | |||
} | |||
public static async Task RemoveReactionAsync(IMessage msg, IUser user, Emoji emoji, BaseDiscordClient client, RequestOptions options) | |||
=> await RemoveReactionAsync(msg, user, $"{emoji.Name}:{emoji.Id}", client, options).ConfigureAwait(false); | |||
public static async Task RemoveReactionAsync(IMessage msg, IUser user, string emoji, BaseDiscordClient client, | |||
RequestOptions options) | |||
{ | |||
await client.ApiClient.RemoveReactionAsync(msg.Channel.Id, msg.Id, user.Id, emoji, options); | |||
} | |||
public static async Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, string emoji, | |||
Action<GetReactionUsersParams> func, BaseDiscordClient client, RequestOptions options) | |||
{ | |||
var args = new GetReactionUsersParams(); | |||
func(args); | |||
return (await client.ApiClient.GetReactionUsersAsync(msg.Channel.Id, msg.Id, emoji, args, options).ConfigureAwait(false)).Select(u => u as IUser).Where(u => u != null).ToImmutableArray(); | |||
} | |||
public static async Task PinAsync(IMessage msg, BaseDiscordClient client, | |||
RequestOptions options) | |||
{ | |||
@@ -117,6 +117,20 @@ namespace Discord.Rest | |||
Update(model); | |||
} | |||
public Task AddReactionAsync(Emoji emoji, RequestOptions options) | |||
=> MessageHelper.AddReactionAsync(this, emoji, Discord, options); | |||
public Task AddReactionAsync(string emoji, RequestOptions options) | |||
=> MessageHelper.AddReactionAsync(this, emoji, Discord, options); | |||
public Task RemoveReactionAsync(Emoji emoji, IUser user, RequestOptions options) | |||
=> MessageHelper.RemoveReactionAsync(this, user, emoji, Discord, options); | |||
public Task RemoveReactionAsync(string emoji, IUser user, RequestOptions options) | |||
=> MessageHelper.RemoveReactionAsync(this, user, emoji, Discord, options); | |||
public Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(string emoji, Action<GetReactionUsersParams> func, RequestOptions options) | |||
=> MessageHelper.GetReactionUsersAsync(this, emoji, func, Discord, options); | |||
public Task PinAsync(RequestOptions options) | |||
=> MessageHelper.PinAsync(this, Discord, options); | |||
public Task UnpinAsync(RequestOptions options) | |||
@@ -101,6 +101,19 @@ namespace Discord.Rpc | |||
public Task ModifyAsync(Action<ModifyMessageParams> func, RequestOptions options) | |||
=> MessageHelper.ModifyAsync(this, Discord, func, options); | |||
public Task AddReactionAsync(Emoji emoji, RequestOptions options) | |||
=> MessageHelper.AddReactionAsync(this, emoji, Discord, options); | |||
public Task AddReactionAsync(string emoji, RequestOptions options) | |||
=> MessageHelper.AddReactionAsync(this, emoji, Discord, options); | |||
public Task RemoveReactionAsync(Emoji emoji, IUser user, RequestOptions options) | |||
=> MessageHelper.RemoveReactionAsync(this, user, emoji, Discord, options); | |||
public Task RemoveReactionAsync(string emoji, IUser user, RequestOptions options) | |||
=> MessageHelper.RemoveReactionAsync(this, user, emoji, Discord, options); | |||
public Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(string emoji, Action<GetReactionUsersParams> func, RequestOptions options) | |||
=> MessageHelper.GetReactionUsersAsync(this, emoji, func, Discord, options); | |||
public Task PinAsync(RequestOptions options) | |||
=> MessageHelper.PinAsync(this, Discord, options); | |||
public Task UnpinAsync(RequestOptions options) | |||
@@ -113,6 +113,19 @@ namespace Discord.WebSocket | |||
public Task ModifyAsync(Action<ModifyMessageParams> func, RequestOptions options = null) | |||
=> MessageHelper.ModifyAsync(this, Discord, func, options); | |||
public Task AddReactionAsync(Emoji emoji, RequestOptions options) | |||
=> MessageHelper.AddReactionAsync(this, emoji, Discord, options); | |||
public Task AddReactionAsync(string emoji, RequestOptions options) | |||
=> MessageHelper.AddReactionAsync(this, emoji, Discord, options); | |||
public Task RemoveReactionAsync(Emoji emoji, IUser user, RequestOptions options) | |||
=> MessageHelper.RemoveReactionAsync(this, user, emoji, Discord, options); | |||
public Task RemoveReactionAsync(string emoji, IUser user, RequestOptions options) | |||
=> MessageHelper.RemoveReactionAsync(this, user, emoji, Discord, options); | |||
public Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(string emoji, Action<GetReactionUsersParams> func, RequestOptions options) | |||
=> MessageHelper.GetReactionUsersAsync(this, emoji, func, Discord, options); | |||
public Task PinAsync(RequestOptions options = null) | |||
=> MessageHelper.PinAsync(this, Discord, options); | |||
public Task UnpinAsync(RequestOptions options = null) | |||