Ruby-Cogs/dankutils/views.py
2025-04-02 22:56:57 -04:00

61 lines
2.5 KiB
Python

"""
MIT License
Copyright (c) 2021-present Kuro-Rui
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
import discord
from redbot.core.commands import Context
class DoxxView(discord.ui.View):
def __init__(self, *, info_embed: discord.Embed):
super().__init__(timeout=60.0)
self.info_embed = info_embed
@discord.ui.button(label="Send Details", style=discord.ButtonStyle.blurple)
async def send_button(self, interaction: discord.Interaction, button: discord.ui.Button):
button.style = discord.ButtonStyle.gray
button.disabled = True
await self.message.edit(view=self)
await interaction.response.send_message(embed=self.info_embed, ephemeral=True)
async def start(self, ctx: Context, content: str = None, **kwargs):
self.author = ctx.author
self.ctx = ctx
kwargs["reference"] = ctx.message.to_reference(fail_if_not_exists=False)
kwargs["mention_author"] = False
kwargs["view"] = self
self.message = await ctx.send(content, **kwargs)
async def interaction_check(self, interaction: discord.Interaction) -> bool:
if interaction.user != self.author:
await interaction.response.send_message(
"You are not authorized to interact with this menu.", ephemeral=True
)
return False
return True
async def on_timeout(self):
for child in self.children:
child.style = discord.ButtonStyle.gray
child.disabled = True
await self.message.edit(view=self)