1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 09:09:00 +03:00

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 <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2023-10-04 20:21:10 +05:00 committed by GitHub
parent d27168a89f
commit 2ab020a2b4
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 245 additions and 251 deletions

View file

@ -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<Result> SendAboutBotAsync(IUser currentUser, Snowflake guildId, CancellationToken ct = default)
private async Task<Result> 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")

View file

@ -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<Result> 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<Result> 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);

View file

@ -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<Result> ClearMessagesAsync(
int amount, GuildData data, Snowflake channelId, IReadOnlyList<IMessage> messages,
IUser user, IUser currentUser, CancellationToken ct = default)
IUser executor, int amount, GuildData data, Snowflake channelId, IReadOnlyList<IMessage> messages, IUser bot,
CancellationToken ct = default)
{
var idList = new List<Snowflake>(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);

View file

@ -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<Result> 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);

View file

@ -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<Result> 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<Result> 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<Result> 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<Snowflake> { 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<Result> 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<Result> 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<Result> 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<Result> 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;
}

View file

@ -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<Result> 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)

View file

@ -50,34 +50,34 @@ public class RemindCommandGroup : CommandGroup
[UsedImplicitly]
public async Task<Result> 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<Result> ListRemindersAsync(MemberData data, IUser user, IUser currentUser, CancellationToken ct)
private async Task<Result> 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<Result> 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<Result> DeleteReminderAsync(MemberData data, int index, IUser currentUser,
private async Task<Result> 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();

View file

@ -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<Result> SendSettingsListAsync(JsonNode cfg, IUser currentUser, int page,
private async Task<Result> 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<Result> 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<Result> ResetSingleSettingAsync(JsonNode cfg, IUser currentUser,
private async Task<Result> 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<Result> ResetAllSettingsAsync(JsonNode cfg, IUser currentUser,
private async Task<Result> ResetAllSettingsAsync(JsonNode cfg, IUser bot,
CancellationToken ct = default)
{
var failedResults = new List<Result>();
@ -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();

View file

@ -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<Result> 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<Result> 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<Result> SendTimestampAsync(TimeSpan? offset, IUser user, CancellationToken ct)
private async Task<Result> 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();

View file

@ -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;
}
}

View file

@ -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);
}
/// <summary>

View file

@ -60,16 +60,16 @@ public class GuildLoadedResponder : IResponder<IGuildCreate>
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()

View file

@ -67,17 +67,17 @@ public class MessageDeletedResponder : IResponder<IMessageDelete>
var auditLog = auditLogPage.AuditLogEntries.Single();
var userResult = Result<IUser>.FromSuccess(message.Author);
var deleterResult = Result<IUser>.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<IMessageDelete>
Messages.CachedMessageDeleted,
message.Author.GetTag()), message.Author)
.WithDescription(builder.ToString())
.WithActionFooter(user)
.WithActionFooter(deleter)
.WithTimestamp(message.Timestamp)
.WithColour(ColorsList.Red)
.Build();

View file

@ -69,10 +69,10 @@ public sealed class UtilityService : IHostedService
return Result<string?>.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<string?>.FromError(currentUserResult);
return Result<string?>.FromError(botResult);
}
var guildResult = await _guildApi.GetGuildAsync(guildId, ct: ct);
@ -87,7 +87,7 @@ public sealed class UtilityService : IHostedService
return Result<string?>.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<string?>.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<string>.FromError(usersResult);
return Result<string>.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();
}