Show post URLs in booru commands
This commit is contained in:
parent
f443a3701a
commit
d0412fe3b8
@ -402,11 +402,12 @@ class GelbooruWatcherBaseCog(commands.Cog, abc.ABC, metaclass=GelbooruWatcherMet
|
||||
return f"No results found from {self.cog_name} for the given tags."
|
||||
else:
|
||||
random_result = random.choice(all_results)
|
||||
return (f"{random_result['file_url']}", all_results)
|
||||
post_url = self.post_url_template.format(random_result["id"])
|
||||
return (f"{random_result['file_url']}\n{post_url}", all_results)
|
||||
|
||||
class GelbooruButtons(View):
|
||||
def __init__(self, cog: 'GelbooruWatcherBaseCog', tags: str, all_results: list, hidden: bool = False):
|
||||
super().__init__(timeout=60)
|
||||
super().__init__(timeout=300)
|
||||
self.cog = cog
|
||||
self.tags = tags
|
||||
self.all_results = all_results
|
||||
@ -416,13 +417,15 @@ class GelbooruWatcherBaseCog(commands.Cog, abc.ABC, metaclass=GelbooruWatcherMet
|
||||
@discord.ui.button(label="New Random", style=discord.ButtonStyle.primary)
|
||||
async def new_random(self, interaction: discord.Interaction, button: Button):
|
||||
random_result = random.choice(self.all_results)
|
||||
content = f"{random_result['file_url']}"
|
||||
post_url = self.cog.post_url_template.format(random_result["id"])
|
||||
content = f"{random_result['file_url']}\n{post_url}"
|
||||
await interaction.response.edit_message(content=content, view=self)
|
||||
|
||||
@discord.ui.button(label="Random In New Message", style=discord.ButtonStyle.success)
|
||||
async def new_message(self, interaction: discord.Interaction, button: Button):
|
||||
random_result = random.choice(self.all_results)
|
||||
content = f"{random_result['file_url']}"
|
||||
post_url = self.cog.post_url_template.format(random_result["id"])
|
||||
content = f"{random_result['file_url']}\n{post_url}"
|
||||
await interaction.response.send_message(content, view=self, ephemeral=self.hidden)
|
||||
|
||||
@discord.ui.button(label="Browse Results", style=discord.ButtonStyle.secondary)
|
||||
@ -432,7 +435,11 @@ class GelbooruWatcherBaseCog(commands.Cog, abc.ABC, metaclass=GelbooruWatcherMet
|
||||
return
|
||||
self.current_index = 0
|
||||
result = self.all_results[self.current_index]
|
||||
content = f"Result 1/{len(self.all_results)}:\n{result['file_url']}"
|
||||
post_url = self.cog.post_url_template.format(result["id"])
|
||||
content = (
|
||||
f"Result 1/{len(self.all_results)}:\n"
|
||||
f"{result['file_url']}\n{post_url}"
|
||||
)
|
||||
view = self.cog.BrowseView(self.cog, self.tags, self.all_results, self.hidden, self.current_index)
|
||||
await interaction.response.edit_message(content=content, view=view)
|
||||
|
||||
@ -447,7 +454,7 @@ class GelbooruWatcherBaseCog(commands.Cog, abc.ABC, metaclass=GelbooruWatcherMet
|
||||
|
||||
class BrowseView(View):
|
||||
def __init__(self, cog: 'GelbooruWatcherBaseCog', tags: str, all_results: list, hidden: bool = False, current_index: int = 0):
|
||||
super().__init__(timeout=60)
|
||||
super().__init__(timeout=300)
|
||||
self.cog = cog
|
||||
self.tags = tags
|
||||
self.all_results = all_results
|
||||
@ -456,7 +463,11 @@ class GelbooruWatcherBaseCog(commands.Cog, abc.ABC, metaclass=GelbooruWatcherMet
|
||||
|
||||
async def _update_message(self, interaction: discord.Interaction):
|
||||
result = self.all_results[self.current_index]
|
||||
content = f"Result {self.current_index + 1}/{len(self.all_results)}:\n{result['file_url']}"
|
||||
post_url = self.cog.post_url_template.format(result["id"])
|
||||
content = (
|
||||
f"Result {self.current_index + 1}/{len(self.all_results)}:\n"
|
||||
f"{result['file_url']}\n{post_url}"
|
||||
)
|
||||
await interaction.response.edit_message(content=content, view=self)
|
||||
|
||||
@discord.ui.button(label="First", style=discord.ButtonStyle.secondary, emoji="⏪")
|
||||
@ -488,8 +499,14 @@ class GelbooruWatcherBaseCog(commands.Cog, abc.ABC, metaclass=GelbooruWatcherMet
|
||||
self.current_index = modal.value - 1
|
||||
# Edit the original message from the modal's followup context
|
||||
result = self.all_results[self.current_index]
|
||||
content = f"Result {modal.value}/{len(self.all_results)}:\n{result['file_url']}"
|
||||
await interaction.followup.edit_message(interaction.message.id, content=content, view=self)
|
||||
post_url = self.cog.post_url_template.format(result["id"])
|
||||
content = (
|
||||
f"Result {modal.value}/{len(self.all_results)}:\n"
|
||||
f"{result['file_url']}\n{post_url}"
|
||||
)
|
||||
await interaction.followup.edit_message(
|
||||
interaction.message.id, content=content, view=self
|
||||
)
|
||||
|
||||
|
||||
@discord.ui.button(label="Back to Main Controls", style=discord.ButtonStyle.danger, row=1)
|
||||
@ -499,8 +516,11 @@ class GelbooruWatcherBaseCog(commands.Cog, abc.ABC, metaclass=GelbooruWatcherMet
|
||||
await interaction.response.edit_message(content="No results available.", view=None)
|
||||
return
|
||||
random_result = random.choice(self.all_results)
|
||||
content = f"{random_result['file_url']}"
|
||||
view = self.cog.GelbooruButtons(self.cog, self.tags, self.all_results, self.hidden)
|
||||
post_url = self.cog.post_url_template.format(random_result["id"])
|
||||
content = f"{random_result['file_url']}\n{post_url}"
|
||||
view = self.cog.GelbooruButtons(
|
||||
self.cog, self.tags, self.all_results, self.hidden
|
||||
)
|
||||
await interaction.response.edit_message(content=content, view=view)
|
||||
|
||||
class GoToModal(discord.ui.Modal):
|
||||
@ -614,7 +634,11 @@ class GelbooruWatcherBaseCog(commands.Cog, abc.ABC, metaclass=GelbooruWatcherMet
|
||||
return
|
||||
|
||||
result = all_results[0]
|
||||
content = f"Result 1/{len(all_results)}:\n{result['file_url']}"
|
||||
post_url = self.post_url_template.format(result["id"])
|
||||
content = (
|
||||
f"Result 1/{len(all_results)}:\n"
|
||||
f"{result['file_url']}\n{post_url}"
|
||||
)
|
||||
view = self.BrowseView(self, tags, all_results, hidden, current_index=0)
|
||||
if interaction.response.is_done(): await interaction.followup.send(content, view=view, ephemeral=hidden)
|
||||
else: await interaction.response.send_message(content, view=view, ephemeral=hidden)
|
||||
|
Loading…
x
Reference in New Issue
Block a user