From fb18c2ed326b55addf6146ea2a68c104fae5a3aa Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Wed, 5 Jul 2017 21:22:55 +0200 Subject: [PATCH] Fixed discord.net errors --- src/NadekoBot/_Extensions/Extensions.cs | 38 +++++++++++++++++++------ 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 880e9fbe..5622b936 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -237,12 +237,20 @@ namespace NadekoBot.Extensions => await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithOkColor().WithDescription(text)); public static async Task SendConfirmAsync(this IUser user, string title, string text, string url = null) - => await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithOkColor().WithDescription(text) - .WithTitle(title).WithUrl(url)); + { + var eb = new EmbedBuilder().WithOkColor().WithDescription(text); + if (url != null && Uri.IsWellFormedUriString(url, UriKind.Absolute)) + eb.WithUrl(url); + return await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: eb); + } public static async Task SendErrorAsync(this IUser user, string title, string error, string url = null) - => await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithErrorColor().WithDescription(error) - .WithTitle(title).WithUrl(url)); + { + var eb = new EmbedBuilder().WithErrorColor().WithDescription(error); + if (url != null && Uri.IsWellFormedUriString(url, UriKind.Absolute)) + eb.WithUrl(url); + return await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: eb); + } public static async Task SendErrorAsync(this IUser user, string error) => await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithErrorColor().WithDescription(error)); @@ -260,15 +268,29 @@ namespace NadekoBot.Extensions => ch.SendMessageAsync(msg, embed: embed); public static Task SendErrorAsync(this IMessageChannel ch, string title, string error, string url = null, string footer = null) - => ch.SendMessageAsync("", embed: new EmbedBuilder().WithErrorColor().WithDescription(error) - .WithTitle(title).WithUrl(url).WithFooter(efb => efb.WithText(footer))); + { + var eb = new EmbedBuilder().WithErrorColor().WithDescription(error) + .WithTitle(title); + if (url != null && Uri.IsWellFormedUriString(url, UriKind.Absolute)) + eb.WithUrl(url); + if (!string.IsNullOrWhiteSpace(footer)) + eb.WithFooter(efb => efb.WithText(footer)); + return ch.SendMessageAsync("", embed: eb); + } public static Task SendErrorAsync(this IMessageChannel ch, string error) => ch.SendMessageAsync("", embed: new EmbedBuilder().WithErrorColor().WithDescription(error)); public static Task SendConfirmAsync(this IMessageChannel ch, string title, string text, string url = null, string footer = null) - => ch.SendMessageAsync("", embed: new EmbedBuilder().WithOkColor().WithDescription(text) - .WithTitle(title).WithUrl(url).WithFooter(efb => efb.WithText(footer))); + { + var eb = new EmbedBuilder().WithOkColor().WithDescription(text) + .WithTitle(title); + if (url != null && Uri.IsWellFormedUriString(url, UriKind.Absolute)) + eb.WithUrl(url); + if (!string.IsNullOrWhiteSpace(footer)) + eb.WithFooter(efb => efb.WithText(footer)); + return ch.SendMessageAsync("", embed: eb); + } public static Task SendConfirmAsync(this IMessageChannel ch, string text) => ch.SendMessageAsync("", embed: new EmbedBuilder().WithOkColor().WithDescription(text));