mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 09:01:13 +03:00
Handle audit log entries for message deletion being empty (#317)
In order to determine who deleted a message, Octobot fetches the audit log with a filter on the action "Message Delete", gets the latest entry and uses its author if the timestamps roughly match. However, if the filter returns no entries (as in, no message deletions are present in the audit log), `Single()` will throw an exception with the message `Sequence contains no elements`. To fix this, this PR replaces `Single()` with `SingleOrDefault()` and adds a null-check on `auditLog` in the form of a pattern access Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
2b0c4b62d3
commit
a953053f1d
1 changed files with 3 additions and 3 deletions
|
@ -66,10 +66,10 @@ public sealed class MessageDeletedResponder : IResponder<IMessageDelete>
|
|||
return ResultExtensions.FromError(auditLogResult);
|
||||
}
|
||||
|
||||
var auditLog = auditLogPage.AuditLogEntries.Single();
|
||||
|
||||
var deleterResult = Result<IUser>.FromSuccess(message.Author);
|
||||
if (auditLog.UserID is not null
|
||||
|
||||
var auditLog = auditLogPage.AuditLogEntries.SingleOrDefault();
|
||||
if (auditLog is { UserID: not null }
|
||||
&& auditLog.Options.Value.ChannelID == gatewayEvent.ChannelID
|
||||
&& DateTimeOffset.UtcNow.Subtract(auditLog.ID.Timestamp).TotalSeconds <= 2)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue