Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Implement support for the guild_audit_log_entry_create event #1224

Merged
merged 10 commits into from
Jan 21, 2023
1 change: 1 addition & 0 deletions interactions/api/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"Connect",
"Disconnect",
"Error",
"GuildAuditLogEntryCreate",
"GuildAvailable",
"GuildEmojisUpdate",
"GuildEvent",
Expand Down
9 changes: 9 additions & 0 deletions interactions/api/events/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def on_guild_join(event):
"ChannelDelete",
"ChannelPinsUpdate",
"ChannelUpdate",
"GuildAuditLogEntryCreate",
"GuildEmojisUpdate",
"GuildJoin",
"GuildLeft",
Expand Down Expand Up @@ -752,3 +753,11 @@ class VoiceUserLeave(BaseVoiceEvent):
repr=False,
)
"""The voice channel the user left"""


@attrs.define(eq=False, order=False, hash=False, kw_only=False)
class GuildAuditLogEntryCreate(GuildEvent):
"""Dispatched when audit log entry is created"""

audit_log_entry: interactions.models.AuditLogEntry = attrs.field(repr=False)
"""The audit log entry object"""
11 changes: 10 additions & 1 deletion interactions/api/events/processors/guild_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from interactions.api.events.discord import (
BanCreate,
BanRemove,
GuildAuditLogEntryCreate,
GuildEmojisUpdate,
GuildStickersUpdate,
IntegrationCreate,
Expand All @@ -13,7 +14,7 @@
WebhooksUpdate,
)
from interactions.client.const import MISSING
from interactions.models import GuildIntegration, Sticker, to_snowflake
from interactions.models import AuditLogEntry, GuildIntegration, Sticker, to_snowflake

from ._template import EventMixinTemplate, Processor

Expand Down Expand Up @@ -140,3 +141,11 @@ async def _on_raw_guild_stickers_update(self, event: "RawGatewayEvent") -> None:
@Processor.define()
async def _on_raw_webhook_update(self, event: "RawGatewayEvent") -> None:
self.dispatch(WebhooksUpdate(event.data.get("guild_id"), event.data.get("channel_id")))

@Processor.define()
async def _on_raw_guild_audit_log_entry_create(self, event: "RawGatewayEvent") -> None:
self.dispatch(
GuildAuditLogEntryCreate(
event.data.get("guild_id"), AuditLogEntry.from_dict(event.data, self)
)
)
9 changes: 5 additions & 4 deletions interactions/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,14 @@
events.MemberAdd: [Intents.GUILD_MEMBERS],
events.MemberRemove: [Intents.GUILD_MEMBERS],
events.MemberUpdate: [Intents.GUILD_MEMBERS],
# Intents.GUILD_BANS
events.BanCreate: [Intents.GUILD_BANS],
events.BanRemove: [Intents.GUILD_BANS],
# Intents.GUILD_MODERATION
events.BanCreate: [Intents.GUILD_MODERATION],
events.BanRemove: [Intents.GUILD_MODERATION],
events.GuildAuditLogEntryCreate: [Intents.GUILD_MODERATION],
# Intents.GUILD_EMOJIS_AND_STICKERS
events.GuildEmojisUpdate: [Intents.GUILD_EMOJIS_AND_STICKERS],
events.GuildStickersUpdate: [Intents.GUILD_EMOJIS_AND_STICKERS],
# Intents.GUILD_BANS
# Intents.GUILD_INTEGRATIONS
events.IntegrationCreate: [Intents.GUILD_INTEGRATIONS],
events.IntegrationDelete: [Intents.GUILD_INTEGRATIONS],
events.IntegrationUpdate: [Intents.GUILD_INTEGRATIONS],
Expand Down
4 changes: 2 additions & 2 deletions interactions/models/discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class Intents(DiscordIntFlag): # type: ignore

GUILDS = 1 << 0
GUILD_MEMBERS = 1 << 1
GUILD_BANS = 1 << 2
GUILD_MODERATION = 1 << 2
GUILD_EMOJIS_AND_STICKERS = 1 << 3
GUILD_INTEGRATIONS = 1 << 4
GUILD_WEBHOOKS = 1 << 5
Expand Down Expand Up @@ -219,7 +219,7 @@ def new(
cls,
guilds=False,
guild_members=False,
guild_bans=False,
guild_moderation=False,
guild_emojis_and_stickers=False,
guild_integrations=False,
guild_webhooks=False,
Expand Down