From 74e32dee9b245d1afe6d32b642b149fbfabf3e2c Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Wed, 20 Dec 2023 21:23:37 +0500 Subject: [PATCH 1/3] Use collection expressions in more places (#238) ReSharper inspections have been updated, causing new warnings to appear in the codebase. This time, the "Use collection expressions" inspection has been enabled for usecases where the collection is not empty. This PR fixes the check failures caused by this inspection. --- src/Commands/AboutCommandGroup.cs | 4 ++-- src/Commands/SettingsCommandGroup.cs | 4 ++-- src/Commands/ToolsCommandGroup.cs | 4 ++-- src/Services/Update/MemberUpdateService.cs | 4 ++-- src/Services/Update/SongUpdateService.cs | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Commands/AboutCommandGroup.cs b/src/Commands/AboutCommandGroup.cs index eec1f99..1c2656b 100644 --- a/src/Commands/AboutCommandGroup.cs +++ b/src/Commands/AboutCommandGroup.cs @@ -28,11 +28,11 @@ namespace Octobot.Commands; public class AboutCommandGroup : CommandGroup { private static readonly (string Username, Snowflake Id)[] Developers = - { + [ ("Octol1ttle", new Snowflake(504343489664909322)), ("mctaylors", new Snowflake(326642240229474304)), ("neroduckale", new Snowflake(474943797063843851)) - }; + ]; private readonly ICommandContext _context; private readonly IFeedbackService _feedback; diff --git a/src/Commands/SettingsCommandGroup.cs b/src/Commands/SettingsCommandGroup.cs index a8891bd..15fd514 100644 --- a/src/Commands/SettingsCommandGroup.cs +++ b/src/Commands/SettingsCommandGroup.cs @@ -36,7 +36,7 @@ public class SettingsCommandGroup : CommandGroup /// that the orders match. /// private static readonly IOption[] AllOptions = - { + [ GuildSettings.Language, GuildSettings.WelcomeMessage, GuildSettings.ReceiveStartupMessages, @@ -51,7 +51,7 @@ public class SettingsCommandGroup : CommandGroup GuildSettings.MuteRole, GuildSettings.EventNotificationRole, GuildSettings.EventEarlyNotificationOffset - }; + ]; private readonly ICommandContext _context; private readonly IFeedbackService _feedback; diff --git a/src/Commands/ToolsCommandGroup.cs b/src/Commands/ToolsCommandGroup.cs index 78058cb..f04ddf6 100644 --- a/src/Commands/ToolsCommandGroup.cs +++ b/src/Commands/ToolsCommandGroup.cs @@ -393,7 +393,7 @@ public class ToolsCommandGroup : CommandGroup } private static readonly TimestampStyle[] AllStyles = - { + [ TimestampStyle.ShortDate, TimestampStyle.LongDate, TimestampStyle.ShortTime, @@ -401,7 +401,7 @@ public class ToolsCommandGroup : CommandGroup TimestampStyle.ShortDateTime, TimestampStyle.LongDateTime, TimestampStyle.RelativeTime - }; + ]; /// /// A slash command that shows the current timestamp with an optional offset in all styles supported by Discord. diff --git a/src/Services/Update/MemberUpdateService.cs b/src/Services/Update/MemberUpdateService.cs index e7860ae..8937833 100644 --- a/src/Services/Update/MemberUpdateService.cs +++ b/src/Services/Update/MemberUpdateService.cs @@ -16,7 +16,7 @@ namespace Octobot.Services.Update; public sealed partial class MemberUpdateService : BackgroundService { private static readonly string[] GenericNicknames = - { + [ "Albatross", "Alpha", "Anchor", "Banjo", "Bell", "Beta", "Blackbird", "Bulldog", "Canary", "Cat", "Calf", "Cyclone", "Daisy", "Dalmatian", "Dart", "Delta", "Diamond", "Donkey", "Duck", "Emu", "Eclipse", "Flamingo", "Flute", "Frog", "Goose", "Hatchet", "Heron", "Husky", "Hurricane", @@ -24,7 +24,7 @@ public sealed partial class MemberUpdateService : BackgroundService "Nautilus", "Ostrich", "Octopus", "Pelican", "Puffin", "Pyramid", "Rattle", "Robin", "Rose", "Salmon", "Seal", "Shark", "Sheep", "Snake", "Sonar", "Stump", "Sparrow", "Toaster", "Toucan", "Torus", "Violet", "Vortex", "Vulture", "Wagon", "Whale", "Woodpecker", "Zebra", "Zigzag" - }; + ]; private readonly IDiscordRestChannelAPI _channelApi; private readonly IDiscordRestGuildAPI _guildApi; diff --git a/src/Services/Update/SongUpdateService.cs b/src/Services/Update/SongUpdateService.cs index 391c416..53cc59b 100644 --- a/src/Services/Update/SongUpdateService.cs +++ b/src/Services/Update/SongUpdateService.cs @@ -9,7 +9,7 @@ namespace Octobot.Services.Update; public sealed class SongUpdateService : BackgroundService { private static readonly (string Author, string Name, TimeSpan Duration)[] SongList = - { + [ ("Yoko & the Gold Bazookas", "Rockagilly Blues", new TimeSpan(0, 2, 52)), ("Deep Cut", "Big Betrayal", new TimeSpan(0, 5, 55)), ("Squid Sisters", "Tomorrow's Nostalgia Today", new TimeSpan(0, 3, 7)), @@ -30,7 +30,7 @@ public sealed class SongUpdateService : BackgroundService ("Turquoise October", "Octoling Rendezvous", new TimeSpan(0, 1, 57)), ("Damp Socks feat. Off the Hook", "Tentacle to the Metal", new TimeSpan(0, 2, 51)), ("Off the Hook", "Fly Octo Fly ~ Ebb & Flow (Octo)", new TimeSpan(0, 3, 5)) - }; + ]; private readonly List _activityList = [new Activity("with Remora.Discord", ActivityType.Game)]; From 6688481093ab217a0e8b036dc00122b82acc71e0 Mon Sep 17 00:00:00 2001 From: Macintxsh <95250141+mctaylors@users.noreply.github.com> Date: Wed, 20 Dec 2023 19:25:13 +0300 Subject: [PATCH 2/3] /about: Show Discord bot username instead of hardcoded one (#230) In this PR, I made it so that in the Author field instead of the hardcoded name was the name of the Discord bot. This was done to match the icon next to it in the same field. Replaces #224 --------- Signed-off-by: mctaylors --- locale/Messages.resx | 2 +- locale/Messages.ru.resx | 2 +- locale/Messages.tt-ru.resx | 2 +- src/Commands/AboutCommandGroup.cs | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/locale/Messages.resx b/locale/Messages.resx index 743dd93..60e6e07 100644 --- a/locale/Messages.resx +++ b/locale/Messages.resx @@ -400,7 +400,7 @@ Octobot's source code - About Octobot + About {0} developer & designer, Octobot's Wiki creator diff --git a/locale/Messages.ru.resx b/locale/Messages.ru.resx index 67a1d29..4b9492c 100644 --- a/locale/Messages.ru.resx +++ b/locale/Messages.ru.resx @@ -400,7 +400,7 @@ Исходный код Octobot - Об Octobot + О боте {0} разработчик diff --git a/locale/Messages.tt-ru.resx b/locale/Messages.tt-ru.resx index 4050d43..de1f39f 100644 --- a/locale/Messages.tt-ru.resx +++ b/locale/Messages.tt-ru.resx @@ -400,7 +400,7 @@ репа Octobot (тык) - немного об Octobot + немного об {0} скучный девелопер + дизайнер создавший Octobot's Wiki diff --git a/src/Commands/AboutCommandGroup.cs b/src/Commands/AboutCommandGroup.cs index 1c2656b..4c396d9 100644 --- a/src/Commands/AboutCommandGroup.cs +++ b/src/Commands/AboutCommandGroup.cs @@ -96,7 +96,8 @@ public class AboutCommandGroup : CommandGroup builder.AppendBulletPointLine($"{tag} — {$"AboutDeveloper@{dev.Username}".Localized()}"); } - var embed = new EmbedBuilder().WithSmallTitle(Messages.AboutBot, bot) + var embed = new EmbedBuilder() + .WithSmallTitle(string.Format(Messages.AboutBot, bot.Username), bot) .WithDescription(builder.ToString()) .WithColour(ColorsList.Cyan) .WithImageUrl("https://cdn.mctaylors.ru/octobot-banner.png") From bd4c5b26da95d7a1fd3e00ce5ce0e90757018f8c Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Wed, 20 Dec 2023 21:33:52 +0500 Subject: [PATCH 3/3] Remove "extends IHostedService" from classes where it's not required (#236) Originally, these classes were services because I thought that all DI-resolvable classes need to be services. However, this is not true, so we can make these classes (notably Utility and GuildDataService) not extend anything. `UtilityService` was renamed to `Utility` for simplicity --------- Signed-off-by: Octol1ttle --- src/Commands/BanCommandGroup.cs | 4 ++-- src/Commands/ClearCommandGroup.cs | 4 ++-- src/Commands/KickCommandGroup.cs | 4 ++-- src/Commands/MuteCommandGroup.cs | 4 ++-- src/Commands/SettingsCommandGroup.cs | 4 ++-- src/Octobot.cs | 2 +- src/Responders/GuildLoadedResponder.cs | 4 ++-- src/Services/GuildDataService.cs | 12 +----------- src/Services/Update/MemberUpdateService.cs | 4 ++-- .../Update/ScheduledEventUpdateService.cs | 4 ++-- src/Services/{UtilityService.cs => Utility.cs} | 15 ++------------- 11 files changed, 20 insertions(+), 41 deletions(-) rename src/Services/{UtilityService.cs => Utility.cs} (97%) diff --git a/src/Commands/BanCommandGroup.cs b/src/Commands/BanCommandGroup.cs index f0da978..bbcf459 100644 --- a/src/Commands/BanCommandGroup.cs +++ b/src/Commands/BanCommandGroup.cs @@ -33,12 +33,12 @@ public class BanCommandGroup : CommandGroup private readonly IDiscordRestGuildAPI _guildApi; private readonly GuildDataService _guildData; private readonly IDiscordRestUserAPI _userApi; - private readonly UtilityService _utility; + private readonly Utility _utility; public BanCommandGroup( ICommandContext context, IDiscordRestChannelAPI channelApi, GuildDataService guildData, IFeedbackService feedback, IDiscordRestGuildAPI guildApi, IDiscordRestUserAPI userApi, - UtilityService utility) + Utility utility) { _context = context; _channelApi = channelApi; diff --git a/src/Commands/ClearCommandGroup.cs b/src/Commands/ClearCommandGroup.cs index 7ebd4ea..1d0ad64 100644 --- a/src/Commands/ClearCommandGroup.cs +++ b/src/Commands/ClearCommandGroup.cs @@ -30,11 +30,11 @@ public class ClearCommandGroup : CommandGroup private readonly IFeedbackService _feedback; private readonly GuildDataService _guildData; private readonly IDiscordRestUserAPI _userApi; - private readonly UtilityService _utility; + private readonly Utility _utility; public ClearCommandGroup( IDiscordRestChannelAPI channelApi, ICommandContext context, GuildDataService guildData, - IFeedbackService feedback, IDiscordRestUserAPI userApi, UtilityService utility) + IFeedbackService feedback, IDiscordRestUserAPI userApi, Utility utility) { _channelApi = channelApi; _context = context; diff --git a/src/Commands/KickCommandGroup.cs b/src/Commands/KickCommandGroup.cs index cad8ea9..ee94b93 100644 --- a/src/Commands/KickCommandGroup.cs +++ b/src/Commands/KickCommandGroup.cs @@ -30,12 +30,12 @@ public class KickCommandGroup : CommandGroup private readonly IDiscordRestGuildAPI _guildApi; private readonly GuildDataService _guildData; private readonly IDiscordRestUserAPI _userApi; - private readonly UtilityService _utility; + private readonly Utility _utility; public KickCommandGroup( ICommandContext context, IDiscordRestChannelAPI channelApi, GuildDataService guildData, IFeedbackService feedback, IDiscordRestGuildAPI guildApi, IDiscordRestUserAPI userApi, - UtilityService utility) + Utility utility) { _context = context; _channelApi = channelApi; diff --git a/src/Commands/MuteCommandGroup.cs b/src/Commands/MuteCommandGroup.cs index 6a28f38..522c7f7 100644 --- a/src/Commands/MuteCommandGroup.cs +++ b/src/Commands/MuteCommandGroup.cs @@ -32,11 +32,11 @@ public class MuteCommandGroup : CommandGroup private readonly IDiscordRestGuildAPI _guildApi; private readonly GuildDataService _guildData; private readonly IDiscordRestUserAPI _userApi; - private readonly UtilityService _utility; + private readonly Utility _utility; public MuteCommandGroup( ICommandContext context, GuildDataService guildData, IFeedbackService feedback, - IDiscordRestGuildAPI guildApi, IDiscordRestUserAPI userApi, UtilityService utility) + IDiscordRestGuildAPI guildApi, IDiscordRestUserAPI userApi, Utility utility) { _context = context; _guildData = guildData; diff --git a/src/Commands/SettingsCommandGroup.cs b/src/Commands/SettingsCommandGroup.cs index 15fd514..ce7472f 100644 --- a/src/Commands/SettingsCommandGroup.cs +++ b/src/Commands/SettingsCommandGroup.cs @@ -57,11 +57,11 @@ public class SettingsCommandGroup : CommandGroup private readonly IFeedbackService _feedback; private readonly GuildDataService _guildData; private readonly IDiscordRestUserAPI _userApi; - private readonly UtilityService _utility; + private readonly Utility _utility; public SettingsCommandGroup( ICommandContext context, GuildDataService guildData, - IFeedbackService feedback, IDiscordRestUserAPI userApi, UtilityService utility) + IFeedbackService feedback, IDiscordRestUserAPI userApi, Utility utility) { _context = context; _guildData = guildData; diff --git a/src/Octobot.cs b/src/Octobot.cs index 1806330..5cffd70 100644 --- a/src/Octobot.cs +++ b/src/Octobot.cs @@ -87,7 +87,7 @@ public sealed class Octobot .AddPostExecutionEvent() // Services .AddSingleton() - .AddSingleton() + .AddSingleton() .AddHostedService() .AddHostedService() .AddHostedService() diff --git a/src/Responders/GuildLoadedResponder.cs b/src/Responders/GuildLoadedResponder.cs index 2d66a3b..a1e7d16 100644 --- a/src/Responders/GuildLoadedResponder.cs +++ b/src/Responders/GuildLoadedResponder.cs @@ -25,11 +25,11 @@ public class GuildLoadedResponder : IResponder private readonly GuildDataService _guildData; private readonly ILogger _logger; private readonly IDiscordRestUserAPI _userApi; - private readonly UtilityService _utility; + private readonly Utility _utility; public GuildLoadedResponder( IDiscordRestChannelAPI channelApi, GuildDataService guildData, ILogger logger, - IDiscordRestUserAPI userApi, UtilityService utility) + IDiscordRestUserAPI userApi, Utility utility) { _channelApi = channelApi; _guildData = guildData; diff --git a/src/Services/GuildDataService.cs b/src/Services/GuildDataService.cs index 3cc8cea..961c8f9 100644 --- a/src/Services/GuildDataService.cs +++ b/src/Services/GuildDataService.cs @@ -11,7 +11,7 @@ namespace Octobot.Services; /// /// Handles saving, loading, initializing and providing . /// -public sealed class GuildDataService : IHostedService +public sealed class GuildDataService { private readonly ConcurrentDictionary _datas = new(); private readonly ILogger _logger; @@ -24,16 +24,6 @@ public sealed class GuildDataService : IHostedService lifetime.ApplicationStopping.Register(ApplicationStopping); } - public Task StartAsync(CancellationToken ct) - { - return Task.CompletedTask; - } - - public Task StopAsync(CancellationToken ct) - { - return Task.CompletedTask; - } - private void ApplicationStopping() { SaveAsync(CancellationToken.None).GetAwaiter().GetResult(); diff --git a/src/Services/Update/MemberUpdateService.cs b/src/Services/Update/MemberUpdateService.cs index 8937833..06e531f 100644 --- a/src/Services/Update/MemberUpdateService.cs +++ b/src/Services/Update/MemberUpdateService.cs @@ -30,10 +30,10 @@ public sealed partial class MemberUpdateService : BackgroundService private readonly IDiscordRestGuildAPI _guildApi; private readonly GuildDataService _guildData; private readonly ILogger _logger; - private readonly UtilityService _utility; + private readonly Utility _utility; public MemberUpdateService(IDiscordRestChannelAPI channelApi, IDiscordRestGuildAPI guildApi, - GuildDataService guildData, ILogger logger, UtilityService utility) + GuildDataService guildData, ILogger logger, Utility utility) { _channelApi = channelApi; _guildApi = guildApi; diff --git a/src/Services/Update/ScheduledEventUpdateService.cs b/src/Services/Update/ScheduledEventUpdateService.cs index dd9be0d..ac5c109 100644 --- a/src/Services/Update/ScheduledEventUpdateService.cs +++ b/src/Services/Update/ScheduledEventUpdateService.cs @@ -19,10 +19,10 @@ public sealed class ScheduledEventUpdateService : BackgroundService private readonly IDiscordRestGuildScheduledEventAPI _eventApi; private readonly GuildDataService _guildData; private readonly ILogger _logger; - private readonly UtilityService _utility; + private readonly Utility _utility; public ScheduledEventUpdateService(IDiscordRestChannelAPI channelApi, IDiscordRestGuildScheduledEventAPI eventApi, - GuildDataService guildData, ILogger logger, UtilityService utility) + GuildDataService guildData, ILogger logger, Utility utility) { _channelApi = channelApi; _eventApi = eventApi; diff --git a/src/Services/UtilityService.cs b/src/Services/Utility.cs similarity index 97% rename from src/Services/UtilityService.cs rename to src/Services/Utility.cs index 9ac481b..401b067 100644 --- a/src/Services/UtilityService.cs +++ b/src/Services/Utility.cs @@ -1,7 +1,6 @@ using System.Drawing; using System.Text; using System.Text.Json.Nodes; -using Microsoft.Extensions.Hosting; using Octobot.Data; using Octobot.Extensions; using Remora.Discord.API.Abstractions.Objects; @@ -17,14 +16,14 @@ namespace Octobot.Services; /// Provides utility methods that cannot be transformed to extension methods because they require usage /// of some Discord APIs. /// -public sealed class UtilityService : IHostedService +public sealed class Utility { private readonly IDiscordRestChannelAPI _channelApi; private readonly IDiscordRestGuildScheduledEventAPI _eventApi; private readonly IDiscordRestGuildAPI _guildApi; private readonly IDiscordRestUserAPI _userApi; - public UtilityService( + public Utility( IDiscordRestChannelAPI channelApi, IDiscordRestGuildScheduledEventAPI eventApi, IDiscordRestGuildAPI guildApi, IDiscordRestUserAPI userApi) { @@ -34,16 +33,6 @@ public sealed class UtilityService : IHostedService _userApi = userApi; } - public Task StartAsync(CancellationToken ct) - { - return Task.CompletedTask; - } - - public Task StopAsync(CancellationToken ct) - { - return Task.CompletedTask; - } - /// /// Checks whether or not a member can interact with another member ///