Skip to content

Commit

Permalink
refactor: Button generic type is CrenataView
Browse files Browse the repository at this point in the history
  • Loading branch information
SaidBySolo authored Jan 8, 2024
1 parent ac7f76a commit aa6acb7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
6 changes: 2 additions & 4 deletions crenata/application/view/confirm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Any

from discord import ButtonStyle, Interaction
from discord.ui import Button, button

Expand All @@ -12,14 +10,14 @@ class Confirm(CrenataView):
"""

@button(label="확인", style=ButtonStyle.green, emoji="✅")
async def confirm(self, interaction: Interaction, _: Button[Any]) -> None:
async def confirm(self, interaction: Interaction, _: Button[CrenataView]) -> None:
self.is_confirm = True

await interaction.response.defer()
self.stop()

@button(label="취소", style=ButtonStyle.red, emoji="✖️")
async def cancel(self, interaction: Interaction, _: Button[Any]) -> None:
async def cancel(self, interaction: Interaction, _: Button[CrenataView]) -> None:
self.is_confirm = False

await interaction.response.defer()
Expand Down
9 changes: 4 additions & 5 deletions crenata/application/view/paginator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from functools import cached_property
from typing import Any, Optional
from typing import Optional

from discord import ButtonStyle, Interaction
from discord.ui import Button, button
Expand Down Expand Up @@ -33,7 +33,7 @@ def total(self) -> int:
return len(self.embeds)

@button(label="이전", style=ButtonStyle.primary, emoji="◀")
async def prev(self, interaction: Interaction, _: Button[Any]) -> None:
async def prev(self, interaction: Interaction, _: Button[CrenataView]) -> None:
self.index -= 1

if self.index < 0:
Expand All @@ -42,7 +42,7 @@ async def prev(self, interaction: Interaction, _: Button[Any]) -> None:
await interaction.response.edit_message(embed=self.embeds[self.index])

@button(label="다음", style=ButtonStyle.primary, emoji="▶️")
async def next(self, interaction: Interaction, _: Button[Any]) -> None:
async def next(self, interaction: Interaction, _: Button[CrenataView]) -> None:
self.index += 1

if self.index >= self.total:
Expand All @@ -51,5 +51,4 @@ async def next(self, interaction: Interaction, _: Button[Any]) -> None:
await interaction.response.edit_message(embed=self.embeds[self.index])


class SelectablePaginator(Paginator, Selector):
...
class SelectablePaginator(Paginator, Selector): ...
6 changes: 2 additions & 4 deletions crenata/application/view/selector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Any

from discord import ButtonStyle, Interaction
from discord.ui import Button, button

Expand All @@ -8,13 +6,13 @@

class Selector(CrenataView):
@button(label="확인", style=ButtonStyle.success, emoji="✅")
async def confirm(self, interaction: Interaction, _: Button[Any]) -> None:
async def confirm(self, interaction: Interaction, _: Button[CrenataView]) -> None:
self.is_confirm = True
await interaction.response.defer()
self.stop()

@button(label="닫기", style=ButtonStyle.danger, emoji="✖️")
async def close(self, interaction: Interaction, _: Button[Any]) -> None:
async def close(self, interaction: Interaction, _: Button[CrenataView]) -> None:
self.is_confirm = False
await interaction.response.defer()
self.stop()

0 comments on commit aa6acb7

Please sign in to comment.