Skip to content

Commit

Permalink
refactor: seal implicitly used classes
Browse files Browse the repository at this point in the history
Signed-off-by: Octol1ttle <[email protected]>
  • Loading branch information
Octol1ttle committed May 18, 2024
1 parent ebcdcb3 commit 38756b4
Show file tree
Hide file tree
Showing 19 changed files with 41 additions and 35 deletions.
4 changes: 2 additions & 2 deletions TeamOctolings.Octobot/Commands/AboutCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace TeamOctolings.Octobot.Commands;
/// Handles the command to show information about this bot: /about.
/// </summary>
[UsedImplicitly]
public class AboutCommandGroup : CommandGroup
public sealed class AboutCommandGroup : CommandGroup
{
private static readonly (string Username, Snowflake Id)[] Developers =
[
Expand All @@ -36,9 +36,9 @@ private static readonly (string Username, Snowflake Id)[] Developers =

private readonly ICommandContext _context;
private readonly IFeedbackService _feedback;
private readonly IDiscordRestGuildAPI _guildApi;
private readonly GuildDataService _guildData;
private readonly IDiscordRestUserAPI _userApi;
private readonly IDiscordRestGuildAPI _guildApi;

public AboutCommandGroup(
ICommandContext context, GuildDataService guildData,
Expand Down
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Commands/BanCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace TeamOctolings.Octobot.Commands;
/// Handles commands related to ban management: /ban and /unban.
/// </summary>
[UsedImplicitly]
public class BanCommandGroup : CommandGroup
public sealed class BanCommandGroup : CommandGroup
{
private readonly AccessControlService _access;
private readonly IDiscordRestChannelAPI _channelApi;
Expand Down
5 changes: 3 additions & 2 deletions TeamOctolings.Octobot/Commands/ClearCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace TeamOctolings.Octobot.Commands;
/// Handles the command to clear messages in a channel: /clear.
/// </summary>
[UsedImplicitly]
public class ClearCommandGroup : CommandGroup
public sealed class ClearCommandGroup : CommandGroup
{
private readonly IDiscordRestChannelAPI _channelApi;
private readonly ICommandContext _context;
Expand Down Expand Up @@ -116,7 +116,8 @@ private async Task<Result> ClearMessagesAsync(
idList.Add(message.ID);

var entry = logEntries[currentLogEntry];
var str = $"{string.Format(Messages.MessageFrom, Mention.User(message.Author))}\n{message.Content.InBlockCode()}";
var str =
$"{string.Format(Messages.MessageFrom, Mention.User(message.Author))}\n{message.Content.InBlockCode()}";
if (entry.Builder.Length + str.Length > EmbedConstants.MaxDescriptionLength)
{
logEntries.Add(entry = new ClearedMessageEntry());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace TeamOctolings.Octobot.Commands.Events;
/// Handles error logging for slash command groups.
/// </summary>
[UsedImplicitly]
public class ErrorLoggingPostExecutionEvent : IPostExecutionEvent
public sealed class ErrorLoggingPostExecutionEvent : IPostExecutionEvent
{
private readonly IFeedbackService _feedback;
private readonly ILogger<ErrorLoggingPostExecutionEvent> _logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace TeamOctolings.Octobot.Commands.Events;
/// Handles error logging for slash commands that couldn't be successfully prepared.
/// </summary>
[UsedImplicitly]
public class LoggingPreparationErrorEvent : IPreparationErrorEvent
public sealed class LoggingPreparationErrorEvent : IPreparationErrorEvent
{
private readonly ILogger<LoggingPreparationErrorEvent> _logger;

Expand Down
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Commands/InfoCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace TeamOctolings.Octobot.Commands;
/// Handles info commands: /userinfo, /guildinfo.
/// </summary>
[UsedImplicitly]
public class InfoCommandGroup : CommandGroup
public sealed class InfoCommandGroup : CommandGroup
{
private readonly ICommandContext _context;
private readonly IFeedbackService _feedback;
Expand Down
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Commands/KickCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace TeamOctolings.Octobot.Commands;
/// Handles the command to kick members of a guild: /kick.
/// </summary>
[UsedImplicitly]
public class KickCommandGroup : CommandGroup
public sealed class KickCommandGroup : CommandGroup
{
private readonly AccessControlService _access;
private readonly IDiscordRestChannelAPI _channelApi;
Expand Down
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Commands/MuteCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace TeamOctolings.Octobot.Commands;
/// Handles commands related to mute management: /mute and /unmute.
/// </summary>
[UsedImplicitly]
public class MuteCommandGroup : CommandGroup
public sealed class MuteCommandGroup : CommandGroup
{
private readonly AccessControlService _access;
private readonly ICommandContext _context;
Expand Down
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Commands/PingCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace TeamOctolings.Octobot.Commands;
/// Handles the command to get the time taken for the gateway to respond to the last heartbeat: /ping
/// </summary>
[UsedImplicitly]
public class PingCommandGroup : CommandGroup
public sealed class PingCommandGroup : CommandGroup
{
private readonly IDiscordRestChannelAPI _channelApi;
private readonly DiscordGatewayClient _client;
Expand Down
35 changes: 20 additions & 15 deletions TeamOctolings.Octobot/Commands/RemindCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ namespace TeamOctolings.Octobot.Commands;
/// Handles commands to manage reminders: /remind, /listremind, /delremind
/// </summary>
[UsedImplicitly]
public class RemindCommandGroup : CommandGroup
public sealed class RemindCommandGroup : CommandGroup
{
public enum Parameters
{
[UsedImplicitly] Time,
[UsedImplicitly] Text
}

private readonly IInteractionCommandContext _context;
private readonly IFeedbackService _feedback;
private readonly GuildDataService _guildData;
private readonly IDiscordRestUserAPI _userApi;
private readonly IDiscordRestInteractionAPI _interactionApi;
private readonly IDiscordRestUserAPI _userApi;

public RemindCommandGroup(
IInteractionCommandContext context, GuildDataService guildData, IFeedbackService feedback,
Expand Down Expand Up @@ -75,10 +81,12 @@ public async Task<Result> ExecuteListReminderAsync()
var data = await _guildData.GetData(guildId, CancellationToken);
Messages.Culture = GuildSettings.Language.Get(data.Settings);

return await ListRemindersAsync(data.GetOrCreateMemberData(executorId), guildId, executor, bot, CancellationToken);
return await ListRemindersAsync(data.GetOrCreateMemberData(executorId), guildId, executor, bot,
CancellationToken);
}

private Task<Result> ListRemindersAsync(MemberData data, Snowflake guildId, IUser executor, IUser bot, CancellationToken ct)
private Task<Result> ListRemindersAsync(MemberData data, Snowflake guildId, IUser executor, IUser bot,
CancellationToken ct)
{
if (data.Reminders.Count == 0)
{
Expand All @@ -93,10 +101,12 @@ private Task<Result> ListRemindersAsync(MemberData data, Snowflake guildId, IUse
for (var i = 0; i < data.Reminders.Count; i++)
{
var reminder = data.Reminders[i];
builder.AppendBulletPointLine(string.Format(Messages.ReminderPosition, Markdown.InlineCode((i + 1).ToString())))
builder.AppendBulletPointLine(string.Format(Messages.ReminderPosition,
Markdown.InlineCode((i + 1).ToString())))
.AppendSubBulletPointLine(string.Format(Messages.ReminderText, Markdown.InlineCode(reminder.Text)))
.AppendSubBulletPointLine(string.Format(Messages.ReminderTime, Markdown.Timestamp(reminder.At)))
.AppendSubBulletPointLine(string.Format(Messages.DescriptionActionJumpToMessage, $"https://discord.com/channels/{guildId.Value}/{reminder.ChannelId}/{reminder.MessageId}"));
.AppendSubBulletPointLine(string.Format(Messages.DescriptionActionJumpToMessage,
$"https://discord.com/channels/{guildId.Value}/{reminder.ChannelId}/{reminder.MessageId}"));
}

var embed = new EmbedBuilder().WithSmallTitle(
Expand All @@ -120,8 +130,7 @@ private Task<Result> ListRemindersAsync(MemberData data, Snowflake guildId, IUse
[RequireContext(ChannelContext.Guild)]
[UsedImplicitly]
public async Task<Result> ExecuteReminderAsync(
[Description("After what period of time mention the reminder (e.g. 1h30m)")]
[Option("in")]
[Description("After what period of time mention the reminder (e.g. 1h30m)")] [Option("in")]
string timeSpanString,
[Description("Reminder text")] [MaxLength(512)]
string text)
Expand Down Expand Up @@ -166,7 +175,9 @@ private async Task<Result> AddReminderAsync(TimeSpan timeSpan, string text, Guil
{
var memberData = data.GetOrCreateMemberData(executor.ID);
var remindAt = DateTimeOffset.UtcNow.Add(timeSpan);
var responseResult = await _interactionApi.GetOriginalInteractionResponseAsync(_context.Interaction.ApplicationID, _context.Interaction.Token, ct);
var responseResult =
await _interactionApi.GetOriginalInteractionResponseAsync(_context.Interaction.ApplicationID,
_context.Interaction.Token, ct);
if (!responseResult.IsDefined(out var response))
{
return (Result)responseResult;
Expand Down Expand Up @@ -194,12 +205,6 @@ private async Task<Result> AddReminderAsync(TimeSpan timeSpan, string text, Guil
return await _feedback.SendContextualEmbedResultAsync(embed, ct: ct);
}

public enum Parameters
{
[UsedImplicitly] Time,
[UsedImplicitly] Text
}

/// <summary>
/// A slash command that edits a scheduled reminder using the specified text or time.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Commands/SettingsCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace TeamOctolings.Octobot.Commands;
/// Handles the commands to list and modify per-guild settings: /settings and /settings list.
/// </summary>
[UsedImplicitly]
public class SettingsCommandGroup : CommandGroup
public sealed class SettingsCommandGroup : CommandGroup
{
/// <summary>
/// Represents all options as an array of objects implementing <see cref="IGuildOption" />.
Expand Down
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Commands/ToolsCommandGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace TeamOctolings.Octobot.Commands;
/// Handles tool commands: /random, /timestamp, /8ball.
/// </summary>
[UsedImplicitly]
public class ToolsCommandGroup : CommandGroup
public sealed class ToolsCommandGroup : CommandGroup
{
private static readonly TimestampStyle[] AllStyles =
[
Expand Down
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Responders/GuildLoadedResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace TeamOctolings.Octobot.Responders;
/// has <see cref="GuildSettings.ReceiveStartupMessages" /> enabled
/// </summary>
[UsedImplicitly]
public class GuildLoadedResponder : IResponder<IGuildCreate>
public sealed class GuildLoadedResponder : IResponder<IGuildCreate>
{
private readonly IDiscordRestChannelAPI _channelApi;
private readonly GuildDataService _guildData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace TeamOctolings.Octobot.Responders;
/// </summary>
/// <seealso cref="GuildSettings.WelcomeMessage" />
[UsedImplicitly]
public class GuildMemberJoinedResponder : IResponder<IGuildMemberAdd>
public sealed class GuildMemberJoinedResponder : IResponder<IGuildMemberAdd>
{
private readonly IDiscordRestChannelAPI _channelApi;
private readonly IDiscordRestGuildAPI _guildApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace TeamOctolings.Octobot.Responders;
/// </summary>
/// <seealso cref="GuildSettings.LeaveMessage" />
[UsedImplicitly]
public class GuildMemberLeftResponder : IResponder<IGuildMemberRemove>
public sealed class GuildMemberLeftResponder : IResponder<IGuildMemberRemove>
{
private readonly IDiscordRestChannelAPI _channelApi;
private readonly IDiscordRestGuildAPI _guildApi;
Expand Down
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Responders/GuildUnloadedResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace TeamOctolings.Octobot.Responders;
/// Handles removing guild ID from <see cref="GuildData" /> if the guild becomes unavailable.
/// </summary>
[UsedImplicitly]
public class GuildUnloadedResponder : IResponder<IGuildDelete>
public sealed class GuildUnloadedResponder : IResponder<IGuildDelete>
{
private readonly GuildDataService _guildData;
private readonly ILogger<GuildUnloadedResponder> _logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace TeamOctolings.Octobot.Responders;
/// to a guild's <see cref="GuildSettings.PrivateFeedbackChannel" /> if one is set.
/// </summary>
[UsedImplicitly]
public class MessageDeletedResponder : IResponder<IMessageDelete>
public sealed class MessageDeletedResponder : IResponder<IMessageDelete>
{
private readonly IDiscordRestAuditLogAPI _auditLogApi;
private readonly IDiscordRestChannelAPI _channelApi;
Expand Down
2 changes: 1 addition & 1 deletion TeamOctolings.Octobot/Responders/MessageEditedResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace TeamOctolings.Octobot.Responders;
/// to a guild's <see cref="GuildSettings.PrivateFeedbackChannel" /> if one is set.
/// </summary>
[UsedImplicitly]
public class MessageEditedResponder : IResponder<IMessageUpdate>
public sealed class MessageEditedResponder : IResponder<IMessageUpdate>
{
private readonly CacheService _cacheService;
private readonly IDiscordRestChannelAPI _channelApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace TeamOctolings.Octobot.Responders;
/// Handles sending replies to easter egg messages.
/// </summary>
[UsedImplicitly]
public class MessageCreateResponder : IResponder<IMessageCreate>
public sealed class MessageCreateResponder : IResponder<IMessageCreate>
{
private readonly IDiscordRestChannelAPI _channelApi;

Expand Down

0 comments on commit 38756b4

Please sign in to comment.