From 2ab020a2b49eb49b766f1a41abf14579bd9705fb Mon Sep 17 00:00:00 2001 From: Octol1ttle Date: Wed, 4 Oct 2023 20:21:10 +0500 Subject: [PATCH] Change IUser variable and parameter names to be less confusing (#149) note: there are still instances of `IUser user` because I could not find a better name for them --------- Signed-off-by: Octol1ttle --- src/Commands/AboutCommandGroup.cs | 12 +-- src/Commands/BanCommandGroup.cs | 64 +++++++------ src/Commands/ClearCommandGroup.cs | 40 ++++----- src/Commands/KickCommandGroup.cs | 32 +++---- src/Commands/MuteCommandGroup.cs | 105 +++++++++++----------- src/Commands/PingCommandGroup.cs | 12 +-- src/Commands/RemindCommandGroup.cs | 57 ++++++------ src/Commands/SettingsCommandGroup.cs | 56 ++++++------ src/Commands/ToolsCommandGroup.cs | 66 +++++++------- src/Data/GuildData.cs | 8 +- src/Extensions.cs | 6 +- src/Responders/GuildLoadedResponder.cs | 8 +- src/Responders/MessageDeletedResponder.cs | 10 +-- src/Services/UtilityService.cs | 20 ++--- 14 files changed, 245 insertions(+), 251 deletions(-) diff --git a/src/Commands/AboutCommandGroup.cs b/src/Commands/AboutCommandGroup.cs index c6a6ed3..c034907 100644 --- a/src/Commands/AboutCommandGroup.cs +++ b/src/Commands/AboutCommandGroup.cs @@ -66,19 +66,19 @@ public class AboutCommandGroup : CommandGroup return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(currentUserResult); + return Result.FromError(botResult); } var cfg = await _guildData.GetSettings(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(cfg); - return await SendAboutBotAsync(currentUser, guildId, CancellationToken); + return await SendAboutBotAsync(bot, guildId, CancellationToken); } - private async Task SendAboutBotAsync(IUser currentUser, Snowflake guildId, CancellationToken ct = default) + private async Task SendAboutBotAsync(IUser bot, Snowflake guildId, CancellationToken ct = default) { var builder = new StringBuilder().Append("### ").AppendLine(Messages.AboutTitleDevelopers); foreach (var dev in Developers) @@ -92,7 +92,7 @@ public class AboutCommandGroup : CommandGroup builder.Append($"### [{Messages.AboutTitleRepository}](https://github.com/LabsDevelopment/Octobot)"); - var embed = new EmbedBuilder().WithSmallTitle(Messages.AboutBot, currentUser) + var embed = new EmbedBuilder().WithSmallTitle(Messages.AboutBot, bot) .WithDescription(builder.ToString()) .WithColour(ColorsList.Cyan) .WithImageUrl("https://mctaylors.ddns.net/cdn/octobot-banner.png") diff --git a/src/Commands/BanCommandGroup.cs b/src/Commands/BanCommandGroup.cs index a76e79c..010a9da 100644 --- a/src/Commands/BanCommandGroup.cs +++ b/src/Commands/BanCommandGroup.cs @@ -74,22 +74,22 @@ public class BanCommandGroup : CommandGroup [Description("Ban reason")] string reason, [Description("Ban duration")] TimeSpan? duration = null) { - if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var userId)) + if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId)) { return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - // The current user's avatar is used when sending error messages - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) + // The bot's avatar is used when sending error messages + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(currentUserResult); + return Result.FromError(botResult); } - var userResult = await _userApi.GetUserAsync(userId, CancellationToken); - if (!userResult.IsDefined(out var user)) + var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); + if (!executorResult.IsDefined(out var executor)) { - return Result.FromError(userResult); + return Result.FromError(executorResult); } var guildResult = await _guildApi.GetGuildAsync(guildId, ct: CancellationToken); @@ -101,25 +101,24 @@ public class BanCommandGroup : CommandGroup var data = await _guildData.GetData(guild.ID, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - return await BanUserAsync( - target, reason, duration, guild, data, channelId, user, currentUser, CancellationToken); + return await BanUserAsync(executor, target, reason, duration, guild, data, channelId, bot, CancellationToken); } private async Task BanUserAsync( - IUser target, string reason, TimeSpan? duration, IGuild guild, GuildData data, Snowflake channelId, - IUser user, IUser currentUser, CancellationToken ct = default) + IUser executor, IUser target, string reason, TimeSpan? duration, IGuild guild, GuildData data, Snowflake channelId, + IUser bot, CancellationToken ct = default) { var existingBanResult = await _guildApi.GetGuildBanAsync(guild.ID, target.ID, ct); if (existingBanResult.IsDefined()) { - var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.UserAlreadyBanned, currentUser) + var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.UserAlreadyBanned, bot) .WithColour(ColorsList.Red).Build(); return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct); } var interactionResult - = await _utility.CheckInteractionsAsync(guild.ID, user.ID, target.ID, "Ban", ct); + = await _utility.CheckInteractionsAsync(guild.ID, executor.ID, target.ID, "Ban", ct); if (!interactionResult.IsSuccess) { return Result.FromError(interactionResult); @@ -127,7 +126,7 @@ public class BanCommandGroup : CommandGroup if (interactionResult.Entity is not null) { - var errorEmbed = new EmbedBuilder().WithSmallTitle(interactionResult.Entity, currentUser) + var errorEmbed = new EmbedBuilder().WithSmallTitle(interactionResult.Entity, bot) .WithColour(ColorsList.Red).Build(); return await _feedback.SendContextualEmbedResultAsync(errorEmbed, ct); @@ -152,7 +151,7 @@ public class BanCommandGroup : CommandGroup var dmEmbed = new EmbedBuilder().WithGuildTitle(guild) .WithTitle(Messages.YouWereBanned) .WithDescription(description) - .WithActionFooter(user) + .WithActionFooter(executor) .WithCurrentTimestamp() .WithColour(ColorsList.Red) .Build(); @@ -166,7 +165,7 @@ public class BanCommandGroup : CommandGroup } var banResult = await _guildApi.CreateGuildBanAsync( - guild.ID, target.ID, reason: $"({user.GetTag()}) {reason}".EncodeHeader(), + guild.ID, target.ID, reason: $"({executor.GetTag()}) {reason}".EncodeHeader(), ct: ct); if (!banResult.IsSuccess) { @@ -183,7 +182,7 @@ public class BanCommandGroup : CommandGroup .WithColour(ColorsList.Green).Build(); var logResult = _utility.LogActionAsync( - data.Settings, channelId, user, title, description, target, ColorsList.Red, ct: ct); + data.Settings, channelId, executor, title, description, target, ColorsList.Red, ct: ct); if (!logResult.IsSuccess) { return Result.FromError(logResult.Error); @@ -218,47 +217,46 @@ public class BanCommandGroup : CommandGroup [Description("User to unban")] IUser target, [Description("Unban reason")] string reason) { - if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var userId)) + if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId)) { return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - // The current user's avatar is used when sending error messages - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) + // The bot's avatar is used when sending error messages + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(currentUserResult); + return Result.FromError(botResult); } // Needed to get the tag and avatar - var userResult = await _userApi.GetUserAsync(userId, CancellationToken); - if (!userResult.IsDefined(out var user)) + var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); + if (!executorResult.IsDefined(out var executor)) { - return Result.FromError(userResult); + return Result.FromError(executorResult); } var data = await _guildData.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - return await UnbanUserAsync( - target, reason, guildId, data, channelId, user, currentUser, CancellationToken); + return await UnbanUserAsync(executor, target, reason, guildId, data, channelId, bot, CancellationToken); } private async Task UnbanUserAsync( - IUser target, string reason, Snowflake guildId, GuildData data, Snowflake channelId, IUser user, - IUser currentUser, CancellationToken ct = default) + IUser executor, IUser target, string reason, Snowflake guildId, GuildData data, Snowflake channelId, + IUser bot, CancellationToken ct = default) { var existingBanResult = await _guildApi.GetGuildBanAsync(guildId, target.ID, ct); if (!existingBanResult.IsDefined()) { - var errorEmbed = new EmbedBuilder().WithSmallTitle(Messages.UserNotBanned, currentUser) + var errorEmbed = new EmbedBuilder().WithSmallTitle(Messages.UserNotBanned, bot) .WithColour(ColorsList.Red).Build(); return await _feedback.SendContextualEmbedResultAsync(errorEmbed, ct); } var unbanResult = await _guildApi.RemoveGuildBanAsync( - guildId, target.ID, $"({user.GetTag()}) {reason}".EncodeHeader(), + guildId, target.ID, $"({executor.GetTag()}) {reason}".EncodeHeader(), ct); if (!unbanResult.IsSuccess) { @@ -275,7 +273,7 @@ public class BanCommandGroup : CommandGroup var description = new StringBuilder().Append("- ") .Append(string.Format(Messages.DescriptionActionReason, reason)); var logResult = _utility.LogActionAsync( - data.Settings, channelId, user, title, description.ToString(), target, ColorsList.Green, ct: ct); + data.Settings, channelId, executor, title, description.ToString(), target, ColorsList.Green, ct: ct); if (!logResult.IsSuccess) { return Result.FromError(logResult.Error); diff --git a/src/Commands/ClearCommandGroup.cs b/src/Commands/ClearCommandGroup.cs index e6c08f3..c963fdf 100644 --- a/src/Commands/ClearCommandGroup.cs +++ b/src/Commands/ClearCommandGroup.cs @@ -63,11 +63,24 @@ public class ClearCommandGroup : CommandGroup [Description("Number of messages to remove (2-100)")] [MinValue(2)] [MaxValue(100)] int amount) { - if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var userId)) + if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId)) { return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } + // The bot's avatar is used when sending messages + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) + { + return Result.FromError(botResult); + } + + var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); + if (!executorResult.IsDefined(out var executor)) + { + return Result.FromError(executorResult); + } + var messagesResult = await _channelApi.GetChannelMessagesAsync( channelId, limit: amount + 1, ct: CancellationToken); if (!messagesResult.IsDefined(out var messages)) @@ -75,28 +88,15 @@ public class ClearCommandGroup : CommandGroup return Result.FromError(messagesResult); } - 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 - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) - { - return Result.FromError(currentUserResult); - } - var data = await _guildData.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - return await ClearMessagesAsync(amount, data, channelId, messages, user, currentUser, CancellationToken); + return await ClearMessagesAsync(executor, amount, data, channelId, messages, bot, CancellationToken); } private async Task ClearMessagesAsync( - int amount, GuildData data, Snowflake channelId, IReadOnlyList messages, - IUser user, IUser currentUser, CancellationToken ct = default) + IUser executor, int amount, GuildData data, Snowflake channelId, IReadOnlyList messages, IUser bot, + CancellationToken ct = default) { var idList = new List(messages.Count); var builder = new StringBuilder().AppendLine(Mention.Channel(channelId)).AppendLine(); @@ -112,20 +112,20 @@ public class ClearCommandGroup : CommandGroup var description = builder.ToString(); var deleteResult = await _channelApi.BulkDeleteMessagesAsync( - channelId, idList, user.GetTag().EncodeHeader(), ct); + channelId, idList, executor.GetTag().EncodeHeader(), ct); if (!deleteResult.IsSuccess) { return Result.FromError(deleteResult.Error); } var logResult = _utility.LogActionAsync( - data.Settings, channelId, user, title, description, currentUser, ColorsList.Red, false, ct); + data.Settings, channelId, executor, title, description, bot, ColorsList.Red, false, ct); if (!logResult.IsSuccess) { return Result.FromError(logResult.Error); } - var embed = new EmbedBuilder().WithSmallTitle(title, currentUser) + var embed = new EmbedBuilder().WithSmallTitle(title, bot) .WithColour(ColorsList.Green).Build(); return await _feedback.SendContextualEmbedResultAsync(embed, ct); diff --git a/src/Commands/KickCommandGroup.cs b/src/Commands/KickCommandGroup.cs index f69103d..2ee99a9 100644 --- a/src/Commands/KickCommandGroup.cs +++ b/src/Commands/KickCommandGroup.cs @@ -68,22 +68,22 @@ public class KickCommandGroup : CommandGroup [Description("Member to kick")] IUser target, [Description("Kick reason")] string reason) { - if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var userId)) + if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId)) { return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - // The current user's avatar is used when sending error messages - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) + // The bot's avatar is used when sending error messages + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(currentUserResult); + return Result.FromError(botResult); } - var userResult = await _userApi.GetUserAsync(userId, CancellationToken); - if (!userResult.IsDefined(out var user)) + var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); + if (!executorResult.IsDefined(out var executor)) { - return Result.FromError(userResult); + return Result.FromError(executorResult); } var guildResult = await _guildApi.GetGuildAsync(guildId, ct: CancellationToken); @@ -98,21 +98,21 @@ public class KickCommandGroup : CommandGroup var memberResult = await _guildApi.GetGuildMemberAsync(guildId, target.ID, CancellationToken); if (!memberResult.IsSuccess) { - var embed = new EmbedBuilder().WithSmallTitle(Messages.UserNotFoundShort, currentUser) + var embed = new EmbedBuilder().WithSmallTitle(Messages.UserNotFoundShort, bot) .WithColour(ColorsList.Red).Build(); return await _feedback.SendContextualEmbedResultAsync(embed, CancellationToken); } - return await KickUserAsync(target, reason, guild, channelId, data, user, currentUser, CancellationToken); + return await KickUserAsync(executor, target, reason, guild, channelId, data, bot, CancellationToken); } private async Task KickUserAsync( - IUser target, string reason, IGuild guild, Snowflake channelId, GuildData data, IUser user, IUser currentUser, + IUser executor, IUser target, string reason, IGuild guild, Snowflake channelId, GuildData data, IUser bot, CancellationToken ct = default) { var interactionResult - = await _utility.CheckInteractionsAsync(guild.ID, user.ID, target.ID, "Kick", ct); + = await _utility.CheckInteractionsAsync(guild.ID, executor.ID, target.ID, "Kick", ct); if (!interactionResult.IsSuccess) { return Result.FromError(interactionResult); @@ -120,7 +120,7 @@ public class KickCommandGroup : CommandGroup if (interactionResult.Entity is not null) { - var failedEmbed = new EmbedBuilder().WithSmallTitle(interactionResult.Entity, currentUser) + var failedEmbed = new EmbedBuilder().WithSmallTitle(interactionResult.Entity, bot) .WithColour(ColorsList.Red).Build(); return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct); @@ -132,7 +132,7 @@ public class KickCommandGroup : CommandGroup var dmEmbed = new EmbedBuilder().WithGuildTitle(guild) .WithTitle(Messages.YouWereKicked) .WithDescription($"- {string.Format(Messages.DescriptionActionReason, reason)}") - .WithActionFooter(user) + .WithActionFooter(executor) .WithCurrentTimestamp() .WithColour(ColorsList.Red) .Build(); @@ -146,7 +146,7 @@ public class KickCommandGroup : CommandGroup } var kickResult = await _guildApi.RemoveGuildMemberAsync( - guild.ID, target.ID, $"({user.GetTag()}) {reason}".EncodeHeader(), + guild.ID, target.ID, $"({executor.GetTag()}) {reason}".EncodeHeader(), ct); if (!kickResult.IsSuccess) { @@ -158,7 +158,7 @@ public class KickCommandGroup : CommandGroup var title = string.Format(Messages.UserKicked, target.GetTag()); var description = $"- {string.Format(Messages.DescriptionActionReason, reason)}"; var logResult = _utility.LogActionAsync( - data.Settings, channelId, user, title, description, target, ColorsList.Red, ct: ct); + data.Settings, channelId, executor, title, description, target, ColorsList.Red, ct: ct); if (!logResult.IsSuccess) { return Result.FromError(logResult.Error); diff --git a/src/Commands/MuteCommandGroup.cs b/src/Commands/MuteCommandGroup.cs index 5146fc3..4ec4c6c 100644 --- a/src/Commands/MuteCommandGroup.cs +++ b/src/Commands/MuteCommandGroup.cs @@ -71,22 +71,22 @@ public class MuteCommandGroup : CommandGroup [Description("Mute reason")] string reason, [Description("Mute duration")] TimeSpan duration) { - if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var userId)) + if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId)) { return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - // The current user's avatar is used when sending error messages - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) + // The bot's avatar is used when sending error messages + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(currentUserResult); + return Result.FromError(botResult); } - var userResult = await _userApi.GetUserAsync(userId, CancellationToken); - if (!userResult.IsDefined(out var user)) + var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); + if (!executorResult.IsDefined(out var executor)) { - return Result.FromError(userResult); + return Result.FromError(executorResult); } var data = await _guildData.GetData(guildId, CancellationToken); @@ -95,23 +95,22 @@ public class MuteCommandGroup : CommandGroup var memberResult = await _guildApi.GetGuildMemberAsync(guildId, target.ID, CancellationToken); if (!memberResult.IsSuccess) { - var embed = new EmbedBuilder().WithSmallTitle(Messages.UserNotFoundShort, currentUser) + var embed = new EmbedBuilder().WithSmallTitle(Messages.UserNotFoundShort, bot) .WithColour(ColorsList.Red).Build(); return await _feedback.SendContextualEmbedResultAsync(embed, CancellationToken); } - return await MuteUserAsync( - target, reason, duration, guildId, data, channelId, user, currentUser, CancellationToken); + return await MuteUserAsync(executor, target, reason, duration, guildId, data, channelId, bot, CancellationToken); } private async Task MuteUserAsync( - IUser target, string reason, TimeSpan duration, Snowflake guildId, GuildData data, Snowflake channelId, - IUser user, IUser currentUser, CancellationToken ct = default) + IUser executor, IUser target, string reason, TimeSpan duration, Snowflake guildId, GuildData data, + Snowflake channelId, IUser bot, CancellationToken ct = default) { var interactionResult = await _utility.CheckInteractionsAsync( - guildId, user.ID, target.ID, "Mute", ct); + guildId, executor.ID, target.ID, "Mute", ct); if (!interactionResult.IsSuccess) { return Result.FromError(interactionResult); @@ -119,7 +118,7 @@ public class MuteCommandGroup : CommandGroup if (interactionResult.Entity is not null) { - var failedEmbed = new EmbedBuilder().WithSmallTitle(interactionResult.Entity, currentUser) + var failedEmbed = new EmbedBuilder().WithSmallTitle(interactionResult.Entity, bot) .WithColour(ColorsList.Red).Build(); return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct); @@ -127,8 +126,7 @@ public class MuteCommandGroup : CommandGroup var until = DateTimeOffset.UtcNow.Add(duration); // >:) - var muteMethodResult = await SelectMuteMethodAsync( - target, reason, duration, guildId, data, user, currentUser, until, ct); + var muteMethodResult = await SelectMuteMethodAsync(executor, target, reason, duration, guildId, data, bot, until, ct); if (!muteMethodResult.IsSuccess) { return muteMethodResult; @@ -140,7 +138,7 @@ public class MuteCommandGroup : CommandGroup Messages.DescriptionActionExpiresAt, Markdown.Timestamp(until))).ToString(); var logResult = _utility.LogActionAsync( - data.Settings, channelId, user, title, description, target, ColorsList.Red, ct: ct); + data.Settings, channelId, executor, title, description, target, ColorsList.Red, ct: ct); if (!logResult.IsSuccess) { return Result.FromError(logResult.Error); @@ -154,26 +152,24 @@ public class MuteCommandGroup : CommandGroup } private async Task SelectMuteMethodAsync( - IUser target, string reason, TimeSpan duration, Snowflake guildId, GuildData data, - IUser user, IUser currentUser, DateTimeOffset until, CancellationToken ct) + IUser executor, IUser target, string reason, TimeSpan duration, Snowflake guildId, GuildData data, + IUser bot, DateTimeOffset until, CancellationToken ct) { var muteRole = GuildSettings.MuteRole.Get(data.Settings); if (muteRole.Empty()) { - var timeoutResult = await TimeoutUserAsync( - target, reason, duration, guildId, user, currentUser, until, ct); + var timeoutResult = await TimeoutUserAsync(executor, target, reason, duration, guildId, bot, until, ct); return timeoutResult; } - var muteRoleResult = await RoleMuteUserAsync( - target, reason, guildId, data, user, until, muteRole, ct); + var muteRoleResult = await RoleMuteUserAsync(executor, target, reason, guildId, data, until, muteRole, ct); return muteRoleResult; } private async Task RoleMuteUserAsync( - IUser target, string reason, Snowflake guildId, GuildData data, - IUser user, DateTimeOffset until, Snowflake muteRole, CancellationToken ct) + IUser executor, IUser target, string reason, Snowflake guildId, GuildData data, + DateTimeOffset until, Snowflake muteRole, CancellationToken ct) { var assignRoles = new List { muteRole }; var memberData = data.GetOrCreateMemberData(target.ID); @@ -184,7 +180,7 @@ public class MuteCommandGroup : CommandGroup var muteResult = await _guildApi.ModifyGuildMemberAsync( guildId, target.ID, roles: assignRoles, - reason: $"({user.GetTag()}) {reason}".EncodeHeader(), ct: ct); + reason: $"({executor.GetTag()}) {reason}".EncodeHeader(), ct: ct); if (muteResult.IsSuccess) { memberData.MutedUntil = until; @@ -194,12 +190,12 @@ public class MuteCommandGroup : CommandGroup } private async Task TimeoutUserAsync( - IUser target, string reason, TimeSpan duration, Snowflake guildId, - IUser user, IUser currentUser, DateTimeOffset until, CancellationToken ct) + IUser executor, IUser target, string reason, TimeSpan duration, Snowflake guildId, + IUser bot, DateTimeOffset until, CancellationToken ct) { if (duration.TotalDays >= 28) { - var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.BotCannotMuteTarget, currentUser) + var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.BotCannotMuteTarget, bot) .WithDescription(Messages.DurationRequiredForTimeOuts) .WithColour(ColorsList.Red).Build(); @@ -207,7 +203,7 @@ public class MuteCommandGroup : CommandGroup } var muteResult = await _guildApi.ModifyGuildMemberAsync( - guildId, target.ID, reason: $"({user.GetTag()}) {reason}".EncodeHeader(), + guildId, target.ID, reason: $"({executor.GetTag()}) {reason}".EncodeHeader(), communicationDisabledUntil: until, ct: ct); return muteResult; } @@ -238,23 +234,23 @@ public class MuteCommandGroup : CommandGroup [Description("Member to unmute")] IUser target, [Description("Unmute reason")] string reason) { - if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var userId)) + if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId)) { return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - // The current user's avatar is used when sending error messages - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) + // The bot's avatar is used when sending error messages + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(currentUserResult); + return Result.FromError(botResult); } // Needed to get the tag and avatar - var userResult = await _userApi.GetUserAsync(userId, CancellationToken); - if (!userResult.IsDefined(out var user)) + var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); + if (!executorResult.IsDefined(out var executor)) { - return Result.FromError(userResult); + return Result.FromError(executorResult); } var data = await _guildData.GetData(guildId, CancellationToken); @@ -263,23 +259,22 @@ public class MuteCommandGroup : CommandGroup var memberResult = await _guildApi.GetGuildMemberAsync(guildId, target.ID, CancellationToken); if (!memberResult.IsSuccess) { - var embed = new EmbedBuilder().WithSmallTitle(Messages.UserNotFoundShort, currentUser) + var embed = new EmbedBuilder().WithSmallTitle(Messages.UserNotFoundShort, bot) .WithColour(ColorsList.Red).Build(); return await _feedback.SendContextualEmbedResultAsync(embed, CancellationToken); } - return await RemoveMuteAsync( - target, reason, guildId, data, channelId, user, currentUser, CancellationToken); + return await RemoveMuteAsync(executor, target, reason, guildId, data, channelId, bot, CancellationToken); } private async Task RemoveMuteAsync( - IUser target, string reason, Snowflake guildId, GuildData data, Snowflake channelId, IUser user, - IUser currentUser, CancellationToken ct = default) + IUser executor, IUser target, string reason, Snowflake guildId, GuildData data, Snowflake channelId, + IUser bot, CancellationToken ct = default) { var interactionResult = await _utility.CheckInteractionsAsync( - guildId, user.ID, target.ID, "Unmute", ct); + guildId, executor.ID, target.ID, "Unmute", ct); if (!interactionResult.IsSuccess) { return Result.FromError(interactionResult); @@ -287,7 +282,7 @@ public class MuteCommandGroup : CommandGroup if (interactionResult.Entity is not null) { - var failedEmbed = new EmbedBuilder().WithSmallTitle(interactionResult.Entity, currentUser) + var failedEmbed = new EmbedBuilder().WithSmallTitle(interactionResult.Entity, bot) .WithColour(ColorsList.Red).Build(); return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct); @@ -305,21 +300,21 @@ public class MuteCommandGroup : CommandGroup if (!isMuted) { - var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.UserNotMuted, currentUser) + var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.UserNotMuted, bot) .WithColour(ColorsList.Red).Build(); return await _feedback.SendContextualEmbedResultAsync(failedEmbed, ct); } var removeMuteRoleAsync = - await RemoveMuteRoleAsync(target, reason, guildId, memberData, user, CancellationToken); + await RemoveMuteRoleAsync(executor, target, reason, guildId, memberData, CancellationToken); if (!removeMuteRoleAsync.IsSuccess) { return Result.FromError(removeMuteRoleAsync.Error); } var removeTimeoutResult = - await RemoveTimeoutAsync(target, reason, guildId, communicationDisabledUntil, user, CancellationToken); + await RemoveTimeoutAsync(executor, target, reason, guildId, communicationDisabledUntil, CancellationToken); if (!removeTimeoutResult.IsSuccess) { return Result.FromError(removeTimeoutResult.Error); @@ -328,7 +323,7 @@ public class MuteCommandGroup : CommandGroup var title = string.Format(Messages.UserUnmuted, target.GetTag()); var description = $"- {string.Format(Messages.DescriptionActionReason, reason)}"; var logResult = _utility.LogActionAsync( - data.Settings, channelId, user, title, description, target, ColorsList.Green, ct: ct); + data.Settings, channelId, executor, title, description, target, ColorsList.Green, ct: ct); if (!logResult.IsSuccess) { return Result.FromError(logResult.Error); @@ -342,7 +337,7 @@ public class MuteCommandGroup : CommandGroup } private async Task RemoveMuteRoleAsync( - IUser target, string reason, Snowflake guildId, MemberData memberData, IUser user, CancellationToken ct = default) + IUser executor, IUser target, string reason, Snowflake guildId, MemberData memberData, CancellationToken ct = default) { if (memberData.MutedUntil is null) { @@ -351,7 +346,7 @@ public class MuteCommandGroup : CommandGroup var unmuteResult = await _guildApi.ModifyGuildMemberAsync( guildId, target.ID, roles: memberData.Roles.ConvertAll(r => r.ToSnowflake()), - reason: $"({user.GetTag()}) {reason}".EncodeHeader(), ct: ct); + reason: $"({executor.GetTag()}) {reason}".EncodeHeader(), ct: ct); if (unmuteResult.IsSuccess) { memberData.MutedUntil = null; @@ -361,8 +356,8 @@ public class MuteCommandGroup : CommandGroup } private async Task RemoveTimeoutAsync( - IUser target, string reason, Snowflake guildId, DateTimeOffset? communicationDisabledUntil, - IUser user, CancellationToken ct = default) + IUser executor, IUser target, string reason, Snowflake guildId, DateTimeOffset? communicationDisabledUntil, + CancellationToken ct = default) { if (communicationDisabledUntil is null) { @@ -370,7 +365,7 @@ public class MuteCommandGroup : CommandGroup } var unmuteResult = await _guildApi.ModifyGuildMemberAsync( - guildId, target.ID, reason: $"({user.GetTag()}) {reason}".EncodeHeader(), + guildId, target.ID, reason: $"({executor.GetTag()}) {reason}".EncodeHeader(), communicationDisabledUntil: null, ct: ct); return unmuteResult; } diff --git a/src/Commands/PingCommandGroup.cs b/src/Commands/PingCommandGroup.cs index 07851a7..a1b14bd 100644 --- a/src/Commands/PingCommandGroup.cs +++ b/src/Commands/PingCommandGroup.cs @@ -60,20 +60,20 @@ public class PingCommandGroup : CommandGroup return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(currentUserResult); + return Result.FromError(botResult); } var cfg = await _guildData.GetSettings(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(cfg); - return await SendLatencyAsync(channelId, currentUser, CancellationToken); + return await SendLatencyAsync(channelId, bot, CancellationToken); } private async Task SendLatencyAsync( - Snowflake channelId, IUser currentUser, CancellationToken ct = default) + Snowflake channelId, IUser bot, CancellationToken ct = default) { var latency = _client.Latency.TotalMilliseconds; if (latency is 0) @@ -89,7 +89,7 @@ public class PingCommandGroup : CommandGroup latency = DateTimeOffset.UtcNow.Subtract(lastMessage.Single().Timestamp).TotalMilliseconds; } - var embed = new EmbedBuilder().WithSmallTitle(currentUser.GetTag(), currentUser) + var embed = new EmbedBuilder().WithSmallTitle(bot.GetTag(), bot) .WithTitle($"Sound{Random.Shared.Next(1, 4)}".Localized()) .WithDescription($"{latency:F0}{Messages.Milliseconds}") .WithColour(latency < 250 ? ColorsList.Green : latency < 500 ? ColorsList.Yellow : ColorsList.Red) diff --git a/src/Commands/RemindCommandGroup.cs b/src/Commands/RemindCommandGroup.cs index cead86e..b6bb235 100644 --- a/src/Commands/RemindCommandGroup.cs +++ b/src/Commands/RemindCommandGroup.cs @@ -50,34 +50,34 @@ public class RemindCommandGroup : CommandGroup [UsedImplicitly] public async Task ExecuteListReminderAsync() { - if (!_context.TryGetContextIDs(out var guildId, out _, out var userId)) + if (!_context.TryGetContextIDs(out var guildId, out _, out var executorId)) { return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - var userResult = await _userApi.GetUserAsync(userId, CancellationToken); - if (!userResult.IsDefined(out var user)) + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(userResult); + return Result.FromError(botResult); } - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) + var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); + if (!executorResult.IsDefined(out var executor)) { - return Result.FromError(currentUserResult); + return Result.FromError(executorResult); } var data = await _guildData.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - return await ListRemindersAsync(data.GetOrCreateMemberData(userId), user, currentUser, CancellationToken); + return await ListRemindersAsync(data.GetOrCreateMemberData(executorId), executor, bot, CancellationToken); } - private async Task ListRemindersAsync(MemberData data, IUser user, IUser currentUser, CancellationToken ct) + private async Task ListRemindersAsync(MemberData data, IUser executor, IUser bot, CancellationToken ct) { if (data.Reminders.Count == 0) { - var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.NoRemindersFound, currentUser) + var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.NoRemindersFound, bot) .WithColour(ColorsList.Red) .Build(); @@ -90,11 +90,12 @@ public class RemindCommandGroup : CommandGroup var reminder = data.Reminders[i]; builder.Append("- ").AppendLine(string.Format(Messages.ReminderIndex, Markdown.InlineCode(i.ToString()))) .Append(" - ").AppendLine(string.Format(Messages.ReminderText, Markdown.InlineCode(reminder.Text))) - .Append(" - ").AppendLine(string.Format(Messages.ReminderWillBeSentOn, Markdown.Timestamp(reminder.At))); + .Append(" - ") + .AppendLine(string.Format(Messages.ReminderWillBeSentOn, Markdown.Timestamp(reminder.At))); } var embed = new EmbedBuilder().WithSmallTitle( - string.Format(Messages.ReminderList, user.GetTag()), user) + string.Format(Messages.ReminderList, executor.GetTag()), executor) .WithDescription(builder.ToString()) .WithColour(ColorsList.Cyan) .Build(); @@ -119,30 +120,30 @@ public class RemindCommandGroup : CommandGroup TimeSpan @in, [Description("Reminder message")] string message) { - if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var userId)) + if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId)) { return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - var userResult = await _userApi.GetUserAsync(userId, CancellationToken); - if (!userResult.IsDefined(out var user)) + var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); + if (!executorResult.IsDefined(out var executor)) { - return Result.FromError(userResult); + return Result.FromError(executorResult); } var data = await _guildData.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - return await AddReminderAsync(@in, message, data, channelId, user, CancellationToken); + return await AddReminderAsync(@in, message, data, channelId, executor, CancellationToken); } private async Task AddReminderAsync( TimeSpan @in, string message, GuildData data, - Snowflake channelId, IUser user, CancellationToken ct = default) + Snowflake channelId, IUser executor, CancellationToken ct = default) { var remindAt = DateTimeOffset.UtcNow.Add(@in); - data.GetOrCreateMemberData(user.ID).Reminders.Add( + data.GetOrCreateMemberData(executor.ID).Reminders.Add( new Reminder { At = remindAt, @@ -155,7 +156,7 @@ public class RemindCommandGroup : CommandGroup .Append("- ").Append(string.Format(Messages.ReminderWillBeSentOn, Markdown.Timestamp(remindAt))); var embed = new EmbedBuilder().WithSmallTitle( - string.Format(Messages.ReminderCreated, user.GetTag()), user) + string.Format(Messages.ReminderCreated, executor.GetTag()), executor) .WithDescription(builder.ToString()) .WithColour(ColorsList.Green) .Build(); @@ -177,29 +178,29 @@ public class RemindCommandGroup : CommandGroup [Description("Index of reminder to delete")] [MinValue(0)] int index) { - if (!_context.TryGetContextIDs(out var guildId, out _, out var userId)) + if (!_context.TryGetContextIDs(out var guildId, out _, out var executorId)) { return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(currentUserResult); + return Result.FromError(botResult); } var data = await _guildData.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - return await DeleteReminderAsync(data.GetOrCreateMemberData(userId), index, currentUser, CancellationToken); + return await DeleteReminderAsync(data.GetOrCreateMemberData(executorId), index, bot, CancellationToken); } - private async Task DeleteReminderAsync(MemberData data, int index, IUser currentUser, + private async Task DeleteReminderAsync(MemberData data, int index, IUser bot, CancellationToken ct) { if (index >= data.Reminders.Count) { - var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.InvalidReminderIndex, currentUser) + var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.InvalidReminderIndex, bot) .WithColour(ColorsList.Red) .Build(); @@ -208,7 +209,7 @@ public class RemindCommandGroup : CommandGroup data.Reminders.RemoveAt(index); - var embed = new EmbedBuilder().WithSmallTitle(Messages.ReminderDeleted, currentUser) + var embed = new EmbedBuilder().WithSmallTitle(Messages.ReminderDeleted, bot) .WithColour(ColorsList.Green) .Build(); diff --git a/src/Commands/SettingsCommandGroup.cs b/src/Commands/SettingsCommandGroup.cs index 9f7c3df..fc4fbe7 100644 --- a/src/Commands/SettingsCommandGroup.cs +++ b/src/Commands/SettingsCommandGroup.cs @@ -91,19 +91,19 @@ public class SettingsCommandGroup : CommandGroup return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(currentUserResult); + return Result.FromError(botResult); } var cfg = await _guildData.GetSettings(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(cfg); - return await SendSettingsListAsync(cfg, currentUser, page, CancellationToken); + return await SendSettingsListAsync(cfg, bot, page, CancellationToken); } - private async Task SendSettingsListAsync(JsonNode cfg, IUser currentUser, int page, + private async Task SendSettingsListAsync(JsonNode cfg, IUser bot, int page, CancellationToken ct = default) { var description = new StringBuilder(); @@ -117,7 +117,7 @@ public class SettingsCommandGroup : CommandGroup if (firstOptionOnPage >= AllOptions.Length) { - var errorEmbed = new EmbedBuilder().WithSmallTitle(Messages.PageNotFound, currentUser) + var errorEmbed = new EmbedBuilder().WithSmallTitle(Messages.PageNotFound, bot) .WithDescription(string.Format(Messages.PagesAllowed, Markdown.Bold(totalPages.ToString()))) .WithColour(ColorsList.Red) .Build(); @@ -141,7 +141,7 @@ public class SettingsCommandGroup : CommandGroup .AppendLine(optionValue); } - var embed = new EmbedBuilder().WithSmallTitle(Messages.SettingsListTitle, currentUser) + var embed = new EmbedBuilder().WithSmallTitle(Messages.SettingsListTitle, bot) .WithDescription(description.ToString()) .WithColour(ColorsList.Default) .WithFooter(footer.ToString()) @@ -168,38 +168,38 @@ public class SettingsCommandGroup : CommandGroup AllOptionsEnum setting, [Description("Setting value")] string value) { - if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var userId)) + if (!_context.TryGetContextIDs(out var guildId, out var channelId, out var executorId)) { return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(currentUserResult); + return Result.FromError(botResult); } - var userResult = await _userApi.GetUserAsync(userId, CancellationToken); - if (!userResult.IsDefined(out var user)) + var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); + if (!executorResult.IsDefined(out var executor)) { - return Result.FromError(userResult); + return Result.FromError(executorResult); } var data = await _guildData.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - return await EditSettingAsync(AllOptions[(int)setting], value, data, channelId, user, currentUser, + return await EditSettingAsync(AllOptions[(int)setting], value, data, channelId, executor, bot, CancellationToken); } private async Task EditSettingAsync( - IOption option, string value, GuildData data, Snowflake channelId, IUser user, IUser currentUser, + IOption option, string value, GuildData data, Snowflake channelId, IUser executor, IUser bot, CancellationToken ct = default) { var setResult = option.Set(data.Settings, value); if (!setResult.IsSuccess) { - var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.SettingNotChanged, currentUser) + var failedEmbed = new EmbedBuilder().WithSmallTitle(Messages.SettingNotChanged, bot) .WithDescription(setResult.Error.Message) .WithColour(ColorsList.Red) .Build(); @@ -216,13 +216,13 @@ public class SettingsCommandGroup : CommandGroup var description = builder.ToString(); var logResult = _utility.LogActionAsync( - data.Settings, channelId, user, title, description, currentUser, ColorsList.Magenta, false, ct); + data.Settings, channelId, executor, title, description, bot, ColorsList.Magenta, false, ct); if (!logResult.IsSuccess) { return Result.FromError(logResult.Error); } - var embed = new EmbedBuilder().WithSmallTitle(title, currentUser) + var embed = new EmbedBuilder().WithSmallTitle(title, bot) .WithDescription(description) .WithColour(ColorsList.Green) .Build(); @@ -250,10 +250,10 @@ public class SettingsCommandGroup : CommandGroup return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(currentUserResult); + return Result.FromError(botResult); } var cfg = await _guildData.GetSettings(guildId, CancellationToken); @@ -261,13 +261,13 @@ public class SettingsCommandGroup : CommandGroup if (setting is not null) { - return await ResetSingleSettingAsync(cfg, currentUser, AllOptions[(int)setting], CancellationToken); + return await ResetSingleSettingAsync(cfg, bot, AllOptions[(int)setting], CancellationToken); } - return await ResetAllSettingsAsync(cfg, currentUser, CancellationToken); + return await ResetAllSettingsAsync(cfg, bot, CancellationToken); } - private async Task ResetSingleSettingAsync(JsonNode cfg, IUser currentUser, + private async Task ResetSingleSettingAsync(JsonNode cfg, IUser bot, IOption option, CancellationToken ct = default) { var resetResult = option.Reset(cfg); @@ -277,14 +277,14 @@ public class SettingsCommandGroup : CommandGroup } var embed = new EmbedBuilder().WithSmallTitle( - string.Format(Messages.SingleSettingReset, option.Name), currentUser) + string.Format(Messages.SingleSettingReset, option.Name), bot) .WithColour(ColorsList.Green) .Build(); return await _feedback.SendContextualEmbedResultAsync(embed, ct); } - private async Task ResetAllSettingsAsync(JsonNode cfg, IUser currentUser, + private async Task ResetAllSettingsAsync(JsonNode cfg, IUser bot, CancellationToken ct = default) { var failedResults = new List(); @@ -298,7 +298,7 @@ public class SettingsCommandGroup : CommandGroup return failedResults.AggregateErrors(); } - var embed = new EmbedBuilder().WithSmallTitle(Messages.AllSettingsReset, currentUser) + var embed = new EmbedBuilder().WithSmallTitle(Messages.AllSettingsReset, bot) .WithColour(ColorsList.Green) .Build(); diff --git a/src/Commands/ToolsCommandGroup.cs b/src/Commands/ToolsCommandGroup.cs index 445140d..f478907 100644 --- a/src/Commands/ToolsCommandGroup.cs +++ b/src/Commands/ToolsCommandGroup.cs @@ -71,48 +71,48 @@ public class ToolsCommandGroup : CommandGroup [Description("User to show info about")] IUser? target = null) { - if (!_context.TryGetContextIDs(out var guildId, out _, out var userId)) + if (!_context.TryGetContextIDs(out var guildId, out _, out var executorId)) { return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - var userResult = await _userApi.GetUserAsync(userId, CancellationToken); - if (!userResult.IsDefined(out var user)) + var botResult = await _userApi.GetCurrentUserAsync(CancellationToken); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(userResult); + return Result.FromError(botResult); } - var currentUserResult = await _userApi.GetCurrentUserAsync(CancellationToken); - if (!currentUserResult.IsDefined(out var currentUser)) + var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); + if (!executorResult.IsDefined(out var executor)) { - return Result.FromError(currentUserResult); + return Result.FromError(executorResult); } var data = await _guildData.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - return await ShowUserInfoAsync(target ?? user, currentUser, data, guildId, CancellationToken); + return await ShowUserInfoAsync(target ?? executor, bot, data, guildId, CancellationToken); } private async Task ShowUserInfoAsync( - IUser user, IUser currentUser, GuildData data, Snowflake guildId, CancellationToken ct = default) + IUser target, IUser bot, GuildData data, Snowflake guildId, CancellationToken ct = default) { - var builder = new StringBuilder().AppendLine($"### <@{user.ID}>"); + var builder = new StringBuilder().AppendLine($"### <@{target.ID}>"); - if (user.GlobalName is not null) + if (target.GlobalName is not null) { builder.Append("- ").AppendLine(Messages.ShowInfoDisplayName) - .AppendLine(Markdown.InlineCode(user.GlobalName)); + .AppendLine(Markdown.InlineCode(target.GlobalName)); } builder.Append("- ").AppendLine(Messages.ShowInfoDiscordUserSince) - .AppendLine(Markdown.Timestamp(user.ID.Timestamp)); + .AppendLine(Markdown.Timestamp(target.ID.Timestamp)); - var memberData = data.GetOrCreateMemberData(user.ID); + var memberData = data.GetOrCreateMemberData(target.ID); var embedColor = ColorsList.Cyan; - var guildMemberResult = await _guildApi.GetGuildMemberAsync(guildId, user.ID, ct); + var guildMemberResult = await _guildApi.GetGuildMemberAsync(guildId, target.ID, ct); DateTimeOffset? communicationDisabledUntil = null; if (guildMemberResult.IsDefined(out var guildMember)) { @@ -124,7 +124,7 @@ public class ToolsCommandGroup : CommandGroup var isMuted = (memberData.MutedUntil is not null && DateTimeOffset.UtcNow <= memberData.MutedUntil) || communicationDisabledUntil is not null; - var existingBanResult = await _guildApi.GetGuildBanAsync(guildId, user.ID, ct); + var existingBanResult = await _guildApi.GetGuildBanAsync(guildId, target.ID, ct); if (isMuted || existingBanResult.IsDefined()) { @@ -155,11 +155,11 @@ public class ToolsCommandGroup : CommandGroup } var embed = new EmbedBuilder().WithSmallTitle( - string.Format(Messages.ShowInfoTitle, user.GetTag()), currentUser) + string.Format(Messages.ShowInfoTitle, target.GetTag()), bot) .WithDescription(builder.ToString()) .WithColour(embedColor) - .WithLargeAvatar(user) - .WithFooter($"ID: {user.ID.ToString()}") + .WithLargeAvatar(target) + .WithFooter($"ID: {target.ID.ToString()}") .Build(); return await _feedback.SendContextualEmbedResultAsync(embed, ct); @@ -246,25 +246,25 @@ public class ToolsCommandGroup : CommandGroup [Description("Second number (Default: 0)")] long? second = null) { - if (!_context.TryGetContextIDs(out var guildId, out _, out var userId)) + if (!_context.TryGetContextIDs(out var guildId, out _, out var executorId)) { return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - var userResult = await _userApi.GetUserAsync(userId, CancellationToken); - if (!userResult.IsDefined(out var user)) + var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); + if (!executorResult.IsDefined(out var executor)) { - return Result.FromError(userResult); + return Result.FromError(executorResult); } var data = await _guildData.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - return await SendRandomNumberAsync(first, second, user, CancellationToken); + return await SendRandomNumberAsync(first, second, executor, CancellationToken); } private async Task SendRandomNumberAsync(long first, long? secondNullable, - IUser user, CancellationToken ct) + IUser executor, CancellationToken ct) { const long secondDefault = 0; var second = secondNullable ?? secondDefault; @@ -298,7 +298,7 @@ public class ToolsCommandGroup : CommandGroup } var embed = new EmbedBuilder().WithSmallTitle( - string.Format(Messages.RandomTitle, user.GetTag()), user) + string.Format(Messages.RandomTitle, executor.GetTag()), executor) .WithDescription(description.ToString()) .WithColour(embedColor) .Build(); @@ -332,24 +332,24 @@ public class ToolsCommandGroup : CommandGroup [Description("Offset from current time")] TimeSpan? offset = null) { - if (!_context.TryGetContextIDs(out var guildId, out _, out var userId)) + if (!_context.TryGetContextIDs(out var guildId, out _, out var executorId)) { return new ArgumentInvalidError(nameof(_context), "Unable to retrieve necessary IDs from command context"); } - var userResult = await _userApi.GetUserAsync(userId, CancellationToken); - if (!userResult.IsDefined(out var user)) + var executorResult = await _userApi.GetUserAsync(executorId, CancellationToken); + if (!executorResult.IsDefined(out var executor)) { - return Result.FromError(userResult); + return Result.FromError(executorResult); } var data = await _guildData.GetData(guildId, CancellationToken); Messages.Culture = GuildSettings.Language.Get(data.Settings); - return await SendTimestampAsync(offset, user, CancellationToken); + return await SendTimestampAsync(offset, executor, CancellationToken); } - private async Task SendTimestampAsync(TimeSpan? offset, IUser user, CancellationToken ct) + private async Task SendTimestampAsync(TimeSpan? offset, IUser executor, CancellationToken ct) { var timestamp = DateTimeOffset.UtcNow.Add(offset ?? TimeSpan.Zero).ToUnixTimeSeconds(); @@ -368,7 +368,7 @@ public class ToolsCommandGroup : CommandGroup } var embed = new EmbedBuilder().WithSmallTitle( - string.Format(Messages.TimestampTitle, user.GetTag()), user) + string.Format(Messages.TimestampTitle, executor.GetTag()), executor) .WithDescription(description.ToString()) .WithColour(ColorsList.Blue) .Build(); diff --git a/src/Data/GuildData.cs b/src/Data/GuildData.cs index a779b56..a675037 100644 --- a/src/Data/GuildData.cs +++ b/src/Data/GuildData.cs @@ -30,15 +30,15 @@ public sealed class GuildData MemberDataPath = memberDataPath; } - public MemberData GetOrCreateMemberData(Snowflake userId) + public MemberData GetOrCreateMemberData(Snowflake memberId) { - if (MemberData.TryGetValue(userId.Value, out var existing)) + if (MemberData.TryGetValue(memberId.Value, out var existing)) { return existing; } - var newData = new MemberData(userId.Value); - MemberData.Add(userId.Value, newData); + var newData = new MemberData(memberId.Value); + MemberData.Add(memberId.Value, newData); return newData; } } diff --git a/src/Extensions.cs b/src/Extensions.cs index 511ab85..20b15e6 100644 --- a/src/Extensions.cs +++ b/src/Extensions.cs @@ -215,13 +215,13 @@ public static class Extensions public static bool TryGetContextIDs( this ICommandContext context, out Snowflake guildId, - out Snowflake channelId, out Snowflake userId) + out Snowflake channelId, out Snowflake executorId) { channelId = default; - userId = default; + executorId = default; return context.TryGetGuildID(out guildId) && context.TryGetChannelID(out channelId) - && context.TryGetUserID(out userId); + && context.TryGetUserID(out executorId); } /// diff --git a/src/Responders/GuildLoadedResponder.cs b/src/Responders/GuildLoadedResponder.cs index b91b209..d78b69a 100644 --- a/src/Responders/GuildLoadedResponder.cs +++ b/src/Responders/GuildLoadedResponder.cs @@ -60,16 +60,16 @@ public class GuildLoadedResponder : IResponder return Result.FromSuccess(); } - var currentUserResult = await _userApi.GetCurrentUserAsync(ct); - if (!currentUserResult.IsDefined(out var currentUser)) + var botResult = await _userApi.GetCurrentUserAsync(ct); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(currentUserResult); + return Result.FromError(botResult); } Messages.Culture = GuildSettings.Language.Get(cfg); var i = Random.Shared.Next(1, 4); - var embed = new EmbedBuilder().WithSmallTitle(currentUser.GetTag(), currentUser) + var embed = new EmbedBuilder().WithSmallTitle(bot.GetTag(), bot) .WithTitle($"Sound{i}".Localized()) .WithDescription(Messages.Ready) .WithCurrentTimestamp() diff --git a/src/Responders/MessageDeletedResponder.cs b/src/Responders/MessageDeletedResponder.cs index ae92770..9233820 100644 --- a/src/Responders/MessageDeletedResponder.cs +++ b/src/Responders/MessageDeletedResponder.cs @@ -67,17 +67,17 @@ public class MessageDeletedResponder : IResponder var auditLog = auditLogPage.AuditLogEntries.Single(); - var userResult = Result.FromSuccess(message.Author); + var deleterResult = Result.FromSuccess(message.Author); if (auditLog.UserID is not null && auditLog.Options.Value.ChannelID == gatewayEvent.ChannelID && DateTimeOffset.UtcNow.Subtract(auditLog.ID.Timestamp).TotalSeconds <= 2) { - userResult = await _userApi.GetUserAsync(auditLog.UserID.Value, ct); + deleterResult = await _userApi.GetUserAsync(auditLog.UserID.Value, ct); } - if (!userResult.IsDefined(out var user)) + if (!deleterResult.IsDefined(out var deleter)) { - return Result.FromError(userResult); + return Result.FromError(deleterResult); } Messages.Culture = GuildSettings.Language.Get(cfg); @@ -93,7 +93,7 @@ public class MessageDeletedResponder : IResponder Messages.CachedMessageDeleted, message.Author.GetTag()), message.Author) .WithDescription(builder.ToString()) - .WithActionFooter(user) + .WithActionFooter(deleter) .WithTimestamp(message.Timestamp) .WithColour(ColorsList.Red) .Build(); diff --git a/src/Services/UtilityService.cs b/src/Services/UtilityService.cs index 4bd9add..22e38cb 100644 --- a/src/Services/UtilityService.cs +++ b/src/Services/UtilityService.cs @@ -69,10 +69,10 @@ public sealed class UtilityService : IHostedService return Result.FromSuccess($"UserCannot{action}Themselves".Localized()); } - var currentUserResult = await _userApi.GetCurrentUserAsync(ct); - if (!currentUserResult.IsDefined(out var currentUser)) + var botResult = await _userApi.GetCurrentUserAsync(ct); + if (!botResult.IsDefined(out var bot)) { - return Result.FromError(currentUserResult); + return Result.FromError(botResult); } var guildResult = await _guildApi.GetGuildAsync(guildId, ct: ct); @@ -87,7 +87,7 @@ public sealed class UtilityService : IHostedService return Result.FromSuccess(null); } - var currentMemberResult = await _guildApi.GetGuildMemberAsync(guildId, currentUser.ID, ct); + var currentMemberResult = await _guildApi.GetGuildMemberAsync(guildId, bot.ID, ct); if (!currentMemberResult.IsDefined(out var currentMember)) { return Result.FromError(currentMemberResult); @@ -167,11 +167,11 @@ public sealed class UtilityService : IHostedService { var builder = new StringBuilder(); var role = GuildSettings.EventNotificationRole.Get(settings); - var usersResult = await _eventApi.GetGuildScheduledEventUsersAsync( + var subscribersResult = await _eventApi.GetGuildScheduledEventUsersAsync( scheduledEvent.GuildID, scheduledEvent.ID, withMember: true, ct: ct); - if (!usersResult.IsDefined(out var users)) + if (!subscribersResult.IsDefined(out var subscribers)) { - return Result.FromError(usersResult); + return Result.FromError(subscribersResult); } if (!role.Empty()) @@ -179,9 +179,9 @@ public sealed class UtilityService : IHostedService builder.Append($"{Mention.Role(role)} "); } - builder = users.Where( - user => user.GuildMember.IsDefined(out var member) && !member.Roles.Contains(role)) - .Aggregate(builder, (current, user) => current.Append($"{Mention.User(user.User)} ")); + builder = subscribers.Where( + subscriber => subscriber.GuildMember.IsDefined(out var member) && !member.Roles.Contains(role)) + .Aggregate(builder, (current, subscriber) => current.Append($"{Mention.User(subscriber.User)} ")); return builder.ToString(); }