Skip to content

Commit

Permalink
add new moderation event types and correct present buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
AbstractUmbra committed Oct 6, 2024
1 parent 3dd9195 commit 2cf8f90
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
4 changes: 4 additions & 0 deletions core/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ class DiscordPyModerationEvent(Enum):
mute = 3
unban = 4
helpblock = 5
generalblock = 6
unmute = 7
ungeneralblock = 8
unhelpblock = 9
27 changes: 21 additions & 6 deletions modules/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
3: "muted",
4: "unbanned",
5: "helpblocked",
6: "generalblocked",
7: "unmuted",
8: "un-generalblocked",
9: "un-helpblocked",
}


Expand All @@ -77,18 +81,24 @@ class GithubError(commands.CommandError):
class ModerationRespostView(discord.ui.View):
message: discord.Message | discord.WebhookMessage

def __init__(self, *, timeout: float | None = 180, target_id: int, target_reason: str) -> None:
def __init__(
self, *, timeout: float | None = 180, event_type: core.DiscordPyModerationEvent, target_id: int, target_reason: str
) -> None:
super().__init__(timeout=timeout)
self.event_type: core.DiscordPyModerationEvent = event_type
self.target: discord.Object = discord.Object(id=target_id, type=discord.Member)
self.target_reason: str = target_reason

def _disable_all_buttons(self) -> None:
if self.event_type.value in (4, 7, 8, 9):
self._disable_all_components()

def _disable_all_components(self) -> None:
for item in self.children:
if isinstance(item, (discord.ui.Button, discord.ui.Select)):
item.disabled = True

async def on_timeout(self) -> None:
self._disable_all_buttons()
self._disable_all_components()
await self.message.edit(view=self)

@discord.ui.button(label="Ban", emoji="\U0001f528")
Expand All @@ -103,7 +113,7 @@ async def ban_button(self, interaction: Interaction, button: discord.ui.Button[S
)
await interaction.followup.send("Banned.")

self._disable_all_buttons()
self._disable_all_components()
await self.message.edit(view=self)

@discord.ui.button(label="Kick", emoji="\U0001f462")
Expand All @@ -118,7 +128,7 @@ async def kick_button(self, interaction: Interaction, button: discord.ui.Button[
)
await interaction.followup.send("Kicked.")

self._disable_all_buttons()
self._disable_all_components()
await self.message.edit(view=self)


Expand Down Expand Up @@ -310,7 +320,12 @@ async def on_papi_dpy_modlog(self, payload: ModLogPayload, /) -> None:
channel = guild.get_channel(Channels.DPY_MOD_LOGS)
assert isinstance(channel, discord.TextChannel) # This is static

view = ModerationRespostView(timeout=60 * 60, target_id=target_id, target_reason=moderation_reason)
view = ModerationRespostView(
timeout=60 * 60,
event_type=moderation_event,
target_id=target_id,
target_reason=moderation_reason,
)
view.message = await channel.send(embed=embed, view=view)


Expand Down

0 comments on commit 2cf8f90

Please sign in to comment.