diff --git a/src/NadekoBot/Bot.cs b/src/NadekoBot/Bot.cs index 67e72fd20..4510110d0 100644 --- a/src/NadekoBot/Bot.cs +++ b/src/NadekoBot/Bot.cs @@ -80,10 +80,10 @@ public sealed class Bot : IBot // _interactionService = new(Client.Rest); Client.Log += Client_Log; - _loadedAssemblies = new[] - { - typeof(Bot).Assembly, // bot - }; + _loadedAssemblies = + [ + typeof(Bot).Assembly // bot + ]; } diff --git a/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs b/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs index db6b3f734..fe9127988 100644 --- a/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs +++ b/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs @@ -7,19 +7,20 @@ namespace NadekoBot.Db; public static class GuildConfigExtensions { private static List DefaultWarnPunishments - => new() - { + => + [ new() { Count = 3, Punishment = PunishmentAction.Kick }, + new() { Count = 5, Punishment = PunishmentAction.Ban } - }; + ]; /// /// Gets full stream role settings for the guild with the specified id. diff --git a/src/NadekoBot/Db/Models/Permission.cs b/src/NadekoBot/Db/Models/Permission.cs index f6b36dbfd..37dfdcb30 100644 --- a/src/NadekoBot/Db/Models/Permission.cs +++ b/src/NadekoBot/Db/Models/Permission.cs @@ -33,10 +33,7 @@ public class Permissionv2 : DbEntity, IIndexed }; public static List GetDefaultPermlist - => new() - { - AllowAllPerm - }; + => [AllowAllPerm]; } public enum PrimaryPermissionType diff --git a/src/NadekoBot/Modules/Administration/GreetBye/GreetService.cs b/src/NadekoBot/Modules/Administration/GreetBye/GreetService.cs index ffde60a84..c1aa564b9 100644 --- a/src/NadekoBot/Modules/Administration/GreetBye/GreetService.cs +++ b/src/NadekoBot/Modules/Administration/GreetBye/GreetService.cs @@ -319,13 +319,13 @@ public class GreetService : INService, IReadyExecutor // if there are no embeds, add an embed with the footer smartText = seta with { - Embeds = new[] - { + Embeds = + [ new SmartEmbedArrayElementText() { Footer = CreateFooterSource(user) } - } + ] }; } else diff --git a/src/NadekoBot/Modules/Administration/Role/ReactionRolesService.cs b/src/NadekoBot/Modules/Administration/Role/ReactionRolesService.cs index 91b64d488..0d8bab39e 100644 --- a/src/NadekoBot/Modules/Administration/Role/ReactionRolesService.cs +++ b/src/NadekoBot/Modules/Administration/Role/ReactionRolesService.cs @@ -305,10 +305,7 @@ public sealed class ReactionRolesService : IReadyExecutor, INService, IReactionR lock (_cacheLock) { _cache.AddOrUpdate(msg.Id, - _ => new() - { - obj - }, + _ => [obj], (_, list) => { list.RemoveAll(x => x.Emote == emote); diff --git a/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommandService.cs b/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommandService.cs index 18d117959..d09d0e18d 100644 --- a/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommandService.cs +++ b/src/NadekoBot/Modules/Administration/ServerLog/ServerLogCommandService.cs @@ -24,7 +24,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor private readonly GuildTimezoneService _tz; private readonly IMemoryCache _memoryCache; - private readonly ConcurrentHashSet _ignoreMessageIds = new(); + private readonly ConcurrentHashSet _ignoreMessageIds = []; private readonly UserPunishService _punishService; private readonly IMessageSenderService _sender; @@ -115,10 +115,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor strs.user_status_change("👤" + Format.Bold(gu.Username), Format.Bold(after.Status.ToString()))); PresenceUpdates.AddOrUpdate(logChannel, - new List - { - str - }, + [str], (_, list) => { list.Add(str); @@ -130,10 +127,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor var str = $"👾`{PrettyCurrentTime(gu.Guild)}`👤__**{gu.Username}**__ is now playing **{after.Activities.FirstOrDefault()?.Name ?? "-"}**."; PresenceUpdates.AddOrUpdate(logChannel, - new List - { - str - }, + [str], (_, list) => { list.Add(str); @@ -881,10 +875,7 @@ public sealed class LogCommandService : ILogCommandService, IReadyExecutor if (!string.IsNullOrWhiteSpace(str)) { PresenceUpdates.AddOrUpdate(logChannel, - new List - { - str - }, + [str], (_, list) => { list.Add(str); diff --git a/src/NadekoBot/Modules/Expressions/NadekoExpressionsService.cs b/src/NadekoBot/Modules/Expressions/NadekoExpressionsService.cs index 6056f2e80..c3f3ac667 100644 --- a/src/NadekoBot/Modules/Expressions/NadekoExpressionsService.cs +++ b/src/NadekoBot/Modules/Expressions/NadekoExpressionsService.cs @@ -356,7 +356,7 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor if (maybeGuildId is { } guildId) { newguildExpressions.AddOrUpdate(guildId, - new[] { expr }, + [expr], (_, old) => { var newArray = old.ToArray(); @@ -389,7 +389,7 @@ public sealed class NadekoExpressionsService : IExecOnMessage, IReadyExecutor expr.Trigger = expr.Trigger.Replace(MENTION_PH, _client.CurrentUser.Mention); if (maybeGuildId is { } guildId) - newguildExpressions.AddOrUpdate(guildId, new[] { expr }, (_, old) => old.With(expr)); + newguildExpressions.AddOrUpdate(guildId, [expr], (_, old) => old.With(expr)); else return _pubSub.Pub(_gexprAddedKey, expr); diff --git a/src/NadekoBot/Modules/Gambling/Connect4/Connect4Commands.cs b/src/NadekoBot/Modules/Gambling/Connect4/Connect4Commands.cs index d405fec9b..c46343a82 100644 --- a/src/NadekoBot/Modules/Gambling/Connect4/Connect4Commands.cs +++ b/src/NadekoBot/Modules/Gambling/Connect4/Connect4Commands.cs @@ -12,9 +12,9 @@ public partial class Gambling public partial class Connect4Commands : GamblingSubmodule { private static readonly string[] _numbers = - { + [ ":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:" - }; + ]; private int RepostCounter { diff --git a/src/NadekoBot/Modules/Gambling/DiceRoll/DiceRollCommands.cs b/src/NadekoBot/Modules/Gambling/DiceRoll/DiceRollCommands.cs index 2ffeeae28..f10870cd7 100644 --- a/src/NadekoBot/Modules/Gambling/DiceRoll/DiceRollCommands.cs +++ b/src/NadekoBot/Modules/Gambling/DiceRoll/DiceRollCommands.cs @@ -16,7 +16,7 @@ public partial class Gambling private static readonly Regex _fudgeRegex = new(@"^(?\d+)d(?:F|f)$", RegexOptions.Compiled); - private static readonly char[] _fateRolls = { '-', ' ', '+' }; + private static readonly char[] _fateRolls = ['-', ' ', '+']; private readonly IImageCache _images; public DiceRollCommands(IImageCache images) diff --git a/src/NadekoBot/Modules/Gambling/GamblingConfig.cs b/src/NadekoBot/Modules/Gambling/GamblingConfig.cs index 90385f0b9..2f5f418c6 100644 --- a/src/NadekoBot/Modules/Gambling/GamblingConfig.cs +++ b/src/NadekoBot/Modules/Gambling/GamblingConfig.cs @@ -131,8 +131,8 @@ public partial class BetRollConfig public BetRollPair[] Pairs { get; set; } = Array.Empty(); public BetRollConfig() - => Pairs = new BetRollPair[] - { + => Pairs = + [ new() { WhenAbove = 99, @@ -148,7 +148,7 @@ public partial class BetRollConfig WhenAbove = 66, MultiplyBy = 2 } - }; + ]; } [Cloneable] @@ -207,7 +207,7 @@ public partial class LuckyLadderSettings public decimal[] Multipliers { get; set; } public LuckyLadderSettings() - => Multipliers = new[] { 2.4M, 1.7M, 1.5M, 1.2M, 0.5M, 0.3M, 0.2M, 0.1M }; + => Multipliers = [2.4M, 1.7M, 1.5M, 1.2M, 0.5M, 0.3M, 0.2M, 0.1M]; } [Cloneable] @@ -228,11 +228,11 @@ public sealed partial class WaifuConfig List of items available for gifting. If negative is true, gift will instead reduce waifu value. """)] - public List Items { get; set; } = new(); + public List Items { get; set; } = []; public WaifuConfig() - => Items = new() - { + => Items = + [ new("🥔", 5, "Potato"), new("🍪", 10, "Cookie"), new("🥖", 20, "Bread"), @@ -269,7 +269,7 @@ public sealed partial class WaifuConfig new("🚁", 20000, "Helicopter"), new("🚀", 30000, "Spaceship"), new("🌕", 50000, "Moon") - }; + ]; public class WaifuDecayConfig { diff --git a/src/NadekoBot/Modules/Gambling/Waifus/db/WaifuExtensions.cs b/src/NadekoBot/Modules/Gambling/Waifus/db/WaifuExtensions.cs index c4892aa36..e5fabb663 100644 --- a/src/NadekoBot/Modules/Gambling/Waifus/db/WaifuExtensions.cs +++ b/src/NadekoBot/Modules/Gambling/Waifus/db/WaifuExtensions.cs @@ -28,9 +28,9 @@ public static class WaifuExtensions public static IEnumerable GetTop(this DbSet waifus, int count, int skip = 0) { ArgumentOutOfRangeException.ThrowIfNegative(count); - + if (count == 0) - return new List(); + return []; return waifus.Include(wi => wi.Waifu) .Include(wi => wi.Affinity) diff --git a/src/NadekoBot/Modules/Games/Acrophobia/Acrophobia.cs b/src/NadekoBot/Modules/Games/Acrophobia/Acrophobia.cs index 8e6ac0ec1..212944cac 100644 --- a/src/NadekoBot/Modules/Games/Acrophobia/Acrophobia.cs +++ b/src/NadekoBot/Modules/Games/Acrophobia/Acrophobia.cs @@ -42,7 +42,7 @@ public sealed class AcrophobiaGame : IDisposable private readonly SemaphoreSlim _locker = new(1, 1); private readonly NadekoRandom _rng; - private readonly HashSet _usersWhoVoted = new(); + private readonly HashSet _usersWhoVoted = []; public AcrophobiaGame(Options options) { diff --git a/src/NadekoBot/Modules/Games/GamesConfig.cs b/src/NadekoBot/Modules/Games/GamesConfig.cs index 7d76c6056..7996a3f9b 100644 --- a/src/NadekoBot/Modules/Games/GamesConfig.cs +++ b/src/NadekoBot/Modules/Games/GamesConfig.cs @@ -24,8 +24,8 @@ public sealed partial class GamesConfig : ICloneable }; [Comment("List of responses for the .8ball command. A random one will be selected every time")] - public List EightBallResponses { get; set; } = new() - { + public List EightBallResponses { get; set; } = + [ "Most definitely yes.", "For sure.", "Totally!", @@ -49,52 +49,59 @@ public sealed partial class GamesConfig : ICloneable "Don't even think about it.", "Definitely no.", "NO - It may cause disease contraction!" - }; + ]; [Comment("List of animals which will be used for the animal race game (.race)")] - public List RaceAnimals { get; set; } = new() - { + public List RaceAnimals { get; set; } = + [ new() { Icon = "🐼", Name = "Panda" }, + new() { Icon = "🐻", Name = "Bear" }, + new() { Icon = "🐧", Name = "Pengu" }, + new() { Icon = "🐨", Name = "Koala" }, + new() { Icon = "🐬", Name = "Dolphin" }, + new() { Icon = "🐞", Name = "Ladybird" }, + new() { Icon = "🦀", Name = "Crab" }, + new() { Icon = "🦄", Name = "Unicorn" } - }; + ]; [Comment(@"Which chatbot API should bot use. 'cleverbot' - bot will use Cleverbot API. diff --git a/src/NadekoBot/Modules/Games/Nunchi/Nunchi.cs b/src/NadekoBot/Modules/Games/Nunchi/Nunchi.cs index c47803bac..48fa4ef47 100644 --- a/src/NadekoBot/Modules/Games/Nunchi/Nunchi.cs +++ b/src/NadekoBot/Modules/Games/Nunchi/Nunchi.cs @@ -33,8 +33,8 @@ public sealed class NunchiGame : IDisposable private readonly SemaphoreSlim _locker = new(1, 1); - private HashSet<(ulong Id, string Name)> participants = new(); - private readonly HashSet<(ulong Id, string Name)> _passed = new(); + private HashSet<(ulong Id, string Name)> participants = []; + private readonly HashSet<(ulong Id, string Name)> _passed = []; private Timer killTimer; public NunchiGame(ulong creatorId, string creatorName) diff --git a/src/NadekoBot/Modules/Games/TicTacToe/TicTacToe.cs b/src/NadekoBot/Modules/Games/TicTacToe/TicTacToe.cs index e73f708c8..c5e0316f4 100644 --- a/src/NadekoBot/Modules/Games/TicTacToe/TicTacToe.cs +++ b/src/NadekoBot/Modules/Games/TicTacToe/TicTacToe.cs @@ -17,9 +17,9 @@ public class TicTacToe private IGuildUser winner; private readonly string[] _numbers = - { + [ ":one:", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:" - }; + ]; private IUserMessage previousMessage; private Timer timeoutTimer; @@ -42,7 +42,7 @@ public class TicTacToe _options = options; _sender = sender; - _users = new[] { firstUser, null }; + _users = [firstUser, null]; _state = new int?[,] { { null, null, null }, { null, null, null }, { null, null, null } }; phase = Phase.Starting; diff --git a/src/NadekoBot/Modules/Games/Trivia/TriviaQuestion.cs b/src/NadekoBot/Modules/Games/Trivia/TriviaQuestion.cs index b6cb1fe13..14bcdbe7a 100644 --- a/src/NadekoBot/Modules/Games/Trivia/TriviaQuestion.cs +++ b/src/NadekoBot/Modules/Games/Trivia/TriviaQuestion.cs @@ -9,13 +9,13 @@ public class TriviaQuestion public const int MAX_STRING_LENGTH = 22; //represents the min size to judge levDistance with - private static readonly HashSet> _strictness = new() - { + private static readonly HashSet> _strictness = + [ new(9, 0), new(14, 1), new(19, 2), new(22, 3) - }; + ]; public string Category => _qModel.Category; diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 593bec27f..458749cc9 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -249,13 +249,16 @@ public sealed partial class Help : NadekoModule var succ = new HashSet(); if (opts.View != CommandsOptions.ViewType.All) { - succ = new((await cmds.Select(async x => - { - var pre = await x.CheckPreconditionsAsync(Context, _services); - return (Cmd: x, Succ: pre.IsSuccess); - }) - .WhenAll()).Where(x => x.Succ) - .Select(x => x.Cmd)); + succ = + [ + ..(await cmds.Select(async x => + { + var pre = await x.CheckPreconditionsAsync(Context, _services); + return (Cmd: x, Succ: pre.IsSuccess); + }) + .WhenAll()).Where(x => x.Succ) + .Select(x => x.Cmd) + ]; if (opts.View == CommandsOptions.ViewType.Hide) // if hidden is specified, completely remove these commands from the list diff --git a/src/NadekoBot/Modules/Medusae/MedusaeRepositoryService.cs b/src/NadekoBot/Modules/Medusae/MedusaeRepositoryService.cs index 08c4be005..d7cc96c4b 100644 --- a/src/NadekoBot/Modules/Medusae/MedusaeRepositoryService.cs +++ b/src/NadekoBot/Modules/Medusae/MedusaeRepositoryService.cs @@ -6,17 +6,62 @@ public class MedusaeRepositoryService : IMedusaeRepositoryService, INService { // Simulate retrieving data from a database or API await Task.Delay(100); - return new List - { - new ModuleItem { Name = "RSS Reader", Description = "Keep up to date with your favorite websites", Command = ".meinstall rss" }, - new ModuleItem { Name = "Password Manager", Description = "Safely store and manage all your passwords", Command = ".meinstall passwordmanager" }, - new ModuleItem { Name = "Browser Extension", Description = "Enhance your browsing experience with useful tools", Command = ".meinstall browserextension" }, - new ModuleItem { Name = "Video Downloader", Description = "Download videos from popular websites", Command = ".meinstall videodownloader" }, - new ModuleItem { Name = "Virtual Private Network", Description = "Securely browse the web and protect your privacy", Command = ".meinstall vpn" }, - new ModuleItem { Name = "Ad Blocker", Description = "Block annoying ads and improve page load times", Command = ".meinstall adblocker" }, - new ModuleItem { Name = "Cloud Storage", Description = "Store and share your files online", Command = ".meinstall cloudstorage" }, - new ModuleItem { Name = "Social Media Manager", Description = "Manage all your social media accounts in one place", Command = ".meinstall socialmediamanager" }, - new ModuleItem { Name = "Code Editor", Description = "Write and edit code online", Command = ".meinstall codeeditor" } - }; + return + [ + new() + { + Name = "RSS Reader", + Description = "Keep up to date with your favorite websites", + Command = ".meinstall rss" + }, + new() + { + Name = "Password Manager", + Description = "Safely store and manage all your passwords", + Command = ".meinstall passwordmanager" + }, + new() + { + Name = "Browser Extension", + Description = "Enhance your browsing experience with useful tools", + Command = ".meinstall browserextension" + }, + new() + { + Name = "Video Downloader", + Description = "Download videos from popular websites", + Command = ".meinstall videodownloader" + }, + new() + { + Name = "Virtual Private Network", + Description = "Securely browse the web and protect your privacy", + Command = ".meinstall vpn" + }, + new() + { + Name = "Ad Blocker", + Description = "Block annoying ads and improve page load times", + Command = ".meinstall adblocker" + }, + new() + { + Name = "Cloud Storage", + Description = "Store and share your files online", + Command = ".meinstall cloudstorage" + }, + new() + { + Name = "Social Media Manager", + Description = "Manage all your social media accounts in one place", + Command = ".meinstall socialmediamanager" + }, + new() + { + Name = "Code Editor", + Description = "Write and edit code online", + Command = ".meinstall codeeditor" + } + ]; } } \ No newline at end of file diff --git a/src/NadekoBot/Modules/Music/Services/AyuVoiceStateService.cs b/src/NadekoBot/Modules/Music/Services/AyuVoiceStateService.cs index a33925a8d..58ac050ab 100644 --- a/src/NadekoBot/Modules/Music/Services/AyuVoiceStateService.cs +++ b/src/NadekoBot/Modules/Music/Services/AyuVoiceStateService.cs @@ -28,11 +28,10 @@ public sealed class AyuVoiceStateService : INService _dnetApiClient = prop.GetValue(_client, null); _sendVoiceStateUpdateMethodInfo = _dnetApiClient.GetType() .GetMethod("SendVoiceStateUpdateAsync", - new[] - { - typeof(ulong), typeof(ulong?), typeof(bool), + [ + typeof(ulong), typeof(ulong?), typeof(bool), typeof(bool), typeof(RequestOptions) - }); + ]); _client.LeftGuild += ClientOnLeftGuild; } @@ -55,7 +54,7 @@ public sealed class AyuVoiceStateService : INService bool isMuted = false) // return _voiceStateUpdate(guildId, channelId, isDeafened, isMuted); => (Task)_sendVoiceStateUpdateMethodInfo.Invoke(_dnetApiClient, - new object[] { guildId, channelId, isMuted, isDeafened, null }); + [guildId, channelId, isMuted, isDeafened, null]); private Task SendLeaveVoiceChannelInternalAsync(ulong guildId) => InvokeSendVoiceStateUpdateAsync(guildId); diff --git a/src/NadekoBot/Modules/Music/Services/extractor/YtLoader.cs b/src/NadekoBot/Modules/Music/Services/extractor/YtLoader.cs index 7a581f383..1790ccc21 100644 --- a/src/NadekoBot/Modules/Music/Services/extractor/YtLoader.cs +++ b/src/NadekoBot/Modules/Music/Services/extractor/YtLoader.cs @@ -11,9 +11,9 @@ public sealed partial class YtLoader : INService private static readonly byte[] _ytResultJsonEnd = Encoding.UTF8.GetBytes(";<"); private static readonly string[] _durationFormats = - { + [ @"m\:ss", @"mm\:ss", @"h\:mm\:ss", @"hh\:mm\:ss", @"hhh\:mm\:ss" - }; + ]; private readonly IHttpClientFactory _httpFactory; diff --git a/src/NadekoBot/Modules/Music/_common/Resolvers/YtdlYoutubeResolver.cs b/src/NadekoBot/Modules/Music/_common/Resolvers/YtdlYoutubeResolver.cs index f529da19b..741f8a004 100644 --- a/src/NadekoBot/Modules/Music/_common/Resolvers/YtdlYoutubeResolver.cs +++ b/src/NadekoBot/Modules/Music/_common/Resolvers/YtdlYoutubeResolver.cs @@ -7,9 +7,9 @@ namespace NadekoBot.Modules.Music; public sealed class YtdlYoutubeResolver : IYoutubeResolver { private static readonly string[] _durationFormats = - { + [ "ss", "m\\:ss", "mm\\:ss", "h\\:mm\\:ss", "hh\\:mm\\:ss", "hhh\\:mm\\:ss" - }; + ]; private static readonly Regex _expiryRegex = new(@"(?:[\?\&]expire\=(?\d+))"); diff --git a/src/NadekoBot/Modules/Searches/Anime/AnimeSearchCommands.cs b/src/NadekoBot/Modules/Searches/Anime/AnimeSearchCommands.cs index c9338091c..219992688 100644 --- a/src/NadekoBot/Modules/Searches/Anime/AnimeSearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/Anime/AnimeSearchCommands.cs @@ -162,7 +162,7 @@ public partial class Searches .AddField(GetText(strs.episodes), animeData.TotalEpisodes.ToString(), true) .AddField(GetText(strs.status), animeData.AiringStatus, true) .AddField(GetText(strs.genres), - string.Join(",\n", animeData.Genres.Any() ? animeData.Genres : new[] { "none" }), + string.Join(",\n", animeData.Genres.Any() ? animeData.Genres : ["none"]), true) .WithFooter($"{GetText(strs.score)} {animeData.AverageScore} / 100"); await Response().Embed(embed).SendAsync(); @@ -194,7 +194,7 @@ public partial class Searches .AddField(GetText(strs.chapters), mangaData.TotalChapters.ToString(), true) .AddField(GetText(strs.status), mangaData.PublishingStatus, true) .AddField(GetText(strs.genres), - string.Join(",\n", mangaData.Genres.Any() ? mangaData.Genres : new[] { "none" }), + string.Join(",\n", mangaData.Genres.Any() ? mangaData.Genres : ["none"]), true) .WithFooter($"{GetText(strs.score)} {mangaData.AverageScore} / 100"); diff --git a/src/NadekoBot/Modules/Searches/Feeds/FeedsService.cs b/src/NadekoBot/Modules/Searches/Feeds/FeedsService.cs index d934dc3c9..5444a2022 100644 --- a/src/NadekoBot/Modules/Searches/Feeds/FeedsService.cs +++ b/src/NadekoBot/Modules/Searches/Feeds/FeedsService.cs @@ -247,10 +247,7 @@ public class FeedsService : INService foreach (var feed in gc.FeedSubs) { _subs.AddOrUpdate(feed.Url.ToLower(), - new List - { - feed - }, + [feed], (_, old) => { old.Add(feed); @@ -275,7 +272,7 @@ public class FeedsService : INService return false; var toRemove = items[index]; _subs.AddOrUpdate(toRemove.Url.ToLower(), - new List(), + [], (_, old) => { old.Remove(toRemove); diff --git a/src/NadekoBot/Modules/Searches/SearchesService.cs b/src/NadekoBot/Modules/Searches/SearchesService.cs index f02a1bdd6..7aa12e06b 100644 --- a/src/NadekoBot/Modules/Searches/SearchesService.cs +++ b/src/NadekoBot/Modules/Searches/SearchesService.cs @@ -23,8 +23,8 @@ public class SearchesService : INService Birds } - public List WowJokes { get; } = new(); - public List MagicItems { get; } = new(); + public List WowJokes { get; } = []; + public List MagicItems { get; } = []; private readonly IHttpClientFactory _httpFactory; private readonly IGoogleApiService _google; private readonly IImageCache _imgs; @@ -68,7 +68,7 @@ public class SearchesService : INService _yomamaJokes = File.ReadAllLines("data/yomama.txt").Shuffle().ToList(); else { - _yomamaJokes = new(); + _yomamaJokes = []; Log.Warning("data/yomama.txt is missing. .yomama command won't work"); } } diff --git a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs index 3671ae45f..9f8ac251e 100644 --- a/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs +++ b/src/NadekoBot/Modules/Searches/StreamNotification/StreamNotificationService.cs @@ -202,10 +202,7 @@ public sealed class StreamNotificationService : INService, IReadyExecutor _trackCounter[key].Add(info.GuildId); else { - _trackCounter[key] = new() - { - info.GuildId - }; + _trackCounter[key] = [info.GuildId]; } } @@ -572,12 +569,12 @@ public sealed class StreamNotificationService : INService, IReadyExecutor { if (map.TryGetValue(guildId, out var set)) return set; - return map[guildId] = new(); + return map[guildId] = []; } _shardTrackedStreams[key] = new() { - { guildId, new() } + { guildId, [] } }; return _shardTrackedStreams[key][guildId]; } diff --git a/src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/PicartoProvider.cs b/src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/PicartoProvider.cs index f56b09e9e..754bb780f 100644 --- a/src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/PicartoProvider.cs +++ b/src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/PicartoProvider.cs @@ -41,10 +41,7 @@ public class PicartoProvider : Provider public override async Task GetStreamDataAsync(string login) { - var data = await GetStreamDataAsync(new List - { - login - }); + var data = await GetStreamDataAsync([login]); return data.FirstOrDefault(); } @@ -52,7 +49,7 @@ public class PicartoProvider : Provider public override async Task> GetStreamDataAsync(List logins) { if (logins.Count == 0) - return new List(); + return []; using var http = _httpClientFactory.CreateClient(); var toReturn = new List(); diff --git a/src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/TwitchHelixProvider.cs b/src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/TwitchHelixProvider.cs index c758cb0c1..643fa7ba4 100644 --- a/src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/TwitchHelixProvider.cs +++ b/src/NadekoBot/Modules/Searches/_common/StreamNotifications/Providers/TwitchHelixProvider.cs @@ -66,10 +66,7 @@ public sealed class TwitchHelixProvider : Provider public override async Task GetStreamDataAsync(string login) { - var data = await GetStreamDataAsync(new List - { - login - }); + var data = await GetStreamDataAsync([login]); return data.FirstOrDefault(); } @@ -125,7 +122,7 @@ public sealed class TwitchHelixProvider : Provider catch (Exception ex) { Log.Warning(ex, "Something went wrong retreiving {StreamPlatform} streams", Platform); - return new List(); + return []; } } @@ -163,7 +160,7 @@ public sealed class TwitchHelixProvider : Provider catch (Exception ex) { Log.Warning(ex, "Something went wrong retreiving {StreamPlatform} streams", Platform); - return new List(); + return []; } } diff --git a/src/NadekoBot/Modules/Utility/UnitConversion/ConverterService.cs b/src/NadekoBot/Modules/Utility/UnitConversion/ConverterService.cs index 69b4345bf..c6b748741 100644 --- a/src/NadekoBot/Modules/Utility/UnitConversion/ConverterService.cs +++ b/src/NadekoBot/Modules/Utility/UnitConversion/ConverterService.cs @@ -58,13 +58,13 @@ public class ConverterService : INService, IReadyExecutor var currencyRates = await GetCurrencyRates(); var baseType = new ConvertUnit { - Triggers = new[] { currencyRates.Base }, + Triggers = [currencyRates.Base], Modifier = decimal.One, UnitType = unitTypeString }; var units = currencyRates.ConversionRates.Select(u => new ConvertUnit { - Triggers = new[] { u.Key }, + Triggers = [u.Key], Modifier = u.Value, UnitType = unitTypeString }) diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 6745c2297..5a43cc904 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -480,7 +480,7 @@ public partial class Utility : NadekoModule try { if (tags.Length == 0) - tags = new[] { name }; + tags = [name]; await ctx.Guild.CreateStickerAsync( name, diff --git a/src/NadekoBot/Services/Impl/Localization.cs b/src/NadekoBot/Services/Impl/Localization.cs index 983e7067c..4fec3559f 100644 --- a/src/NadekoBot/Services/Impl/Localization.cs +++ b/src/NadekoBot/Services/Impl/Localization.cs @@ -112,7 +112,7 @@ public class Localization : ILocalization { Cmd = key, Desc = key, - Usage = new[] { key } + Usage = [key] }; } diff --git a/src/NadekoBot/Services/Impl/RedisBotCache.cs b/src/NadekoBot/Services/Impl/RedisBotCache.cs index 41f84b2d2..2797aefbd 100644 --- a/src/NadekoBot/Services/Impl/RedisBotCache.cs +++ b/src/NadekoBot/Services/Impl/RedisBotCache.cs @@ -8,13 +8,13 @@ namespace NadekoBot.Common; public sealed class RedisBotCache : IBotCache { - private static readonly Type[] _supportedTypes = new [] - { + private static readonly Type[] _supportedTypes = + [ typeof(bool), typeof(int), typeof(uint), typeof(long), typeof(ulong), typeof(float), typeof(double), typeof(string), typeof(byte[]), typeof(ReadOnlyMemory), typeof(Memory), - typeof(RedisValue), - }; + typeof(RedisValue) + ]; private static readonly JsonSerializerOptions _opts = new() { diff --git a/src/NadekoBot/_common/Abstractions/Extensions/StringExtensions.cs b/src/NadekoBot/_common/Abstractions/Extensions/StringExtensions.cs index bc17d154e..a3e770e0c 100644 --- a/src/NadekoBot/_common/Abstractions/Extensions/StringExtensions.cs +++ b/src/NadekoBot/_common/Abstractions/Extensions/StringExtensions.cs @@ -6,10 +6,13 @@ namespace NadekoBot.Extensions; public static class StringExtensions { - private static readonly HashSet _lettersAndDigits = new(Enumerable.Range(48, 10) - .Concat(Enumerable.Range(65, 26)) - .Concat(Enumerable.Range(97, 26)) - .Select(x => (char)x)); + private static readonly HashSet _lettersAndDigits = + [ + ..Enumerable.Range(48, 10) + .Concat(Enumerable.Range(65, 26)) + .Concat(Enumerable.Range(97, 26)) + .Select(x => (char)x) + ]; private static readonly Regex _filterRegex = new(@"discord(?:\.gg|\.io|\.me|\.li|(?:app)?\.com\/invite)\/(\w+)", RegexOptions.Compiled | RegexOptions.IgnoreCase); @@ -43,7 +46,7 @@ public static class StringExtensions public static string ToTitleCase(this string str) { - var tokens = str.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); + var tokens = str.Split([" "], StringSplitOptions.RemoveEmptyEntries); for (var i = 0; i < tokens.Length; i++) { var token = tokens[i]; diff --git a/src/NadekoBot/_common/Configs/BotConfig.cs b/src/NadekoBot/_common/Configs/BotConfig.cs index 6bb655a7f..6f526cf4f 100644 --- a/src/NadekoBot/_common/Configs/BotConfig.cs +++ b/src/NadekoBot/_common/Configs/BotConfig.cs @@ -146,14 +146,14 @@ public sealed partial class BotConfig : ICloneable Prefix = "."; RotateStatuses = false; GroupGreets = false; - DmHelpTextKeywords = new() - { + DmHelpTextKeywords = + [ "help", "commands", "cmds", "module", "can you do" - }; + ]; } // [Comment(@"Whether the prefix will be a suffix, or prefix. @@ -178,8 +178,8 @@ public sealed partial class BlockedConfig public BlockedConfig() { - Modules = new(); - Commands = new(); + Modules = []; + Commands = []; } } diff --git a/src/NadekoBot/_common/Deck/Deck.cs b/src/NadekoBot/_common/Deck/Deck.cs index 930f47d30..58747d88b 100644 --- a/src/NadekoBot/_common/Deck/Deck.cs +++ b/src/NadekoBot/_common/Deck/Deck.cs @@ -259,10 +259,10 @@ public class Deck } private readonly string[] _regIndicators = - { + [ "🇦", ":two:", ":three:", ":four:", ":five:", ":six:", ":seven:", ":eight:", ":nine:", ":keycap_ten:", "🇯", "🇶", "🇰" - }; + ]; public Card(CardSuit s, int cardNum) { diff --git a/src/NadekoBot/_common/Medusa/Common/MedusaIoCKernelModule.cs b/src/NadekoBot/_common/Medusa/Common/MedusaIoCKernelModule.cs index 3a1d7827d..2cf91b15b 100644 --- a/src/NadekoBot/_common/Medusa/Common/MedusaIoCKernelModule.cs +++ b/src/NadekoBot/_common/Medusa/Common/MedusaIoCKernelModule.cs @@ -64,7 +64,7 @@ public sealed class MedusaNinjectIocModule : IIocModule, IDisposable var assembly = typeof(JsonSerializerOptions).Assembly; var updateHandlerType = assembly.GetType("System.Text.Json.JsonSerializerOptionsUpdateHandler"); var clearCacheMethod = updateHandlerType?.GetMethod("ClearCache", BindingFlags.Static | BindingFlags.Public); - clearCacheMethod?.Invoke(null, new object?[] { null }); + clearCacheMethod?.Invoke(null, [null]); isLoaded = false; } diff --git a/src/NadekoBot/_common/Medusa/Common/MedusaLoaderService.cs b/src/NadekoBot/_common/Medusa/Common/MedusaLoaderService.cs index 9b6697afc..9fb38dd01 100644 --- a/src/NadekoBot/_common/Medusa/Common/MedusaLoaderService.cs +++ b/src/NadekoBot/_common/Medusa/Common/MedusaLoaderService.cs @@ -140,7 +140,7 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor, => alias.Equals(commandName, StringComparison.InvariantCultureIgnoreCase))) ?.OptionalStrings .Args - ?? new[] { string.Empty }; + ?? [string.Empty]; } public Task ReloadStrings() @@ -375,7 +375,7 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor, var targetType = parserType.BaseType!.GetGenericArguments()[0]; var typeReaderInstance = (TypeReader)Activator.CreateInstance( typeof(ParamParserAdapter<>).MakeGenericType(targetType), - args: new[] { parserObj, strings, _cont })!; + args: [parserObj, strings, _cont])!; typeReaders.Add(targetType, typeReaderInstance); } @@ -888,7 +888,7 @@ public sealed class MedusaLoaderService : IMedusaLoaderService, IReadyExecutor, var cmdAttribute = method.GetCustomAttribute(true)!; var aliases = cmdAttribute.Aliases; if (aliases.Length == 0) - aliases = new[] { method.Name.ToLowerInvariant() }; + aliases = [method.Name.ToLowerInvariant()]; cmds.Add(new( aliases, diff --git a/src/NadekoBot/_common/Services/strings/impl/BotStrings.cs b/src/NadekoBot/_common/Services/strings/impl/BotStrings.cs index 3daebc99c..7f024ed14 100644 --- a/src/NadekoBot/_common/Services/strings/impl/BotStrings.cs +++ b/src/NadekoBot/_common/Services/strings/impl/BotStrings.cs @@ -81,7 +81,7 @@ public class BotStrings : IBotStrings return new CommandStrings() { - Examples = new[] { "" }, + Examples = [""], Desc = "?", Params = [] }; diff --git a/src/NadekoBot/_common/Yml/MultilineScalarFlowStyleEmitter.cs b/src/NadekoBot/_common/Yml/MultilineScalarFlowStyleEmitter.cs index 52c015dc4..6180d7be7 100644 --- a/src/NadekoBot/_common/Yml/MultilineScalarFlowStyleEmitter.cs +++ b/src/NadekoBot/_common/Yml/MultilineScalarFlowStyleEmitter.cs @@ -19,7 +19,7 @@ public class MultilineScalarFlowStyleEmitter : ChainedEventEmitter var value = eventInfo.Source.Value as string; if (!string.IsNullOrEmpty(value)) { - var isMultiLine = value.IndexOfAny(new[] { '\r', '\n', '\x85', '\x2028', '\x2029' }) >= 0; + var isMultiLine = value.IndexOfAny(['\r', '\n', '\x85', '\x2028', '\x2029']) >= 0; if (isMultiLine) { eventInfo = new(eventInfo.Source)