2017-07-15 13:08:34 +00:00
|
|
|
|
using Discord;
|
2017-10-13 04:14:54 +00:00
|
|
|
|
using NadekoBot.Core.Services.Database.Models;
|
2017-07-15 13:08:34 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace NadekoBot.Extensions
|
|
|
|
|
{
|
|
|
|
|
public static class IUserExtensions
|
|
|
|
|
{
|
|
|
|
|
public static async Task<IUserMessage> SendConfirmAsync(this IUser user, string text)
|
2017-09-10 01:52:34 +00:00
|
|
|
|
=> await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithOkColor().WithDescription(text).Build());
|
2017-07-15 13:08:34 +00:00
|
|
|
|
|
|
|
|
|
public static async Task<IUserMessage> SendConfirmAsync(this IUser user, string title, string text, string url = null)
|
|
|
|
|
{
|
|
|
|
|
var eb = new EmbedBuilder().WithOkColor().WithDescription(text);
|
|
|
|
|
if (url != null && Uri.IsWellFormedUriString(url, UriKind.Absolute))
|
|
|
|
|
eb.WithUrl(url);
|
2017-09-10 01:52:34 +00:00
|
|
|
|
return await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: eb.Build());
|
2017-07-15 13:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<IUserMessage> SendErrorAsync(this IUser user, string title, string error, string url = null)
|
|
|
|
|
{
|
|
|
|
|
var eb = new EmbedBuilder().WithErrorColor().WithDescription(error);
|
|
|
|
|
if (url != null && Uri.IsWellFormedUriString(url, UriKind.Absolute))
|
|
|
|
|
eb.WithUrl(url);
|
2017-09-10 01:52:34 +00:00
|
|
|
|
return await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: eb.Build());
|
2017-07-15 13:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static async Task<IUserMessage> SendErrorAsync(this IUser user, string error)
|
2017-09-10 01:52:34 +00:00
|
|
|
|
=> await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithErrorColor().WithDescription(error).Build());
|
2017-07-15 13:08:34 +00:00
|
|
|
|
|
|
|
|
|
public static async Task<IUserMessage> SendFileAsync(this IUser user, string filePath, string caption = null, string text = null, bool isTTS = false) =>
|
|
|
|
|
await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(File.Open(filePath, FileMode.Open), caption ?? "x", text, isTTS).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
public static async Task<IUserMessage> SendFileAsync(this IUser user, Stream fileStream, string fileName, string caption = null, bool isTTS = false) =>
|
|
|
|
|
await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(fileStream, fileName, caption, isTTS).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
public static string RealAvatarUrl(this IUser usr) =>
|
|
|
|
|
usr.AvatarId.StartsWith("a_")
|
|
|
|
|
? $"{DiscordConfig.CDNUrl}avatars/{usr.Id}/{usr.AvatarId}.gif"
|
|
|
|
|
: usr.GetAvatarUrl(ImageFormat.Auto);
|
2017-09-10 01:52:34 +00:00
|
|
|
|
|
|
|
|
|
public static string RealAvatarUrl(this DiscordUser usr) =>
|
|
|
|
|
usr.AvatarId.StartsWith("a_")
|
|
|
|
|
? $"{DiscordConfig.CDNUrl}avatars/{usr.UserId}/{usr.AvatarId}.gif"
|
2017-10-21 17:48:05 +00:00
|
|
|
|
: $"{DiscordConfig.CDNUrl}avatars/{usr.UserId}/{usr.AvatarId}.png";
|
2017-07-15 13:08:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|