mirror of
				https://gitlab.com/Kwoth/nadekobot.git
				synced 2025-11-04 00:34:26 -05:00 
			
		
		
		
	Updated editorconfig to (mostly?) require braces around if/else statements, and applied the new formatting rules
This commit is contained in:
		@@ -13,7 +13,7 @@ public static class Extensions
 | 
			
		||||
 | 
			
		||||
    public static IEmbedBuilder WithAuthor(this IEmbedBuilder eb, IUser author)
 | 
			
		||||
        => eb.WithAuthor(author.ToString(), author.RealAvatarUrl().ToString());
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    public static Task EditAsync(this IUserMessage msg, SmartText text)
 | 
			
		||||
        => text switch
 | 
			
		||||
        {
 | 
			
		||||
@@ -58,7 +58,6 @@ public static class Extensions
 | 
			
		||||
    public static IEmote ToIEmote(this string emojiStr)
 | 
			
		||||
        => Emote.TryParse(emojiStr, out var maybeEmote) ? maybeEmote : new Emoji(emojiStr);
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    ///     First 10 characters of teh bot token.
 | 
			
		||||
@@ -115,11 +114,11 @@ public static class Extensions
 | 
			
		||||
        var wrap = new ReactionEventWrapper(client, msg);
 | 
			
		||||
        wrap.OnReactionAdded += r =>
 | 
			
		||||
        {
 | 
			
		||||
            _= Task.Run(() => reactionAdded(r));
 | 
			
		||||
            _ = Task.Run(() => reactionAdded(r));
 | 
			
		||||
        };
 | 
			
		||||
        wrap.OnReactionRemoved += r =>
 | 
			
		||||
        {
 | 
			
		||||
            _= Task.Run(() => reactionRemoved(r));
 | 
			
		||||
            _ = Task.Run(() => reactionRemoved(r));
 | 
			
		||||
        };
 | 
			
		||||
        return wrap;
 | 
			
		||||
    }
 | 
			
		||||
@@ -143,7 +142,8 @@ public static class Extensions
 | 
			
		||||
        Task.Run(async () =>
 | 
			
		||||
        {
 | 
			
		||||
            await Task.Delay(seconds * 1000);
 | 
			
		||||
            if (logService is not null) logService.AddDeleteIgnore(msg.Id);
 | 
			
		||||
            if (logService is not null)
 | 
			
		||||
                logService.AddDeleteIgnore(msg.Id);
 | 
			
		||||
 | 
			
		||||
            try { await msg.DeleteAsync(); }
 | 
			
		||||
            catch { }
 | 
			
		||||
@@ -153,7 +153,8 @@ public static class Extensions
 | 
			
		||||
 | 
			
		||||
    public static ModuleInfo GetTopLevelModule(this ModuleInfo module)
 | 
			
		||||
    {
 | 
			
		||||
        while (module.Parent is not null) module = module.Parent;
 | 
			
		||||
        while (module.Parent is not null)
 | 
			
		||||
            module = module.Parent;
 | 
			
		||||
 | 
			
		||||
        return module;
 | 
			
		||||
    }
 | 
			
		||||
@@ -183,14 +184,16 @@ public static class Extensions
 | 
			
		||||
    public static bool IsImage(this HttpResponseMessage msg, out string? mimeType)
 | 
			
		||||
    {
 | 
			
		||||
        mimeType = msg.Content.Headers.ContentType?.MediaType;
 | 
			
		||||
        if (mimeType is "image/png" or "image/jpeg" or "image/gif") return true;
 | 
			
		||||
        if (mimeType is "image/png" or "image/jpeg" or "image/gif")
 | 
			
		||||
            return true;
 | 
			
		||||
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public static long? GetImageSize(this HttpResponseMessage msg)
 | 
			
		||||
    {
 | 
			
		||||
        if (msg.Content.Headers.ContentLength is null) return null;
 | 
			
		||||
        if (msg.Content.Headers.ContentLength is null)
 | 
			
		||||
            return null;
 | 
			
		||||
 | 
			
		||||
        return msg.Content.Headers.ContentLength.Value / 1.Mb();
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,12 @@ public static class MessageChannelExtensions
 | 
			
		||||
    private static readonly IEmote _arrowRight = new Emoji("➡");
 | 
			
		||||
 | 
			
		||||
    public static Task<IUserMessage> EmbedAsync(this IMessageChannel ch, IEmbedBuilder embed, string msg = "")
 | 
			
		||||
        => ch.SendMessageAsync(msg, embed: embed.Build(), options: new() { RetryMode = RetryMode.AlwaysRetry });
 | 
			
		||||
        => ch.SendMessageAsync(msg,
 | 
			
		||||
            embed: embed.Build(),
 | 
			
		||||
            options: new()
 | 
			
		||||
            {
 | 
			
		||||
                RetryMode = RetryMode.AlwaysRetry
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
    public static Task<IUserMessage> SendAsync(
 | 
			
		||||
        this IMessageChannel channel,
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,8 @@ public static class ImagesharpExtensions
 | 
			
		||||
    /// <returns>The same <see cref="TextOptions" /> to allow chaining</returns>
 | 
			
		||||
    public static TextOptions WithFallbackFonts(this TextOptions opts, List<FontFamily> fallback)
 | 
			
		||||
    {
 | 
			
		||||
        foreach (var ff in fallback) opts.FallbackFonts.Add(ff);
 | 
			
		||||
        foreach (var ff in fallback)
 | 
			
		||||
            opts.FallbackFonts.Add(ff);
 | 
			
		||||
 | 
			
		||||
        return opts;
 | 
			
		||||
    }
 | 
			
		||||
@@ -36,7 +37,7 @@ public static class ImagesharpExtensions
 | 
			
		||||
        opts.TextOptions.WithFallbackFonts(fallback);
 | 
			
		||||
        return opts;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    // https://github.com/SixLabors/Samples/blob/master/ImageSharp/AvatarWithRoundedCorner/Program.cs
 | 
			
		||||
    public static IImageProcessingContext ApplyRoundedCorners(this IImageProcessingContext ctx, float cornerRadius)
 | 
			
		||||
    {
 | 
			
		||||
@@ -50,7 +51,8 @@ public static class ImagesharpExtensions
 | 
			
		||||
            AlphaCompositionMode = PixelAlphaCompositionMode.DestOut
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        foreach (var c in corners) ctx = ctx.Fill(SixLabors.ImageSharp.Color.Red, c);
 | 
			
		||||
        foreach (var c in corners)
 | 
			
		||||
            ctx = ctx.Fill(SixLabors.ImageSharp.Color.Red, c);
 | 
			
		||||
 | 
			
		||||
        return ctx;
 | 
			
		||||
    }
 | 
			
		||||
@@ -76,7 +78,7 @@ public static class ImagesharpExtensions
 | 
			
		||||
 | 
			
		||||
        return new PathCollection(cornerTopLeft, cornerBottomLeft, cornerTopRight, cornerBottomRight);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    public static Color ToDiscordColor(this Rgba32 color)
 | 
			
		||||
        => new(color.R, color.G, color.B);
 | 
			
		||||
 | 
			
		||||
@@ -89,7 +91,8 @@ public static class ImagesharpExtensions
 | 
			
		||||
            img.SaveAsPng(imageStream,
 | 
			
		||||
                new()
 | 
			
		||||
                {
 | 
			
		||||
                    ColorType = PngColorType.RgbWithAlpha, CompressionLevel = PngCompressionLevel.BestCompression
 | 
			
		||||
                    ColorType = PngColorType.RgbWithAlpha,
 | 
			
		||||
                    CompressionLevel = PngCompressionLevel.BestCompression
 | 
			
		||||
                });
 | 
			
		||||
 | 
			
		||||
        imageStream.Position = 0;
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,8 @@ public static class ProcessExtensions
 | 
			
		||||
        {
 | 
			
		||||
            var children = new HashSet<int>();
 | 
			
		||||
            GetAllChildIdsUnix(process.Id, children, timeout);
 | 
			
		||||
            foreach (var childId in children) KillProcessUnix(childId, timeout);
 | 
			
		||||
            foreach (var childId in children)
 | 
			
		||||
                KillProcessUnix(childId, timeout);
 | 
			
		||||
 | 
			
		||||
            KillProcessUnix(process.Id, timeout);
 | 
			
		||||
        }
 | 
			
		||||
@@ -41,7 +42,8 @@ public static class ProcessExtensions
 | 
			
		||||
            while (true)
 | 
			
		||||
            {
 | 
			
		||||
                var text = reader.ReadLine();
 | 
			
		||||
                if (text is null) return;
 | 
			
		||||
                if (text is null)
 | 
			
		||||
                    return;
 | 
			
		||||
 | 
			
		||||
                if (int.TryParse(text, out var id))
 | 
			
		||||
                {
 | 
			
		||||
@@ -66,7 +68,10 @@ public static class ProcessExtensions
 | 
			
		||||
 | 
			
		||||
        var startInfo = new ProcessStartInfo
 | 
			
		||||
        {
 | 
			
		||||
            FileName = fileName, Arguments = arguments, RedirectStandardOutput = true, UseShellExecute = false
 | 
			
		||||
            FileName = fileName,
 | 
			
		||||
            Arguments = arguments,
 | 
			
		||||
            RedirectStandardOutput = true,
 | 
			
		||||
            UseShellExecute = false
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
        var process = Process.Start(startInfo);
 | 
			
		||||
 
 | 
			
		||||
@@ -23,11 +23,13 @@ public static class ServiceCollectionExtensions
 | 
			
		||||
        var baseType = typeof(ConfigServiceBase<>);
 | 
			
		||||
 | 
			
		||||
        foreach (var type in Assembly.GetCallingAssembly().ExportedTypes.Where(x => x.IsSealed))
 | 
			
		||||
        {
 | 
			
		||||
            if (type.BaseType?.IsGenericType == true && type.BaseType.GetGenericTypeDefinition() == baseType)
 | 
			
		||||
            {
 | 
			
		||||
                services.AddSingleton(type);
 | 
			
		||||
                services.AddSingleton(x => (IConfigService)x.GetRequiredService(type));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return services;
 | 
			
		||||
    }
 | 
			
		||||
@@ -53,7 +55,8 @@ public static class ServiceCollectionExtensions
 | 
			
		||||
        var subTypes = Assembly.GetCallingAssembly()
 | 
			
		||||
                               .ExportedTypes.Where(type => type.IsSealed && baseType.IsAssignableFrom(type));
 | 
			
		||||
 | 
			
		||||
        foreach (var subType in subTypes) services.AddSingleton(baseType, subType);
 | 
			
		||||
        foreach (var subType in subTypes)
 | 
			
		||||
            services.AddSingleton(baseType, subType);
 | 
			
		||||
 | 
			
		||||
        return services;
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -55,9 +55,11 @@ public static class StringExtensions
 | 
			
		||||
        var d = new int[n + 1, m + 1];
 | 
			
		||||
 | 
			
		||||
        // Step 1
 | 
			
		||||
        if (n == 0) return m;
 | 
			
		||||
        if (n == 0)
 | 
			
		||||
            return m;
 | 
			
		||||
 | 
			
		||||
        if (m == 0) return n;
 | 
			
		||||
        if (m == 0)
 | 
			
		||||
            return n;
 | 
			
		||||
 | 
			
		||||
        // Step 2
 | 
			
		||||
        for (var i = 0; i <= n; d[i, 0] = i++)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user