Skip to content

Commit

Permalink
Update package versions and refactor audit logic
Browse files Browse the repository at this point in the history
Updated "Remora.Discord" package version to 2023.3.0 to acquire new features and fixes. Replaced "ClientStatus" to "UserStatus" enumeration to align with revised library definitions in ReadyResponder.cs. Refactored getting audit logs in MemberUpdateResponder.cs to use the updated method call and simplified the condition to get the most recent timeout event. These updates improve compatibility with the newer version of the library and streamline the audit log process for better performance.
  • Loading branch information
patrickklaeren committed Jul 7, 2023
1 parent 3da96d8 commit 51aa03f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Accord.Bot/Accord.Bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="LazyCache" Version="2.4.0" />
<PackageReference Include="MediatR" Version="11.1.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
<PackageReference Include="Remora.Discord" Version="2022.52.0" />
<PackageReference Include="Remora.Discord" Version="2023.3.0" />
<PackageReference Include="Serilog" Version="2.12.1-dev-01587" />
<PackageReference Include="TimeSpanParserUtil" Version="1.2.0" />
</ItemGroup>
Expand Down
14 changes: 6 additions & 8 deletions src/Accord.Bot/Responders/MemberUpdateResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ private async Task HandleTimeOut(IGuildMemberUpdate gatewayEvent, IUser user, Da
if (!timeoutHasChanged)
return;

var logRequest = await _auditLogApi.GetAuditLogAsync(gatewayEvent.GuildID,
actionType: AuditLogEvent.MemberUpdate, ct: cancellationToken);
var logRequest = await _auditLogApi.GetGuildAuditLogAsync(gatewayEvent.GuildID, actionType: AuditLogEvent.MemberUpdate, ct: cancellationToken);

var durationMessage = "has been timed out";
var actor = "a moderator";
Expand All @@ -120,16 +119,15 @@ private async Task HandleTimeOut(IGuildMemberUpdate gatewayEvent, IUser user, Da
.Where(x => x.TargetID == rawUserId)
.Where(x => x.UserID != null)
.Where(x => x.Changes.HasValue && x.Changes.Value.Any(a => a.Key == "communication_disabled_until"))
.OrderByDescending(x => x.ID)
.FirstOrDefault();
.MaxBy(x => x.ID);

if (probableAudit is { } audit)
if (probableAudit != null)
{
var timedOutFrom = audit.ID.Timestamp;
var timedOutFrom = probableAudit.ID.Timestamp;
var durationOfTimeout = timedOutUntil - timedOutFrom;
durationMessage = $"has been timed out for {durationOfTimeout.Humanize()}";
actor = $"{DiscordFormatter.UserIdToMention(audit.UserID!.Value.Value)}";
reason = audit.Reason.HasValue ? audit.Reason.Value : "an unknown reason";
actor = $"{DiscordFormatter.UserIdToMention(probableAudit.UserID!.Value.Value)}";
reason = probableAudit.Reason.HasValue ? probableAudit.Reason.Value : "an unknown reason";
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Accord.Bot/Responders/ReadyResponder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public partial class ReadyResponder : IResponder<IReady>
_discordCache.SetSelfSnowflake(gatewayEvent.User.ID);
await CacheGuild(gatewayEvent.User, ct);

var updateCommand = new UpdatePresence(ClientStatus.Online, false, null, new IActivity[]
var updateCommand = new UpdatePresence(UserStatus.Online, false, null, new IActivity[]
{
new Activity("for everything", ActivityType.Watching)
});
Expand Down

0 comments on commit 51aa03f

Please sign in to comment.