using System.Threading.Tasks;
namespace Discord
{
///
/// Provides extension methods for .
///
public static class MessageExtensions
{
///
/// Gets a URL that jumps to the message.
///
/// The message to jump to.
///
/// A string that contains a URL for jumping to the message in chat.
///
public static string GetJumpUrl(this IMessage msg)
{
var channel = msg.Channel;
return $"https://discord.com/channels/{(channel is IDMChannel ? "@me" : $"{(channel as ITextChannel).GuildId}")}/{channel.Id}/{msg.Id}";
}
///
/// Add multiple reactions to a message.
///
///
/// This method does not bulk add reactions! It will send a request for each reaction inculded.
///
///
///
/// IEmote A = new Emoji("🅰");
/// IEmote B = new Emoji("🅱");
/// await msg.AddReactionsAsync(new[] { A, B });
///
///
/// The message to add reactions to.
/// An array of reactions to add to the message
/// The options to be used when sending the request.
///
/// A task that represents the asynchronous operation for adding a reaction to this message.
///
///
///
public static async Task AddReactionsAsync(this IUserMessage msg, IEmote[] reactions, RequestOptions options = null)
{
foreach (var rxn in reactions)
await msg.AddReactionAsync(rxn, options).ConfigureAwait(false);
}
///
/// Remove multiple reactions from a message.
///
///
/// This method does not bulk remove reactions! If you want to clear reactions from a message,
///
///
///
///
/// await msg.RemoveReactionsAsync(currentUser, new[] { A, B });
///
///
/// The message to remove reactions from.
/// An array of reactions to remove from the message
/// The options to be used when sending the request.
///
/// A task that represents the asynchronous operation for removing a reaction to this message.
///
///
///
public static async Task RemoveReactionsAsync(this IUserMessage msg, IUser user, IEmote[] reactions, RequestOptions options = null)
{
foreach (var rxn in reactions)
await msg.RemoveReactionAsync(rxn, user, options).ConfigureAwait(false);
}
///
/// Sends an inline reply that references a message.
///
/// The message to be sent.
/// Determines whether the message should be read aloud by Discord or not.
/// The to be sent.
///
/// Specifies if notifications are sent for mentioned users and roles in the message .
/// If null, all mentioned roles and users will be notified.
///
/// The options to be used when sending the request.
///
/// A task that represents an asynchronous send operation for delivering the message. The task result
/// contains the sent message.
///
public static async Task ReplyAsync(this IUserMessage msg, string text = null, bool isTTS = false, Embed embed = null, AllowedMentions allowedMentions = null, RequestOptions options = null, MessageComponent components = null, ISticker[] stickers = null)
{
return await msg.Channel.SendMessageAsync(text, isTTS, embed, options, allowedMentions, new MessageReference(messageId: msg.Id), components, stickers).ConfigureAwait(false);
}
}
}