Catalogger.NET/Catalogger.Backend/Bot/Responders/Guilds/AuditLogResponder.cs

66 lines
2.5 KiB
C#
Raw Normal View History

// Copyright (C) 2021-present sam (starshines.gay)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2024-09-02 17:00:33 +02:00
using Catalogger.Backend.Cache.InMemoryCache;
using Remora.Discord.API.Abstractions.Gateway.Events;
using Remora.Discord.API.Abstractions.Objects;
2024-09-02 17:00:33 +02:00
using Remora.Discord.Gateway.Responders;
using Remora.Results;
namespace Catalogger.Backend.Bot.Responders.Guilds;
2024-10-09 17:35:11 +02:00
public class AuditLogResponder(AuditLogCache auditLogCache, ILogger logger)
: IResponder<IGuildAuditLogEntryCreate>
2024-09-02 17:00:33 +02:00
{
private readonly ILogger _logger = logger.ForContext<AuditLogResponder>();
2024-10-09 17:35:11 +02:00
2024-09-02 17:00:33 +02:00
public Task<Result> RespondAsync(IGuildAuditLogEntryCreate evt, CancellationToken ct = default)
{
if (evt.TargetID == null || evt.UserID == null)
return Task.FromResult(Result.Success);
2024-10-09 17:35:11 +02:00
switch (evt.ActionType)
{
case AuditLogEvent.MemberKick:
auditLogCache.SetKick(evt.GuildID, evt.TargetID, evt.UserID.Value, evt.Reason);
break;
case AuditLogEvent.MemberBanAdd:
auditLogCache.SetBan(evt.GuildID, evt.TargetID, evt.UserID.Value, evt.Reason);
break;
case AuditLogEvent.MemberBanRemove:
auditLogCache.SetUnban(evt.GuildID, evt.TargetID, evt.UserID.Value, evt.Reason);
break;
2024-10-11 21:29:02 +02:00
case AuditLogEvent.MemberRoleUpdate:
case AuditLogEvent.MemberUpdate:
auditLogCache.SetMemberUpdate(
evt.GuildID,
evt.TargetID,
evt.UserID.Value,
evt.Reason
);
break;
default:
_logger.Debug(
2024-10-11 21:29:02 +02:00
"Received audit log event {Id} with type {Type} that we don't care about, ignoring",
evt.ID,
evt.ActionType
);
break;
}
return Task.FromResult(Result.Success);
2024-09-02 17:00:33 +02:00
}
2024-10-09 17:35:11 +02:00
}