mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 09:09:00 +03:00
General fixes (#54)
Depends on #55 These changes are really small and I don't know how to reasonably split them into multiple PRs, but here's the changelog: - The result of the `UtilityService#LogActionAsync` call in `BanCommandGroup#BanUserAsync` is no longer ignored and it's errors will now prevent feedback from being sent; - Converted `if` statement to a `return` with ternary in `LanguageOption`; - Slightly decreased method complexity of `MessageDeletedResponder#RespondAsync` by cleverly using Results; - Changed the order of parameters for `UtilityService#LogActionAsync` to flow better; - Removed the exemption for `ConvertIfToReturnStatement` for InspectCode. --------- Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
685688bbe8
commit
daa1dd4184
5 changed files with 19 additions and 20 deletions
2
.github/workflows/resharper.yml
vendored
2
.github/workflows/resharper.yml
vendored
|
@ -31,5 +31,5 @@ jobs:
|
||||||
uses: muno92/resharper_inspectcode@1.7.1
|
uses: muno92/resharper_inspectcode@1.7.1
|
||||||
with:
|
with:
|
||||||
solutionPath: ./Boyfriend.sln
|
solutionPath: ./Boyfriend.sln
|
||||||
ignoreIssueType: InvertIf, ConvertIfStatementToReturnStatement, ConvertIfStatementToSwitchStatement
|
ignoreIssueType: InvertIf, ConvertIfStatementToSwitchStatement
|
||||||
solutionWideAnalysis: true
|
solutionWideAnalysis: true
|
||||||
|
|
|
@ -152,7 +152,9 @@ public class BanCommandGroup : CommandGroup {
|
||||||
title, target)
|
title, target)
|
||||||
.WithColour(ColorsList.Green).Build();
|
.WithColour(ColorsList.Green).Build();
|
||||||
|
|
||||||
_utility.LogActionAsync(cfg, channelId, title, target, description, user, CancellationToken);
|
var logResult = _utility.LogActionAsync(cfg, channelId, user, title, description, target, CancellationToken);
|
||||||
|
if (!logResult.IsSuccess)
|
||||||
|
return Result.FromError(logResult.Error);
|
||||||
|
|
||||||
return await _feedbackService.SendContextualEmbedResultAsync(embed, CancellationToken);
|
return await _feedbackService.SendContextualEmbedResultAsync(embed, CancellationToken);
|
||||||
}
|
}
|
||||||
|
@ -222,7 +224,7 @@ public class BanCommandGroup : CommandGroup {
|
||||||
|
|
||||||
var title = string.Format(Messages.UserUnbanned, target.GetTag());
|
var title = string.Format(Messages.UserUnbanned, target.GetTag());
|
||||||
var description = string.Format(Messages.DescriptionActionReason, reason);
|
var description = string.Format(Messages.DescriptionActionReason, reason);
|
||||||
var logResult = _utility.LogActionAsync(cfg, channelId, title, target, description, user, CancellationToken);
|
var logResult = _utility.LogActionAsync(cfg, channelId, user, title, description, target, CancellationToken);
|
||||||
if (!logResult.IsSuccess)
|
if (!logResult.IsSuccess)
|
||||||
return Result.FromError(logResult.Error);
|
return Result.FromError(logResult.Error);
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,8 @@ public class LanguageOption : Option<CultureInfo> {
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override Result Set(JsonNode settings, string from) {
|
public override Result Set(JsonNode settings, string from) {
|
||||||
if (!CultureInfoCache.ContainsKey(from.ToLowerInvariant()))
|
return CultureInfoCache.ContainsKey(from.ToLowerInvariant())
|
||||||
return Result.FromError(new ArgumentInvalidError(nameof(from), Messages.LanguageNotSupported));
|
? base.Set(settings, from.ToLowerInvariant())
|
||||||
|
: Result.FromError(new ArgumentInvalidError(nameof(from), Messages.LanguageNotSupported));
|
||||||
return base.Set(settings, from.ToLowerInvariant());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,15 +46,13 @@ public class MessageDeletedResponder : IResponder<IMessageDelete> {
|
||||||
if (!auditLogResult.IsDefined(out var auditLogPage)) return Result.FromError(auditLogResult);
|
if (!auditLogResult.IsDefined(out var auditLogPage)) return Result.FromError(auditLogResult);
|
||||||
|
|
||||||
var auditLog = auditLogPage.AuditLogEntries.Single();
|
var auditLog = auditLogPage.AuditLogEntries.Single();
|
||||||
if (!auditLog.Options.IsDefined(out var options))
|
|
||||||
return Result.FromError(new ArgumentNullError(nameof(auditLog.Options)));
|
|
||||||
|
|
||||||
var user = message.Author;
|
var userResult = Result<IUser>.FromSuccess(message.Author);
|
||||||
if (options.ChannelID == gatewayEvent.ChannelID
|
if (auditLog.Options.Value.ChannelID == gatewayEvent.ChannelID
|
||||||
&& DateTimeOffset.UtcNow.Subtract(auditLog.ID.Timestamp).TotalSeconds <= 2) {
|
&& DateTimeOffset.UtcNow.Subtract(auditLog.ID.Timestamp).TotalSeconds <= 2)
|
||||||
var userResult = await _userApi.GetUserAsync(auditLog.UserID!.Value, ct);
|
userResult = await _userApi.GetUserAsync(auditLog.UserID!.Value, ct);
|
||||||
if (!userResult.IsDefined(out user)) return Result.FromError(userResult);
|
|
||||||
}
|
if (!userResult.IsDefined(out var user)) return Result.FromError(userResult);
|
||||||
|
|
||||||
Messages.Culture = GuildSettings.Language.Get(cfg);
|
Messages.Culture = GuildSettings.Language.Get(cfg);
|
||||||
|
|
||||||
|
|
|
@ -154,15 +154,15 @@ public class UtilityService : IHostedService {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="cfg">The guild configuration.</param>
|
/// <param name="cfg">The guild configuration.</param>
|
||||||
/// <param name="channelId">The ID of the channel where the action was executed.</param>
|
/// <param name="channelId">The ID of the channel where the action was executed.</param>
|
||||||
/// <param name="title">The title for the embed.</param>
|
|
||||||
/// <param name="avatar">The user whose avatar will be displayed next to the <paramref name="title" /> of the embed.</param>
|
|
||||||
/// <param name="description">The description of the embed.</param>
|
|
||||||
/// <param name="user">The user who performed the action.</param>
|
/// <param name="user">The user who performed the action.</param>
|
||||||
|
/// <param name="title">The title for the embed.</param>
|
||||||
|
/// <param name="description">The description of the embed.</param>
|
||||||
|
/// <param name="avatar">The user whose avatar will be displayed next to the <paramref name="title" /> of the embed.</param>
|
||||||
/// <param name="ct">The cancellation token for this operation.</param>
|
/// <param name="ct">The cancellation token for this operation.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Result LogActionAsync(
|
public Result LogActionAsync(
|
||||||
JsonNode cfg, Snowflake channelId, string title, IUser avatar, string description,
|
JsonNode cfg, Snowflake channelId, IUser user, string title, string description, IUser avatar,
|
||||||
IUser user, CancellationToken ct = default) {
|
CancellationToken ct = default) {
|
||||||
var publicChannel = GuildSettings.PublicFeedbackChannel.Get(cfg);
|
var publicChannel = GuildSettings.PublicFeedbackChannel.Get(cfg);
|
||||||
var privateChannel = GuildSettings.PrivateFeedbackChannel.Get(cfg);
|
var privateChannel = GuildSettings.PrivateFeedbackChannel.Get(cfg);
|
||||||
if (GuildSettings.PublicFeedbackChannel.Get(cfg).EmptyOrEqualTo(channelId)
|
if (GuildSettings.PublicFeedbackChannel.Get(cfg).EmptyOrEqualTo(channelId)
|
||||||
|
|
Loading…
Reference in a new issue