1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-04-20 00:43:36 +03:00

Add missing implicit use annotations

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2023-07-11 13:57:19 +05:00
parent aeeb3d4399
commit bb291559ce
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
11 changed files with 44 additions and 5 deletions

View file

@ -67,11 +67,12 @@ public class Boyfriend {
// Init // Init
.AddDiscordCaching() .AddDiscordCaching()
.AddDiscordCommands(true) .AddDiscordCommands(true)
// Interactions
.AddInteractivity() .AddInteractivity()
.AddInteractionGroup<InteractionResponders>()
// Slash command event handlers // Slash command event handlers
.AddPreparationErrorEvent<ErrorLoggingPreparationErrorEvent>() .AddPreparationErrorEvent<ErrorLoggingPreparationErrorEvent>()
.AddPostExecutionEvent<ErrorLoggingPostExecutionEvent>() .AddPostExecutionEvent<ErrorLoggingPostExecutionEvent>()
.AddInteractionGroup<InteractionResponders>()
// Services // Services
.AddSingleton<GuildDataService>() .AddSingleton<GuildDataService>()
.AddSingleton<UtilityService>() .AddSingleton<UtilityService>()

View file

@ -2,6 +2,7 @@
using System.Text; using System.Text;
using Boyfriend.Data; using Boyfriend.Data;
using Boyfriend.Services; using Boyfriend.Services;
using JetBrains.Annotations;
using Remora.Commands.Attributes; using Remora.Commands.Attributes;
using Remora.Commands.Groups; using Remora.Commands.Groups;
using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.API.Abstractions.Rest;
@ -16,6 +17,7 @@ namespace Boyfriend.Commands;
/// <summary> /// <summary>
/// Handles the command to show information about this bot: /about. /// Handles the command to show information about this bot: /about.
/// </summary> /// </summary>
[UsedImplicitly]
public class AboutCommandGroup : CommandGroup { public class AboutCommandGroup : CommandGroup {
private static readonly string[] Developers = { "Octol1ttle", "mctaylors", "neroduckale" }; private static readonly string[] Developers = { "Octol1ttle", "mctaylors", "neroduckale" };
private readonly ICommandContext _context; private readonly ICommandContext _context;
@ -40,6 +42,7 @@ public class AboutCommandGroup : CommandGroup {
/// </returns> /// </returns>
[Command("about")] [Command("about")]
[Description("Shows Boyfriend's developers")] [Description("Shows Boyfriend's developers")]
[UsedImplicitly]
public async Task<Result> SendAboutBotAsync() { public async Task<Result> SendAboutBotAsync() {
if (!_context.TryGetContextIDs(out var guildId, out _, out _)) if (!_context.TryGetContextIDs(out var guildId, out _, out _))
return Result.FromError( return Result.FromError(

View file

@ -2,6 +2,7 @@ using System.ComponentModel;
using System.Text; using System.Text;
using Boyfriend.Data; using Boyfriend.Data;
using Boyfriend.Services; using Boyfriend.Services;
using JetBrains.Annotations;
using Remora.Commands.Attributes; using Remora.Commands.Attributes;
using Remora.Commands.Groups; using Remora.Commands.Groups;
using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Objects;
@ -19,6 +20,7 @@ namespace Boyfriend.Commands;
/// <summary> /// <summary>
/// Handles commands related to ban management: /ban and /unban. /// Handles commands related to ban management: /ban and /unban.
/// </summary> /// </summary>
[UsedImplicitly]
public class BanCommandGroup : CommandGroup { public class BanCommandGroup : CommandGroup {
private readonly IDiscordRestChannelAPI _channelApi; private readonly IDiscordRestChannelAPI _channelApi;
private readonly ICommandContext _context; private readonly ICommandContext _context;
@ -60,6 +62,7 @@ public class BanCommandGroup : CommandGroup {
[RequireDiscordPermission(DiscordPermission.BanMembers)] [RequireDiscordPermission(DiscordPermission.BanMembers)]
[RequireBotDiscordPermissions(DiscordPermission.BanMembers)] [RequireBotDiscordPermissions(DiscordPermission.BanMembers)]
[Description("Ban user")] [Description("Ban user")]
[UsedImplicitly]
public async Task<Result> BanUserAsync( public async Task<Result> BanUserAsync(
[Description("User to ban")] IUser target, [Description("User to ban")] IUser target,
[Description("Ban reason")] string reason, [Description("Ban reason")] string reason,
@ -197,6 +200,7 @@ public class BanCommandGroup : CommandGroup {
[RequireDiscordPermission(DiscordPermission.BanMembers)] [RequireDiscordPermission(DiscordPermission.BanMembers)]
[RequireBotDiscordPermissions(DiscordPermission.BanMembers)] [RequireBotDiscordPermissions(DiscordPermission.BanMembers)]
[Description("Unban user")] [Description("Unban user")]
[UsedImplicitly]
public async Task<Result> UnbanUserAsync( public async Task<Result> UnbanUserAsync(
[Description("User to unban")] IUser target, [Description("User to unban")] IUser target,
[Description("Unban reason")] string reason) { [Description("Unban reason")] string reason) {

View file

@ -1,5 +1,7 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Remora.Discord.Commands.Contexts; using Remora.Discord.Commands.Contexts;
using Remora.Discord.Commands.Extensions;
using Remora.Discord.Commands.Services; using Remora.Discord.Commands.Services;
using Remora.Results; using Remora.Results;
@ -8,6 +10,7 @@ namespace Boyfriend.Commands;
/// <summary> /// <summary>
/// Handles error logging for slash commands that couldn't be successfully prepared. /// Handles error logging for slash commands that couldn't be successfully prepared.
/// </summary> /// </summary>
[UsedImplicitly]
public class ErrorLoggingPreparationErrorEvent : IPreparationErrorEvent { public class ErrorLoggingPreparationErrorEvent : IPreparationErrorEvent {
private readonly ILogger<ErrorLoggingPreparationErrorEvent> _logger; private readonly ILogger<ErrorLoggingPreparationErrorEvent> _logger;
@ -25,8 +28,11 @@ public class ErrorLoggingPreparationErrorEvent : IPreparationErrorEvent {
/// <returns>A result which has succeeded.</returns> /// <returns>A result which has succeeded.</returns>
public Task<Result> PreparationFailed( public Task<Result> PreparationFailed(
IOperationContext context, IResult preparationResult, CancellationToken ct = default) { IOperationContext context, IResult preparationResult, CancellationToken ct = default) {
if (!preparationResult.IsSuccess) if (!preparationResult.IsSuccess && !preparationResult.Error.IsUserOrEnvironmentError()) {
_logger.LogWarning("Error in slash command preparation.\n{ErrorMessage}", preparationResult.Error.Message); _logger.LogWarning("Error in slash command preparation.\n{ErrorMessage}", preparationResult.Error.Message);
if (preparationResult.Error is ExceptionError exerr)
_logger.LogError(exerr.Exception, "An exception has been thrown");
}
return Task.FromResult(Result.FromSuccess()); return Task.FromResult(Result.FromSuccess());
} }
@ -35,6 +41,7 @@ public class ErrorLoggingPreparationErrorEvent : IPreparationErrorEvent {
/// <summary> /// <summary>
/// Handles error logging for slash command groups. /// Handles error logging for slash command groups.
/// </summary> /// </summary>
[UsedImplicitly]
public class ErrorLoggingPostExecutionEvent : IPostExecutionEvent { public class ErrorLoggingPostExecutionEvent : IPostExecutionEvent {
private readonly ILogger<ErrorLoggingPostExecutionEvent> _logger; private readonly ILogger<ErrorLoggingPostExecutionEvent> _logger;
@ -52,8 +59,11 @@ public class ErrorLoggingPostExecutionEvent : IPostExecutionEvent {
/// <returns>A result which has succeeded.</returns> /// <returns>A result which has succeeded.</returns>
public Task<Result> AfterExecutionAsync( public Task<Result> AfterExecutionAsync(
ICommandContext context, IResult commandResult, CancellationToken ct = default) { ICommandContext context, IResult commandResult, CancellationToken ct = default) {
if (!commandResult.IsSuccess) if (!commandResult.IsSuccess && !commandResult.Error.IsUserOrEnvironmentError()) {
_logger.LogWarning("Error in slash command execution.\n{ErrorMessage}", commandResult.Error.Message); _logger.LogWarning("Error in slash command execution.\n{ErrorMessage}", commandResult.Error.Message);
if (commandResult.Error is ExceptionError exerr)
_logger.LogError(exerr.Exception, "An exception has been thrown");
}
return Task.FromResult(Result.FromSuccess()); return Task.FromResult(Result.FromSuccess());
} }

View file

@ -1,6 +1,7 @@
using System.ComponentModel; using System.ComponentModel;
using Boyfriend.Data; using Boyfriend.Data;
using Boyfriend.Services; using Boyfriend.Services;
using JetBrains.Annotations;
using Remora.Commands.Attributes; using Remora.Commands.Attributes;
using Remora.Commands.Groups; using Remora.Commands.Groups;
using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Objects;
@ -17,6 +18,7 @@ namespace Boyfriend.Commands;
/// <summary> /// <summary>
/// Handles the command to kick members of a guild: /kick. /// Handles the command to kick members of a guild: /kick.
/// </summary> /// </summary>
[UsedImplicitly]
public class KickCommandGroup : CommandGroup { public class KickCommandGroup : CommandGroup {
private readonly IDiscordRestChannelAPI _channelApi; private readonly IDiscordRestChannelAPI _channelApi;
private readonly ICommandContext _context; private readonly ICommandContext _context;
@ -56,6 +58,7 @@ public class KickCommandGroup : CommandGroup {
[RequireDiscordPermission(DiscordPermission.KickMembers)] [RequireDiscordPermission(DiscordPermission.KickMembers)]
[RequireBotDiscordPermissions(DiscordPermission.KickMembers)] [RequireBotDiscordPermissions(DiscordPermission.KickMembers)]
[Description("Kick member")] [Description("Kick member")]
[UsedImplicitly]
public async Task<Result> KickUserAsync( public async Task<Result> KickUserAsync(
[Description("Member to kick")] IUser target, [Description("Member to kick")] IUser target,
[Description("Kick reason")] string reason) { [Description("Kick reason")] string reason) {

View file

@ -2,6 +2,7 @@ using System.ComponentModel;
using System.Text; using System.Text;
using Boyfriend.Data; using Boyfriend.Data;
using Boyfriend.Services; using Boyfriend.Services;
using JetBrains.Annotations;
using Remora.Commands.Attributes; using Remora.Commands.Attributes;
using Remora.Commands.Groups; using Remora.Commands.Groups;
using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Objects;
@ -19,6 +20,7 @@ namespace Boyfriend.Commands;
/// <summary> /// <summary>
/// Handles commands related to mute management: /mute and /unmute. /// Handles commands related to mute management: /mute and /unmute.
/// </summary> /// </summary>
[UsedImplicitly]
public class MuteCommandGroup : CommandGroup { public class MuteCommandGroup : CommandGroup {
private readonly IDiscordRestChannelAPI _channelApi; private readonly IDiscordRestChannelAPI _channelApi;
private readonly ICommandContext _context; private readonly ICommandContext _context;
@ -60,6 +62,7 @@ public class MuteCommandGroup : CommandGroup {
[RequireDiscordPermission(DiscordPermission.ModerateMembers)] [RequireDiscordPermission(DiscordPermission.ModerateMembers)]
[RequireBotDiscordPermissions(DiscordPermission.ModerateMembers)] [RequireBotDiscordPermissions(DiscordPermission.ModerateMembers)]
[Description("Mute member")] [Description("Mute member")]
[UsedImplicitly]
public async Task<Result> MuteUserAsync( public async Task<Result> MuteUserAsync(
[Description("Member to mute")] IUser target, [Description("Member to mute")] IUser target,
[Description("Mute reason")] string reason, [Description("Mute reason")] string reason,
@ -173,6 +176,7 @@ public class MuteCommandGroup : CommandGroup {
[RequireDiscordPermission(DiscordPermission.ModerateMembers)] [RequireDiscordPermission(DiscordPermission.ModerateMembers)]
[RequireBotDiscordPermissions(DiscordPermission.ModerateMembers)] [RequireBotDiscordPermissions(DiscordPermission.ModerateMembers)]
[Description("Unmute member")] [Description("Unmute member")]
[UsedImplicitly]
public async Task<Result> UnmuteUserAsync( public async Task<Result> UnmuteUserAsync(
[Description("Member to unmute")] IUser target, [Description("Member to unmute")] IUser target,
[Description("Unmute reason")] string reason) { [Description("Unmute reason")] string reason) {

View file

@ -1,6 +1,7 @@
using System.ComponentModel; using System.ComponentModel;
using Boyfriend.Data; using Boyfriend.Data;
using Boyfriend.Services; using Boyfriend.Services;
using JetBrains.Annotations;
using Remora.Commands.Attributes; using Remora.Commands.Attributes;
using Remora.Commands.Groups; using Remora.Commands.Groups;
using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.API.Abstractions.Rest;
@ -15,6 +16,7 @@ namespace Boyfriend.Commands;
/// <summary> /// <summary>
/// Handles the command to get the time taken for the gateway to respond to the last heartbeat: /ping /// Handles the command to get the time taken for the gateway to respond to the last heartbeat: /ping
/// </summary> /// </summary>
[UsedImplicitly]
public class PingCommandGroup : CommandGroup { public class PingCommandGroup : CommandGroup {
private readonly IDiscordRestChannelAPI _channelApi; private readonly IDiscordRestChannelAPI _channelApi;
private readonly DiscordGatewayClient _client; private readonly DiscordGatewayClient _client;
@ -42,6 +44,7 @@ public class PingCommandGroup : CommandGroup {
/// </returns> /// </returns>
[Command("ping", "пинг")] [Command("ping", "пинг")]
[Description("Get bot latency")] [Description("Get bot latency")]
[UsedImplicitly]
public async Task<Result> SendPingAsync() { public async Task<Result> SendPingAsync() {
if (!_context.TryGetContextIDs(out var guildId, out var channelId, out _)) if (!_context.TryGetContextIDs(out var guildId, out var channelId, out _))
return Result.FromError( return Result.FromError(

View file

@ -1,6 +1,7 @@
using System.ComponentModel; using System.ComponentModel;
using Boyfriend.Data; using Boyfriend.Data;
using Boyfriend.Services; using Boyfriend.Services;
using JetBrains.Annotations;
using Remora.Commands.Attributes; using Remora.Commands.Attributes;
using Remora.Commands.Groups; using Remora.Commands.Groups;
using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.API.Abstractions.Rest;
@ -15,6 +16,7 @@ namespace Boyfriend.Commands;
/// <summary> /// <summary>
/// Handles the command to manage reminders: /remind /// Handles the command to manage reminders: /remind
/// </summary> /// </summary>
[UsedImplicitly]
public class RemindCommandGroup : CommandGroup { public class RemindCommandGroup : CommandGroup {
private readonly ICommandContext _context; private readonly ICommandContext _context;
private readonly GuildDataService _dataService; private readonly GuildDataService _dataService;
@ -38,6 +40,7 @@ public class RemindCommandGroup : CommandGroup {
/// <returns>A feedback sending result which may or may not have succeeded.</returns> /// <returns>A feedback sending result which may or may not have succeeded.</returns>
[Command("remind")] [Command("remind")]
[Description("Create a reminder")] [Description("Create a reminder")]
[UsedImplicitly]
public async Task<Result> AddReminderAsync( public async Task<Result> AddReminderAsync(
[Description("After what period of time mention the reminder")] [Description("After what period of time mention the reminder")]
TimeSpan @in, TimeSpan @in,

View file

@ -3,6 +3,7 @@ using System.Text;
using Boyfriend.Data; using Boyfriend.Data;
using Boyfriend.Data.Options; using Boyfriend.Data.Options;
using Boyfriend.Services; using Boyfriend.Services;
using JetBrains.Annotations;
using Remora.Commands.Attributes; using Remora.Commands.Attributes;
using Remora.Commands.Groups; using Remora.Commands.Groups;
using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.API.Abstractions.Rest;
@ -17,6 +18,7 @@ namespace Boyfriend.Commands;
/// <summary> /// <summary>
/// Handles the commands to list and modify per-guild settings: /settings and /settings list. /// Handles the commands to list and modify per-guild settings: /settings and /settings list.
/// </summary> /// </summary>
[UsedImplicitly]
public class SettingsCommandGroup : CommandGroup { public class SettingsCommandGroup : CommandGroup {
private static readonly IOption[] AllOptions = { private static readonly IOption[] AllOptions = {
GuildSettings.Language, GuildSettings.Language,
@ -56,6 +58,7 @@ public class SettingsCommandGroup : CommandGroup {
/// </returns> /// </returns>
[Command("settingslist")] [Command("settingslist")]
[Description("Shows settings list for this server")] [Description("Shows settings list for this server")]
[UsedImplicitly]
public async Task<Result> ListSettingsAsync() { public async Task<Result> ListSettingsAsync() {
if (!_context.TryGetContextIDs(out var guildId, out _, out _)) if (!_context.TryGetContextIDs(out var guildId, out _, out _))
return Result.FromError( return Result.FromError(
@ -93,6 +96,7 @@ public class SettingsCommandGroup : CommandGroup {
/// <returns>A feedback sending result which may or may not have succeeded.</returns> /// <returns>A feedback sending result which may or may not have succeeded.</returns>
[Command("settings")] [Command("settings")]
[Description("Change settings for this server")] [Description("Change settings for this server")]
[UsedImplicitly]
public async Task<Result> EditSettingsAsync( public async Task<Result> EditSettingsAsync(
[Description("The setting whose value you want to change")] [Description("The setting whose value you want to change")]
string setting, string setting,

View file

@ -1,4 +1,5 @@
using Boyfriend.Data.Options; using Boyfriend.Data.Options;
using Boyfriend.Responders;
using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Objects;
namespace Boyfriend.Data; namespace Boyfriend.Data;
@ -19,14 +20,14 @@ public static class GuildSettings {
/// <item><see cref="Messages.DefaultWelcomeMessage" /> will be sent if set to "default" or "reset"</item> /// <item><see cref="Messages.DefaultWelcomeMessage" /> will be sent if set to "default" or "reset"</item>
/// </list> /// </list>
/// </remarks> /// </remarks>
/// <seealso cref="GuildMemberAddResponder" /> /// <seealso cref="GuildMemberJoinedResponder" />
public static readonly Option<string> WelcomeMessage = new("WelcomeMessage", "default"); public static readonly Option<string> WelcomeMessage = new("WelcomeMessage", "default");
/// <summary> /// <summary>
/// Controls whether or not the <see cref="Messages.Ready" /> message should be sent /// Controls whether or not the <see cref="Messages.Ready" /> message should be sent
/// in <see cref="PrivateFeedbackChannel" /> on startup. /// in <see cref="PrivateFeedbackChannel" /> on startup.
/// </summary> /// </summary>
/// <seealso cref="GuildCreateResponder" /> /// <seealso cref="GuildLoadedResponder" />
public static readonly BoolOption ReceiveStartupMessages = new("ReceiveStartupMessages", false); public static readonly BoolOption ReceiveStartupMessages = new("ReceiveStartupMessages", false);
public static readonly BoolOption RemoveRolesOnMute = new("RemoveRolesOnMute", false); public static readonly BoolOption RemoveRolesOnMute = new("RemoveRolesOnMute", false);

View file

@ -1,3 +1,4 @@
using JetBrains.Annotations;
using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Objects;
using Remora.Discord.Commands.Feedback.Messages; using Remora.Discord.Commands.Feedback.Messages;
using Remora.Discord.Commands.Feedback.Services; using Remora.Discord.Commands.Feedback.Services;
@ -9,6 +10,7 @@ namespace Boyfriend;
/// <summary> /// <summary>
/// Handles responding to various interactions. /// Handles responding to various interactions.
/// </summary> /// </summary>
[UsedImplicitly]
public class InteractionResponders : InteractionGroup { public class InteractionResponders : InteractionGroup {
private readonly FeedbackService _feedbackService; private readonly FeedbackService _feedbackService;
@ -22,6 +24,7 @@ public class InteractionResponders : InteractionGroup {
/// <param name="state">The ID of the guild and scheduled event, encoded as "guildId:eventId".</param> /// <param name="state">The ID of the guild and scheduled event, encoded as "guildId:eventId".</param>
/// <returns>An ephemeral feedback sending result which may or may not have succeeded.</returns> /// <returns>An ephemeral feedback sending result which may or may not have succeeded.</returns>
[Button("scheduled-event-details")] [Button("scheduled-event-details")]
[UsedImplicitly]
public async Task<Result> OnStatefulButtonClicked(string? state = null) { public async Task<Result> OnStatefulButtonClicked(string? state = null) {
if (state is null) return Result.FromError(new ArgumentNullError(nameof(state))); if (state is null) return Result.FromError(new ArgumentNullError(nameof(state)));