mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
Switch to discord.net 3.0.0
This commit is contained in:
@@ -38,23 +38,6 @@ public static class Extensions
|
||||
}),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(text))
|
||||
};
|
||||
|
||||
public static Task<IUserMessage> SendAsync(this IMessageChannel channel, string plainText, Embed embed, bool sanitizeAll = false)
|
||||
{
|
||||
plainText = sanitizeAll
|
||||
? plainText?.SanitizeAllMentions() ?? ""
|
||||
: plainText?.SanitizeMentions() ?? "";
|
||||
|
||||
return channel.SendMessageAsync(plainText, embed: embed);
|
||||
}
|
||||
|
||||
public static Task<IUserMessage> SendAsync(this IMessageChannel channel, SmartText text, bool sanitizeAll = false)
|
||||
=> text switch
|
||||
{
|
||||
SmartEmbedText set => channel.SendAsync(set.PlainText, set.GetEmbed().Build(), sanitizeAll),
|
||||
SmartPlainText st => channel.SendAsync(st.Text, null, sanitizeAll),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(text))
|
||||
};
|
||||
|
||||
public static List<ulong> GetGuildIds(this DiscordSocketClient client)
|
||||
=> client.Guilds.Select(x => x.Id).ToList();
|
||||
@@ -334,10 +317,9 @@ public static class Extensions
|
||||
|
||||
public static async Task<IMessage> SendMessageToOwnerAsync(this IGuild guild, string message)
|
||||
{
|
||||
var ownerPrivate = await (await guild.GetOwnerAsync().ConfigureAwait(false)).GetOrCreateDMChannelAsync()
|
||||
.ConfigureAwait(false);
|
||||
var owner = await guild.GetOwnerAsync();
|
||||
|
||||
return await ownerPrivate.SendMessageAsync(message).ConfigureAwait(false);
|
||||
return await owner.SendMessageAsync(message);
|
||||
}
|
||||
|
||||
public static bool IsImage(this HttpResponseMessage msg) => IsImage(msg, out _);
|
||||
|
@@ -5,6 +5,23 @@ public static class IMessageChannelExtensions
|
||||
public static Task<IUserMessage> EmbedAsync(this IMessageChannel ch, IEmbedBuilder embed, string msg = "")
|
||||
=> ch.SendMessageAsync(msg, embed: embed.Build(),
|
||||
options: new() { RetryMode = RetryMode.AlwaysRetry });
|
||||
|
||||
public static Task<IUserMessage> SendAsync(this IMessageChannel channel, string plainText, Embed embed, bool sanitizeAll = false)
|
||||
{
|
||||
plainText = sanitizeAll
|
||||
? plainText?.SanitizeAllMentions() ?? ""
|
||||
: plainText?.SanitizeMentions() ?? "";
|
||||
|
||||
return channel.SendMessageAsync(plainText, embed: embed);
|
||||
}
|
||||
|
||||
public static Task<IUserMessage> SendAsync(this IMessageChannel channel, SmartText text, bool sanitizeAll = false)
|
||||
=> text switch
|
||||
{
|
||||
SmartEmbedText set => channel.SendAsync(set.PlainText, set.GetEmbed().Build(), sanitizeAll),
|
||||
SmartPlainText st => channel.SendAsync(st.Text, null, sanitizeAll),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(text))
|
||||
};
|
||||
|
||||
// this is a huge problem, because now i don't have
|
||||
// access to embed builder service
|
||||
@@ -97,7 +114,7 @@ public static class IMessageChannelExtensions
|
||||
else if (addPaginatedFooter)
|
||||
embed.AddPaginatedFooter(currentPage, lastPage);
|
||||
|
||||
var msg = await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false) as IUserMessage;
|
||||
var msg = await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
|
||||
if (lastPage == 0 || !canPaginate)
|
||||
return;
|
||||
|
@@ -4,8 +4,26 @@ namespace NadekoBot.Extensions;
|
||||
|
||||
public static class IUserExtensions
|
||||
{
|
||||
public static async Task<IUserMessage> EmbedAsync(this IUser user, IEmbedBuilder embed, string msg = "")
|
||||
{
|
||||
var ch = await user.CreateDMChannelAsync();
|
||||
return await ch.EmbedAsync(embed, msg);
|
||||
}
|
||||
|
||||
public static async Task<IUserMessage> SendAsync(this IUser user, string plainText, Embed embed, bool sanitizeAll = false)
|
||||
{
|
||||
var ch = await user.CreateDMChannelAsync();
|
||||
return await ch.SendAsync(plainText, embed, sanitizeAll);
|
||||
}
|
||||
|
||||
public static async Task<IUserMessage> SendAsync(this IUser user, SmartText text, bool sanitizeAll = false)
|
||||
{
|
||||
var ch = await user.CreateDMChannelAsync();
|
||||
return await ch.SendAsync(text, sanitizeAll);
|
||||
}
|
||||
|
||||
public static async Task<IUserMessage> SendConfirmAsync(this IUser user, IEmbedBuilderService eb, string text)
|
||||
=> await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: eb.Create()
|
||||
=> await user.SendMessageAsync("", embed: eb.Create()
|
||||
.WithOkColor()
|
||||
.WithDescription(text)
|
||||
.Build());
|
||||
@@ -16,7 +34,7 @@ public static class IUserExtensions
|
||||
if (url != null && Uri.IsWellFormedUriString(url, UriKind.Absolute))
|
||||
embed.WithUrl(url);
|
||||
|
||||
return await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: embed.Build());
|
||||
return await user.SendMessageAsync("", embed: embed.Build());
|
||||
}
|
||||
|
||||
public static async Task<IUserMessage> SendErrorAsync(this IUser user, IEmbedBuilderService eb, string title, string error, string url = null)
|
||||
@@ -25,11 +43,11 @@ public static class IUserExtensions
|
||||
if (url != null && Uri.IsWellFormedUriString(url, UriKind.Absolute))
|
||||
embed.WithUrl(url);
|
||||
|
||||
return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync("", embed: embed.Build()).ConfigureAwait(false);
|
||||
return await user.SendMessageAsync("", embed: embed.Build()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public static async Task<IUserMessage> SendErrorAsync(this IUser user, IEmbedBuilderService eb, string error)
|
||||
=> await (await user.GetOrCreateDMChannelAsync())
|
||||
=> await user
|
||||
.SendMessageAsync("", embed: eb.Create()
|
||||
.WithErrorColor()
|
||||
.WithDescription(error)
|
||||
@@ -39,12 +57,12 @@ public static class IUserExtensions
|
||||
{
|
||||
await using (var file = File.Open(filePath, FileMode.Open))
|
||||
{
|
||||
return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(file, caption ?? "x", text, isTTS).ConfigureAwait(false);
|
||||
return await user.SendFileAsync(file, 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);
|
||||
await user.SendFileAsync(fileStream, fileName, caption, isTTS).ConfigureAwait(false);
|
||||
|
||||
// This method is used by everything that fetches the avatar from a user
|
||||
public static Uri RealAvatarUrl(this IUser usr, ushort size = 128)
|
||||
|
Reference in New Issue
Block a user