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
.AddDiscordCaching()
.AddDiscordCommands(true)
// Interactions
.AddInteractivity()
.AddInteractionGroup<InteractionResponders>()
// Slash command event handlers
.AddPreparationErrorEvent<ErrorLoggingPreparationErrorEvent>()
.AddPostExecutionEvent<ErrorLoggingPostExecutionEvent>()
.AddInteractionGroup<InteractionResponders>()
// Services
.AddSingleton<GuildDataService>()
.AddSingleton<UtilityService>()

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,6 +1,7 @@
using System.ComponentModel;
using Boyfriend.Data;
using Boyfriend.Services;
using JetBrains.Annotations;
using Remora.Commands.Attributes;
using Remora.Commands.Groups;
using Remora.Discord.API.Abstractions.Rest;
@ -15,6 +16,7 @@ namespace Boyfriend.Commands;
/// <summary>
/// Handles the command to manage reminders: /remind
/// </summary>
[UsedImplicitly]
public class RemindCommandGroup : CommandGroup {
private readonly ICommandContext _context;
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>
[Command("remind")]
[Description("Create a reminder")]
[UsedImplicitly]
public async Task<Result> AddReminderAsync(
[Description("After what period of time mention the reminder")]
TimeSpan @in,

View file

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

View file

@ -1,4 +1,5 @@
using Boyfriend.Data.Options;
using Boyfriend.Responders;
using Remora.Discord.API.Abstractions.Objects;
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>
/// </list>
/// </remarks>
/// <seealso cref="GuildMemberAddResponder" />
/// <seealso cref="GuildMemberJoinedResponder" />
public static readonly Option<string> WelcomeMessage = new("WelcomeMessage", "default");
/// <summary>
/// Controls whether or not the <see cref="Messages.Ready" /> message should be sent
/// in <see cref="PrivateFeedbackChannel" /> on startup.
/// </summary>
/// <seealso cref="GuildCreateResponder" />
/// <seealso cref="GuildLoadedResponder" />
public static readonly BoolOption ReceiveStartupMessages = new("ReceiveStartupMessages", 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.Commands.Feedback.Messages;
using Remora.Discord.Commands.Feedback.Services;
@ -9,6 +10,7 @@ namespace Boyfriend;
/// <summary>
/// Handles responding to various interactions.
/// </summary>
[UsedImplicitly]
public class InteractionResponders : InteractionGroup {
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>
/// <returns>An ephemeral feedback sending result which may or may not have succeeded.</returns>
[Button("scheduled-event-details")]
[UsedImplicitly]
public async Task<Result> OnStatefulButtonClicked(string? state = null) {
if (state is null) return Result.FromError(new ArgumentNullError(nameof(state)));