mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-04 00:34:26 -05:00 
			
		
		
		
	NadekoBot Patronage system, Search commands improvements + fixes
This commit is contained in:
		@@ -3,5 +3,8 @@ namespace NadekoBot.Extensions;
 | 
			
		||||
public static class BotCredentialsExtensions
 | 
			
		||||
{
 | 
			
		||||
    public static bool IsOwner(this IBotCredentials creds, IUser user)
 | 
			
		||||
        => creds.OwnerIds.Contains(user.Id);
 | 
			
		||||
        => creds.IsOwner(user.Id);
 | 
			
		||||
    
 | 
			
		||||
    public static bool IsOwner(this IBotCredentials creds, ulong userId)
 | 
			
		||||
        => creds.OwnerIds.Contains(userId);
 | 
			
		||||
}
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
using Humanizer.Localisation;
 | 
			
		||||
using Nadeko.Medusa;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Globalization;
 | 
			
		||||
using System.Net.Http.Headers;
 | 
			
		||||
using System.Text.Json;
 | 
			
		||||
@@ -179,6 +180,9 @@ public static class Extensions
 | 
			
		||||
        return module;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static string GetGroupName(this ModuleInfo module)
 | 
			
		||||
        => module.Name.Replace("Commands", "", StringComparison.InvariantCulture);
 | 
			
		||||
 | 
			
		||||
    public static async Task<IEnumerable<IGuildUser>> GetMembersAsync(this IRole role)
 | 
			
		||||
    {
 | 
			
		||||
        var users = await role.Guild.GetUsersAsync(CacheMode.CacheOnly);
 | 
			
		||||
@@ -214,4 +218,10 @@ public static class Extensions
 | 
			
		||||
        => msg.Content.Headers.ContentLength is long length
 | 
			
		||||
            ? length
 | 
			
		||||
            : long.MaxValue;
 | 
			
		||||
 | 
			
		||||
    public static void Lap(this Stopwatch sw, string checkpoint)
 | 
			
		||||
    {
 | 
			
		||||
        Log.Information("Checkpoint {CheckPoint}: {Time}", checkpoint, sw.Elapsed.TotalMilliseconds);
 | 
			
		||||
        sw.Restart();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -30,7 +30,7 @@ public static class MessageChannelExtensions
 | 
			
		||||
    public static async Task<IUserMessage> SendAsync(
 | 
			
		||||
        this IMessageChannel channel,
 | 
			
		||||
        string? plainText,
 | 
			
		||||
        NadekoInteraction? inter,
 | 
			
		||||
        NadekoButtonInteraction? inter,
 | 
			
		||||
        Embed? embed = null,
 | 
			
		||||
        IReadOnlyCollection<Embed>? embeds = null,
 | 
			
		||||
        bool sanitizeAll = false)
 | 
			
		||||
@@ -69,7 +69,7 @@ public static class MessageChannelExtensions
 | 
			
		||||
        IEmbedBuilder? embed,
 | 
			
		||||
        string plainText = "",
 | 
			
		||||
        IReadOnlyCollection<IEmbedBuilder>? embeds = null,
 | 
			
		||||
        NadekoInteraction? inter = null)
 | 
			
		||||
        NadekoButtonInteraction? inter = null)
 | 
			
		||||
        => ch.SendAsync(plainText,
 | 
			
		||||
            inter,
 | 
			
		||||
            embed: embed?.Build(),
 | 
			
		||||
@@ -80,7 +80,7 @@ public static class MessageChannelExtensions
 | 
			
		||||
        IEmbedBuilderService eb,
 | 
			
		||||
        string text,
 | 
			
		||||
        MessageType type,
 | 
			
		||||
        NadekoInteraction? inter = null)
 | 
			
		||||
        NadekoButtonInteraction? inter = null)
 | 
			
		||||
    {
 | 
			
		||||
        var builder = eb.Create().WithDescription(text);
 | 
			
		||||
 | 
			
		||||
@@ -106,12 +106,14 @@ public static class MessageChannelExtensions
 | 
			
		||||
        this IMessageChannel ch,
 | 
			
		||||
        IEmbedBuilderService eb,
 | 
			
		||||
        MessageType type,
 | 
			
		||||
        string title,
 | 
			
		||||
        string? title,
 | 
			
		||||
        string text,
 | 
			
		||||
        string? url = null,
 | 
			
		||||
        string? footer = null)
 | 
			
		||||
    {
 | 
			
		||||
        var embed = eb.Create().WithDescription(text).WithTitle(title);
 | 
			
		||||
        var embed = eb.Create()
 | 
			
		||||
                      .WithDescription(text)
 | 
			
		||||
                      .WithTitle(title);
 | 
			
		||||
 | 
			
		||||
        if (url is not null && Uri.IsWellFormedUriString(url, UriKind.Absolute))
 | 
			
		||||
            embed.WithUrl(url);
 | 
			
		||||
@@ -135,7 +137,7 @@ public static class MessageChannelExtensions
 | 
			
		||||
    public static Task<IUserMessage> SendConfirmAsync(
 | 
			
		||||
        this IMessageChannel ch,
 | 
			
		||||
        IEmbedBuilderService eb,
 | 
			
		||||
        string title,
 | 
			
		||||
        string? title,
 | 
			
		||||
        string text,
 | 
			
		||||
        string? url = null,
 | 
			
		||||
        string? footer = null)
 | 
			
		||||
 
 | 
			
		||||
@@ -100,4 +100,25 @@ public static class ImagesharpExtensions
 | 
			
		||||
        imageStream.Position = 0;
 | 
			
		||||
        return imageStream;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static async Task<MemoryStream> ToStreamAsync(this Image<Rgba32> img, IImageFormat? format = null)
 | 
			
		||||
    {
 | 
			
		||||
        var imageStream = new MemoryStream();
 | 
			
		||||
        if (format?.Name == "GIF")
 | 
			
		||||
        {
 | 
			
		||||
            await img.SaveAsGifAsync(imageStream);
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            await img.SaveAsPngAsync(imageStream,
 | 
			
		||||
                new PngEncoder()
 | 
			
		||||
                {
 | 
			
		||||
                    ColorType = PngColorType.RgbWithAlpha,
 | 
			
		||||
                    CompressionLevel = PngCompressionLevel.DefaultCompression
 | 
			
		||||
                });
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        imageStream.Position = 0;
 | 
			
		||||
        return imageStream;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -54,7 +54,7 @@ public static class SocketMessageComponentExtensions
 | 
			
		||||
        IEmbedBuilder? embed,
 | 
			
		||||
        string plainText = "",
 | 
			
		||||
        IReadOnlyCollection<IEmbedBuilder>? embeds = null,
 | 
			
		||||
        NadekoInteraction? inter = null,
 | 
			
		||||
        NadekoButtonInteraction? inter = null,
 | 
			
		||||
        bool ephemeral = false)
 | 
			
		||||
        => smc.RespondAsync(plainText,
 | 
			
		||||
            embed: embed?.Build(),
 | 
			
		||||
@@ -66,7 +66,7 @@ public static class SocketMessageComponentExtensions
 | 
			
		||||
        string text,
 | 
			
		||||
        MessageType type,
 | 
			
		||||
        bool ephemeral = false,
 | 
			
		||||
        NadekoInteraction? inter = null)
 | 
			
		||||
        NadekoButtonInteraction? inter = null)
 | 
			
		||||
    {
 | 
			
		||||
        var builder = eb.Create().WithDescription(text);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user