Skip to content

Commit

Permalink
Merge pull request #203 from IgKniteDev/develop
Browse files Browse the repository at this point in the history
🔨 [tuning] Better embeds and views, bookmark improvements
  • Loading branch information
hitblast authored Mar 21, 2023
2 parents 66d4c10 + 544aaa4 commit 6ccc634
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
18 changes: 12 additions & 6 deletions cogs/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,19 @@ def __init__(self, bot: core.IgKnite) -> None:

# Listener for the bookmark feature.
@commands.Cog.listener()
async def on_reaction_add(self, reaction: disnake.Reaction, user: disnake.Member) -> None:
async def on_reaction_add(self, reaction: disnake.Reaction, member: disnake.Member) -> None:
if reaction.emoji == '🔖':
embed = disnake.Embed(
color=3158326,
description=reaction.message.content,
).set_author(name=f'{user.name}#{user.discriminator}', icon_url=user.avatar)
await user.send(content=reaction.message.jump_url, embed=embed)
embed = (
core.TypicalEmbed()
.set_title('You\'ve bookmarked a message.')
.set_description(
reaction.message.content + f'\n\nSent by {member} on {member.guild.name}'
)
)
view = core.SmallView().add_button(
label='Original Message', url=reaction.message.jump_url
)
await member.send(embed=embed, view=view)

# Backend for avatar-labelled commands.
# Do not use it within other commands unless really necessary.
Expand Down
21 changes: 12 additions & 9 deletions core/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class TypicalEmbed(disnake.Embed):

def __init__(
self,
inter: disnake.CommandInteraction,
inter: disnake.CommandInteraction | None = None,
*,
disabled_footer: bool = False,
is_error: bool = False
) -> None:
super().__init__(color=(3158326 if not is_error else 16608388))
super().__init__(color=(2764081 if not is_error else 16608388))

if not disabled_footer:
if not disabled_footer and inter:
self.set_footer(
text=random.choice(
[
Expand Down Expand Up @@ -67,7 +67,9 @@ class SmallView(disnake.ui.View):
Can be used for simple views with buttons.
'''

def __init__(self, inter: disnake.CommandInteraction, *, timeout: float = 60) -> None:
def __init__(
self, inter: disnake.CommandInteraction | None = None, *, timeout: float = 60
) -> None:
super().__init__(timeout=timeout)
self.inter = inter

Expand All @@ -76,7 +78,7 @@ def add_button(
*,
label: str,
url: str | None = None,
style=disnake.ButtonStyle.gray,
style: disnake.ButtonStyle = disnake.ButtonStyle.gray,
disabled: bool = False
) -> Self:
'''
Expand All @@ -87,8 +89,9 @@ def add_button(
return self

async def on_timeout(self) -> None:
for children in self.children:
if children.style != disnake.ButtonStyle.link:
children.disabled = True
if self.inter:
for children in self.children:
if children.style != disnake.ButtonStyle.link:
children.disabled = True

await self.inter.edit_original_message(view=self)
await self.inter.edit_original_message(view=self)

0 comments on commit 6ccc634

Please sign in to comment.