@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;
using System.IO;
@@ -6,7 +7,16 @@ namespace Discord
/// <summary> An extension class for various Discord user objects. </summary>
public static class UserExtensions
{
/// <summary> Sends a message to the user via DM. </summary>
/// <summary>
/// Sends a message via DM.
/// </summary>
/// <param name="text">The message to be sent.</param>
/// <param name="isTTS">Whether the message should be read aloud by Discord or not.</param>
/// <param name="embed">The <see cref="EmbedType.Rich"/> <see cref="Embed"/> to be sent.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable Task containing the message sent to the channel.
/// </returns>
public static async Task<IUserMessage> SendMessageAsync(this IUser user,
string text,
bool isTTS = false,
@@ -16,7 +26,23 @@ namespace Discord
return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false);
}
/// <summary> Sends a file to the user via DM. </summary>
/// <summary>
/// Sends a file to this message channel with an optional caption.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> of the file to be sent.</param>
/// <param name="filename">The name of the attachment.</param>
/// <param name="text">The message to be sent.</param>
/// <param name="isTTS">Whether the message should be read aloud by Discord or not.</param>
/// <param name="embed">The <see cref="EmbedType.Rich"/> <see cref="Embed"/> to be sent.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <remarks>
/// If you wish to upload an image and have it embedded in a <see cref="EmbedType.Rich"/> embed, you may
/// upload the file and refer to the file with "attachment://filename.ext" in the
/// <see cref="Discord.EmbedBuilder.ImageUrl"/>.
/// </remarks>
/// <returns>
/// An awaitable Task containing the message sent to the channel.
/// </returns>
public static async Task<IUserMessage> SendFileAsync(this IUser user,
Stream stream,
string filename,
@@ -30,7 +56,22 @@ namespace Discord
}
#if FILESYSTEM
/// <summary> Sends a file to the user via DM. </summary>
/// <summary>
/// Sends a file via DM with an optional caption.
/// </summary>
/// <param name="filePath">The file path of the file.</param>
/// <param name="text">The message to be sent.</param>
/// <param name="isTTS">Whether the message should be read aloud by Discord or not.</param>
/// <param name="embed">The <see cref="EmbedType.Rich"/> <see cref="Embed"/> to be sent.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <remarks>
/// If you wish to upload an image and have it embedded in a <see cref="EmbedType.Rich"/> embed, you may
/// upload the file and refer to the file with "attachment://filename.ext" in the
/// <see cref="Discord.EmbedBuilder.ImageUrl"/>.
/// </remarks>
/// <returns>
/// An awaitable Task containing the message sent to the channel.
/// </returns>
public static async Task<IUserMessage> SendFileAsync(this IUser user,
string filePath,
string text = null,
@@ -41,10 +82,15 @@ namespace Discord
return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false);
}
#endif
/// <summary> Bans the provided user from the guild and optionally prunes their recent messages. </summary>
/// <param name="user"> The user to ban. </param>
/// <param name="pruneDays"> The number of days to remove messages from this user for - must be between [0, 7]</param>
/// <param name="reason"> The reason of the ban to be written in the audit log. </param>
/// <summary>
/// Bans the provided user from the guild and optionally prunes their recent messages.
/// </summary>
/// <param name="user">The user to ban.</param>
/// <param name="pruneDays">
/// The number of days to remove messages from this user for - must be between [0, 7]
/// </param>
/// <param name="reason">The reason of the ban to be written in the audit log.</param>
/// <exception cref="ArgumentException"><paramref name="pruneDays" /> is not between 0 to 7.</exception>
public static Task BanAsync(this IGuildUser user, int pruneDays = 0, string reason = null, RequestOptions options = null)
=> user.Guild.AddBanAsync(user, pruneDays, reason, options);
}