From 77bbc5ef7abea709d55a19db898b9ee700b513bd Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 25 Dec 2021 02:53:00 +0100 Subject: [PATCH] Removed some unused classes, minor cleanup. Added rider anotations to stop some annoying code suggestions --- .../Common/Attributes/Description.cs | 10 --- .../Common/Attributes/LeftoverAttribute.cs | 8 -- src/NadekoBot/Common/Attributes/Usage.cs | 14 ---- .../Collections/DisposableImutableList.cs | 74 ------------------- src/NadekoBot/Common/NadekoModule.cs | 3 + src/NadekoBot/Db/NadekoContext.cs | 3 +- src/NadekoBot/GlobalUsings.cs | 5 +- .../Modules/Administration/RoleCommands.cs | 1 - .../Searches/StreamNotificationCommands.cs | 2 +- src/NadekoBot/NadekoBot.csproj | 1 + 10 files changed, 10 insertions(+), 111 deletions(-) delete mode 100644 src/NadekoBot/Common/Attributes/Description.cs delete mode 100644 src/NadekoBot/Common/Attributes/LeftoverAttribute.cs delete mode 100644 src/NadekoBot/Common/Attributes/Usage.cs delete mode 100644 src/NadekoBot/Common/Collections/DisposableImutableList.cs diff --git a/src/NadekoBot/Common/Attributes/Description.cs b/src/NadekoBot/Common/Attributes/Description.cs deleted file mode 100644 index 5286b6d27..000000000 --- a/src/NadekoBot/Common/Attributes/Description.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace NadekoBot.Common.Attributes; - -[AttributeUsage(AttributeTargets.Method)] -public sealed class DescriptionAttribute : SummaryAttribute -{ - // Localization.LoadCommand(memberName.ToLowerInvariant()).Desc - public DescriptionAttribute(string text = "") : base(text) - { - } -} \ No newline at end of file diff --git a/src/NadekoBot/Common/Attributes/LeftoverAttribute.cs b/src/NadekoBot/Common/Attributes/LeftoverAttribute.cs deleted file mode 100644 index 61f99bd92..000000000 --- a/src/NadekoBot/Common/Attributes/LeftoverAttribute.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Discord.Commands; - -public class LeftoverAttribute : RemainderAttribute -{ - public LeftoverAttribute() - { - } -} \ No newline at end of file diff --git a/src/NadekoBot/Common/Attributes/Usage.cs b/src/NadekoBot/Common/Attributes/Usage.cs deleted file mode 100644 index 96e30eb0a..000000000 --- a/src/NadekoBot/Common/Attributes/Usage.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace NadekoBot.Common.Attributes; - -[AttributeUsage(AttributeTargets.Method)] -public sealed class UsageAttribute : RemarksAttribute -{ - // public static string GetUsage(string memberName) - // { - // var usage = Localization.LoadCommand(memberName.ToLowerInvariant()).Usage; - // return JsonConvert.SerializeObject(usage); - // } - public UsageAttribute(string text = "") : base(text) - { - } -} \ No newline at end of file diff --git a/src/NadekoBot/Common/Collections/DisposableImutableList.cs b/src/NadekoBot/Common/Collections/DisposableImutableList.cs deleted file mode 100644 index 2bb737f2c..000000000 --- a/src/NadekoBot/Common/Collections/DisposableImutableList.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Collections; - -namespace NadekoBot.Common.Collections; - -public static class DisposableReadOnlyListExtensions -{ - public static IDisposableReadOnlyList AsDisposable(this IReadOnlyList arr) where T : IDisposable - => new DisposableReadOnlyList(arr); - - public static IDisposableReadOnlyList> AsDisposable(this IReadOnlyList> arr) where TValue : IDisposable - => new DisposableReadOnlyList(arr); -} - -public interface IDisposableReadOnlyList : IReadOnlyList, IDisposable -{ -} - -public sealed class DisposableReadOnlyList : IDisposableReadOnlyList - where T : IDisposable -{ - private readonly IReadOnlyList _arr; - - public int Count => _arr.Count; - - public T this[int index] => _arr[index]; - - public DisposableReadOnlyList(IReadOnlyList arr) - { - this._arr = arr; - } - - public IEnumerator GetEnumerator() - => _arr.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() - => _arr.GetEnumerator(); - - public void Dispose() - { - foreach (var item in _arr) - { - item.Dispose(); - } - } -} - -public sealed class DisposableReadOnlyList : IDisposableReadOnlyList> - where U : IDisposable -{ - private readonly IReadOnlyList> _arr; - - public int Count => _arr.Count; - - KeyValuePair IReadOnlyList>.this[int index] => _arr[index]; - - public DisposableReadOnlyList(IReadOnlyList> arr) - { - this._arr = arr; - } - - public IEnumerator> GetEnumerator() => - _arr.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => - _arr.GetEnumerator(); - - public void Dispose() - { - foreach (var item in _arr) - { - item.Value.Dispose(); - } - } -} \ No newline at end of file diff --git a/src/NadekoBot/Common/NadekoModule.cs b/src/NadekoBot/Common/NadekoModule.cs index 95599735d..bb7482241 100644 --- a/src/NadekoBot/Common/NadekoModule.cs +++ b/src/NadekoBot/Common/NadekoModule.cs @@ -2,6 +2,9 @@ namespace NadekoBot.Modules; +[UsedImplicitly(ImplicitUseTargetFlags.Default + | ImplicitUseTargetFlags.WithInheritors + | ImplicitUseTargetFlags.WithMembers)] public abstract class NadekoModule : ModuleBase { protected CultureInfo _cultureInfo { get; set; } diff --git a/src/NadekoBot/Db/NadekoContext.cs b/src/NadekoBot/Db/NadekoContext.cs index b5a63a01c..1a1a37236 100644 --- a/src/NadekoBot/Db/NadekoContext.cs +++ b/src/NadekoBot/Db/NadekoContext.cs @@ -45,8 +45,7 @@ public class NadekoContext : DbContext public DbSet RotatingStatus { get; set; } public DbSet Blacklist { get; set; } - public DbSet AutoCommands { get; set; } - + public DbSet AutoCommands { get; set; } public DbSet RewardedUsers { get; set; } public DbSet PlantedCurrency { get; set; } public DbSet BanTemplates { get; set; } diff --git a/src/NadekoBot/GlobalUsings.cs b/src/NadekoBot/GlobalUsings.cs index 2d4e52403..8ea69a8f5 100644 --- a/src/NadekoBot/GlobalUsings.cs +++ b/src/NadekoBot/GlobalUsings.cs @@ -16,5 +16,8 @@ global using Discord.WebSocket; global using GuildPerm = Discord.GuildPermission; global using ChannelPerm = Discord.ChannelPermission; global using BotPermAttribute = Discord.Commands.RequireBotPermissionAttribute; +global using LeftoverAttribute = Discord.Commands.RemainderAttribute; -global using System.Collections.Concurrent; \ No newline at end of file +global using System.Collections.Concurrent; + +global using JetBrains.Annotations; \ No newline at end of file diff --git a/src/NadekoBot/Modules/Administration/RoleCommands.cs b/src/NadekoBot/Modules/Administration/RoleCommands.cs index e0988b298..eb5637a1f 100644 --- a/src/NadekoBot/Modules/Administration/RoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/RoleCommands.cs @@ -28,7 +28,6 @@ public partial class Administration if (input.Length % 2 != 0) return; - var grp = 0; var results = input .Chunk(input.Length / 2) .Select(async x => diff --git a/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs index d366b1c1f..72e07387c 100644 --- a/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs @@ -58,7 +58,7 @@ public partial class Searches fs.Type)); } - [NadekoCommand, Usage, Description, Aliases] + [NadekoCommand, Aliases] [RequireContext(ContextType.Guild)] [UserPerm(GuildPerm.Administrator)] public async Task StreamsClear() diff --git a/src/NadekoBot/NadekoBot.csproj b/src/NadekoBot/NadekoBot.csproj index 718282f10..baf7ac12d 100644 --- a/src/NadekoBot/NadekoBot.csproj +++ b/src/NadekoBot/NadekoBot.csproj @@ -54,6 +54,7 @@ +