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

Add new moderation event types and correct present buttons #68

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading