Skip to content

Commit

Permalink
[AFK] fix views
Browse files Browse the repository at this point in the history
  • Loading branch information
japandotorg committed Oct 20, 2023
1 parent dcd4ab6 commit 159fa2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion afk/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ async def on_message(self, message: discord.Message):
time_difference = datetime.now().timestamp() - afk_time
if time_difference > 10:
ctx = await self.bot.get_context(message)
_view = AFKView(ctx, data)
_view = AFKView(ctx, self, data)
_view._message = await message.channel.send(
embed=discord.Embed(
title="Your AFK has been removed!",
Expand Down
12 changes: 9 additions & 3 deletions afk/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@
SOFTWARE.
"""

from typing import Any, Dict, List, Optional, Union
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union

import discord
from redbot.core import commands
from redbot.core.bot import Red

if TYPE_CHECKING:
from .core import AFK


def disable_items(self: discord.ui.View):
for child in self.children:
Expand All @@ -48,9 +51,12 @@ async def callback(self, _: discord.Interaction[Red], /) -> None:


class AFKView(discord.ui.View):
def __init__(self, ctx: commands.Context, data: Dict, timeout: float = 60.0) -> None:
def __init__(
self, ctx: commands.Context, cog: "AFK", data: Dict, timeout: float = 60.0
) -> None:
super().__init__(timeout=timeout)
self.ctx: commands.Context = ctx
self.cog: "AFK" = cog
self.data: Dict = data
self._message: Optional[discord.Message] = None
self.add_item(CloseButton())
Expand Down Expand Up @@ -78,7 +84,7 @@ async def _callback(self, interaction: discord.Interaction[Red], _: discord.ui.B
ephemeral=True,
)
else:
await self.ctx.cog._ping_list(interaction, self.data)
await self.cog._ping_list(interaction, self.data)


class ViewDisableOnTimeout(discord.ui.View):
Expand Down

0 comments on commit 159fa2c

Please sign in to comment.