Skip to content

Commit f471891

Browse files
add new moderation event types and correct present buttons (#68)
1 parent 3dd9195 commit f471891

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

core/enums.py

+4
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ class DiscordPyModerationEvent(Enum):
99
mute = 3
1010
unban = 4
1111
helpblock = 5
12+
generalblock = 6
13+
unmute = 7
14+
ungeneralblock = 8
15+
unhelpblock = 9

modules/moderation.py

+21-6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
3: "muted",
5858
4: "unbanned",
5959
5: "helpblocked",
60+
6: "generalblocked",
61+
7: "unmuted",
62+
8: "un-generalblocked",
63+
9: "un-helpblocked",
6064
}
6165

6266

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

80-
def __init__(self, *, timeout: float | None = 180, target_id: int, target_reason: str) -> None:
84+
def __init__(
85+
self, *, timeout: float | None = 180, event_type: core.DiscordPyModerationEvent, target_id: int, target_reason: str
86+
) -> None:
8187
super().__init__(timeout=timeout)
88+
self.event_type: core.DiscordPyModerationEvent = event_type
8289
self.target: discord.Object = discord.Object(id=target_id, type=discord.Member)
8390
self.target_reason: str = target_reason
8491

85-
def _disable_all_buttons(self) -> None:
92+
if self.event_type.value in (4, 7, 8, 9):
93+
self._disable_all_components()
94+
95+
def _disable_all_components(self) -> None:
8696
for item in self.children:
8797
if isinstance(item, (discord.ui.Button, discord.ui.Select)):
8898
item.disabled = True
8999

90100
async def on_timeout(self) -> None:
91-
self._disable_all_buttons()
101+
self._disable_all_components()
92102
await self.message.edit(view=self)
93103

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

106-
self._disable_all_buttons()
116+
self._disable_all_components()
107117
await self.message.edit(view=self)
108118

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

121-
self._disable_all_buttons()
131+
self._disable_all_components()
122132
await self.message.edit(view=self)
123133

124134

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

313-
view = ModerationRespostView(timeout=60 * 60, target_id=target_id, target_reason=moderation_reason)
323+
view = ModerationRespostView(
324+
timeout=60 * 60,
325+
event_type=moderation_event,
326+
target_id=target_id,
327+
target_reason=moderation_reason,
328+
)
314329
view.message = await channel.send(embed=embed, view=view)
315330

316331

0 commit comments

Comments
 (0)