diff --git a/Boyfriend.csproj b/Boyfriend.csproj index 44fab7b..12cf9af 100644 --- a/Boyfriend.csproj +++ b/Boyfriend.csproj @@ -26,7 +26,7 @@ - + diff --git a/src/Commands/AboutCommandGroup.cs b/src/Commands/AboutCommandGroup.cs index 50e7de7..b479764 100644 --- a/src/Commands/AboutCommandGroup.cs +++ b/src/Commands/AboutCommandGroup.cs @@ -57,7 +57,7 @@ public class AboutCommandGroup : CommandGroup { if (!currentUserResult.IsDefined(out var currentUser)) return Result.FromError(currentUserResult); - var cfg = await _dataService.GetSettings(guildId.Value, CancellationToken); + var cfg = await _dataService.GetSettings(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(cfg); return await SendAboutBotAsync(currentUser, CancellationToken); diff --git a/src/Commands/BanCommandGroup.cs b/src/Commands/BanCommandGroup.cs index ff48156..ad5ad5d 100644 --- a/src/Commands/BanCommandGroup.cs +++ b/src/Commands/BanCommandGroup.cs @@ -77,10 +77,10 @@ public class BanCommandGroup : CommandGroup { var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); if (!currentUserResult.IsDefined(out var currentUser)) return Result.FromError(currentUserResult); - var userResult = await _userApi.GetUserAsync(userId.Value, CancellationToken); + var userResult = await _userApi.GetUserAsync(userId, CancellationToken); if (!userResult.IsDefined(out var user)) return Result.FromError(userResult); - var guildResult = await _guildApi.GetGuildAsync(guildId.Value, ct: CancellationToken); + var guildResult = await _guildApi.GetGuildAsync(guildId, ct: CancellationToken); if (!guildResult.IsDefined(out var guild)) return Result.FromError(guildResult); @@ -88,7 +88,7 @@ public class BanCommandGroup : CommandGroup { Messages.Culture = GuildSettings.Language.Get(data.Settings); return await BanUserAsync( - target, reason, duration, guild, data, channelId.Value, user, currentUser, CancellationToken); + target, reason, duration, guild, data, channelId, user, currentUser, CancellationToken); } private async Task BanUserAsync( @@ -193,15 +193,15 @@ public class BanCommandGroup : CommandGroup { if (!currentUserResult.IsDefined(out var currentUser)) return Result.FromError(currentUserResult); // Needed to get the tag and avatar - var userResult = await _userApi.GetUserAsync(userId.Value, CancellationToken); + var userResult = await _userApi.GetUserAsync(userId, CancellationToken); if (!userResult.IsDefined(out var user)) return Result.FromError(userResult); - var data = await _dataService.GetData(guildId.Value, CancellationToken); + var data = await _dataService.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); return await UnbanUserAsync( - target, reason, guildId.Value, data, channelId.Value, user, currentUser, CancellationToken); + target, reason, guildId, data, channelId, user, currentUser, CancellationToken); } private async Task UnbanUserAsync( diff --git a/src/Commands/ClearCommandGroup.cs b/src/Commands/ClearCommandGroup.cs index 0d35814..9fae93c 100644 --- a/src/Commands/ClearCommandGroup.cs +++ b/src/Commands/ClearCommandGroup.cs @@ -65,10 +65,10 @@ public class ClearCommandGroup : CommandGroup { new ArgumentNullError(nameof(_context), "Unable to retrieve necessary IDs from command context")); var messagesResult = await _channelApi.GetChannelMessagesAsync( - channelId.Value, limit: amount + 1, ct: CancellationToken); + channelId, limit: amount + 1, ct: CancellationToken); if (!messagesResult.IsDefined(out var messages)) return Result.FromError(messagesResult); - var userResult = await _userApi.GetUserAsync(userId.Value, CancellationToken); + var userResult = await _userApi.GetUserAsync(userId, CancellationToken); if (!userResult.IsDefined(out var user)) return Result.FromError(userResult); // The current user's avatar is used when sending messages @@ -76,10 +76,10 @@ public class ClearCommandGroup : CommandGroup { if (!currentUserResult.IsDefined(out var currentUser)) return Result.FromError(currentUserResult); - var data = await _dataService.GetData(guildId.Value, CancellationToken); + var data = await _dataService.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - return await ClearMessagesAsync(amount, data, channelId.Value, messages, user, currentUser, CancellationToken); + return await ClearMessagesAsync(amount, data, channelId, messages, user, currentUser, CancellationToken); } private async Task ClearMessagesAsync( diff --git a/src/Commands/KickCommandGroup.cs b/src/Commands/KickCommandGroup.cs index 09dd833..62bbbad 100644 --- a/src/Commands/KickCommandGroup.cs +++ b/src/Commands/KickCommandGroup.cs @@ -72,17 +72,17 @@ public class KickCommandGroup : CommandGroup { var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); if (!currentUserResult.IsDefined(out var currentUser)) return Result.FromError(currentUserResult); - var userResult = await _userApi.GetUserAsync(userId.Value, CancellationToken); + var userResult = await _userApi.GetUserAsync(userId, CancellationToken); if (!userResult.IsDefined(out var user)) return Result.FromError(userResult); - var guildResult = await _guildApi.GetGuildAsync(guildId.Value, ct: CancellationToken); + var guildResult = await _guildApi.GetGuildAsync(guildId, ct: CancellationToken); if (!guildResult.IsDefined(out var guild)) return Result.FromError(guildResult); - var data = await _dataService.GetData(guildId.Value, CancellationToken); + var data = await _dataService.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - var memberResult = await _guildApi.GetGuildMemberAsync(guildId.Value, target.ID, CancellationToken); + var memberResult = await _guildApi.GetGuildMemberAsync(guildId, target.ID, CancellationToken); if (!memberResult.IsSuccess) { var embed = new EmbedBuilder().WithSmallTitle(Messages.UserNotFoundShort, currentUser) .WithColour(ColorsList.Red).Build(); @@ -90,7 +90,7 @@ public class KickCommandGroup : CommandGroup { return await _feedbackService.SendContextualEmbedResultAsync(embed, CancellationToken); } - return await KickUserAsync(target, reason, guild, channelId.Value, data, user, currentUser, CancellationToken); + return await KickUserAsync(target, reason, guild, channelId, data, user, currentUser, CancellationToken); } private async Task KickUserAsync( diff --git a/src/Commands/MuteCommandGroup.cs b/src/Commands/MuteCommandGroup.cs index be31ee8..697e24e 100644 --- a/src/Commands/MuteCommandGroup.cs +++ b/src/Commands/MuteCommandGroup.cs @@ -76,14 +76,14 @@ public class MuteCommandGroup : CommandGroup { if (!currentUserResult.IsDefined(out var currentUser)) return Result.FromError(currentUserResult); - var userResult = await _userApi.GetUserAsync(userId.Value, CancellationToken); + var userResult = await _userApi.GetUserAsync(userId, CancellationToken); if (!userResult.IsDefined(out var user)) return Result.FromError(userResult); - var data = await _dataService.GetData(guildId.Value, CancellationToken); + var data = await _dataService.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - var memberResult = await _guildApi.GetGuildMemberAsync(guildId.Value, target.ID, CancellationToken); + var memberResult = await _guildApi.GetGuildMemberAsync(guildId, target.ID, CancellationToken); if (!memberResult.IsSuccess) { var embed = new EmbedBuilder().WithSmallTitle(Messages.UserNotFoundShort, currentUser) .WithColour(ColorsList.Red).Build(); @@ -92,7 +92,7 @@ public class MuteCommandGroup : CommandGroup { } return await MuteUserAsync( - target, reason, duration, guildId.Value, data, channelId.Value, user, currentUser, CancellationToken); + target, reason, duration, guildId, data, channelId, user, currentUser, CancellationToken); } private async Task MuteUserAsync( @@ -171,14 +171,14 @@ public class MuteCommandGroup : CommandGroup { return Result.FromError(currentUserResult); // Needed to get the tag and avatar - var userResult = await _userApi.GetUserAsync(userId.Value, CancellationToken); + var userResult = await _userApi.GetUserAsync(userId, CancellationToken); if (!userResult.IsDefined(out var user)) return Result.FromError(userResult); - var data = await _dataService.GetData(guildId.Value, CancellationToken); + var data = await _dataService.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - var memberResult = await _guildApi.GetGuildMemberAsync(guildId.Value, target.ID, CancellationToken); + var memberResult = await _guildApi.GetGuildMemberAsync(guildId, target.ID, CancellationToken); if (!memberResult.IsSuccess) { var embed = new EmbedBuilder().WithSmallTitle(Messages.UserNotFoundShort, currentUser) .WithColour(ColorsList.Red).Build(); @@ -187,7 +187,7 @@ public class MuteCommandGroup : CommandGroup { } return await UnmuteUserAsync( - target, reason, guildId.Value, data, channelId.Value, user, currentUser, CancellationToken); + target, reason, guildId, data, channelId, user, currentUser, CancellationToken); } private async Task UnmuteUserAsync( diff --git a/src/Commands/PingCommandGroup.cs b/src/Commands/PingCommandGroup.cs index 83b04c9..08e0c58 100644 --- a/src/Commands/PingCommandGroup.cs +++ b/src/Commands/PingCommandGroup.cs @@ -60,10 +60,10 @@ public class PingCommandGroup : CommandGroup { if (!currentUserResult.IsDefined(out var currentUser)) return Result.FromError(currentUserResult); - var cfg = await _dataService.GetSettings(guildId.Value, CancellationToken); + var cfg = await _dataService.GetSettings(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(cfg); - return await SendLatencyAsync(channelId.Value, currentUser, CancellationToken); + return await SendLatencyAsync(channelId, currentUser, CancellationToken); } private async Task SendLatencyAsync( diff --git a/src/Commands/RemindCommandGroup.cs b/src/Commands/RemindCommandGroup.cs index 90016f6..2d892bc 100644 --- a/src/Commands/RemindCommandGroup.cs +++ b/src/Commands/RemindCommandGroup.cs @@ -55,14 +55,14 @@ public class RemindCommandGroup : CommandGroup { return Result.FromError( new ArgumentNullError(nameof(_context), "Unable to retrieve necessary IDs from command context")); - var userResult = await _userApi.GetUserAsync(userId.Value, CancellationToken); + var userResult = await _userApi.GetUserAsync(userId, CancellationToken); if (!userResult.IsDefined(out var user)) return Result.FromError(userResult); - var data = await _dataService.GetData(guildId.Value, CancellationToken); + var data = await _dataService.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - return await AddReminderAsync(@in, message, data, channelId.Value, user, CancellationToken); + return await AddReminderAsync(@in, message, data, channelId, user, CancellationToken); } private async Task AddReminderAsync( diff --git a/src/Commands/SettingsCommandGroup.cs b/src/Commands/SettingsCommandGroup.cs index 741f10e..37dca6d 100644 --- a/src/Commands/SettingsCommandGroup.cs +++ b/src/Commands/SettingsCommandGroup.cs @@ -76,7 +76,7 @@ public class SettingsCommandGroup : CommandGroup { if (!currentUserResult.IsDefined(out var currentUser)) return Result.FromError(currentUserResult); - var cfg = await _dataService.GetSettings(guildId.Value, CancellationToken); + var cfg = await _dataService.GetSettings(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(cfg); return await SendSettingsListAsync(cfg, currentUser, CancellationToken); @@ -124,7 +124,7 @@ public class SettingsCommandGroup : CommandGroup { if (!currentUserResult.IsDefined(out var currentUser)) return Result.FromError(currentUserResult); - var data = await _dataService.GetData(guildId.Value, CancellationToken); + var data = await _dataService.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); return await EditSettingAsync(setting, value, data, currentUser, CancellationToken); diff --git a/src/Extensions.cs b/src/Extensions.cs index a9e0d48..2fa342c 100644 --- a/src/Extensions.cs +++ b/src/Extensions.cs @@ -1,4 +1,3 @@ -using System.Diagnostics.CodeAnalysis; using System.Net; using System.Text; using DiffPlex.DiffBuilder.Model; @@ -182,11 +181,10 @@ public static class Extensions { } public static bool TryGetContextIDs( - this ICommandContext context, [NotNullWhen(true)] out Snowflake? guildId, - [NotNullWhen(true)] out Snowflake? channelId, [NotNullWhen(true)] out Snowflake? userId) { - guildId = null; - channelId = null; - userId = null; + this ICommandContext context, out Snowflake guildId, + out Snowflake channelId, out Snowflake userId) { + channelId = default; + userId = default; return context.TryGetGuildID(out guildId) && context.TryGetChannelID(out channelId) && context.TryGetUserID(out userId); diff --git a/src/Services/UtilityService.cs b/src/Services/UtilityService.cs index 81acd85..6ddc204 100644 --- a/src/Services/UtilityService.cs +++ b/src/Services/UtilityService.cs @@ -185,12 +185,12 @@ public class UtilityService : IHostedService { var builtArray = new[] { logBuilt }; // Not awaiting to reduce response time - if (isPublic && publicChannel != channelId.Value) + if (isPublic && publicChannel != channelId) _ = _channelApi.CreateMessageAsync( publicChannel, embeds: builtArray, ct: ct); if (privateChannel != publicChannel - && privateChannel != channelId.Value) + && privateChannel != channelId) _ = _channelApi.CreateMessageAsync( privateChannel, embeds: builtArray, ct: ct);