-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Units] Return list of WikiArticle results for search_wiki function
[Discord] Add and use utilities.views and WikiArticlesView to show and allow selection of multiple article results for commands that search wikis
- Loading branch information
Showing
4 changed files
with
278 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
|
||
import discord | ||
|
||
|
||
class WikiArticlesView(discord.ui.View): | ||
|
||
def __init__(self, articles): | ||
super().__init__(timeout = None) | ||
# TODO: Timeout? | ||
|
||
self.articles = articles | ||
|
||
for number, article in enumerate(articles): | ||
self.article.add_option(label = article.title, value = number) | ||
|
||
self.article.options[0].default = True | ||
|
||
def initial_embed(self, ctx): | ||
article = self.articles[0] | ||
return discord.Embed( | ||
color = ctx.bot.bot_color, | ||
title = article.title, | ||
url = article.url, | ||
description = article.extract | ||
).set_image( | ||
url = article.image_url | ||
).set_footer( | ||
icon_url = article.wiki.logo, | ||
text = article.wiki.name | ||
) | ||
|
||
@discord.ui.select() | ||
async def article(self, interaction, select): | ||
for option in select.options: | ||
option.default = False | ||
|
||
selected = int(select.values[0]) | ||
article = self.articles[selected] | ||
|
||
embed = discord.Embed( | ||
color = interaction.client.bot_color, | ||
title = article.title, | ||
url = article.url, | ||
description = article.extract | ||
).set_image( | ||
url = article.image_url | ||
).set_footer( | ||
icon_url = article.wiki.logo, | ||
text = article.wiki.name | ||
) | ||
|
||
select.options[selected].default = True | ||
|
||
await interaction.response.edit_message(embed = embed, view = self) | ||
|
||
async def stop(self): | ||
self.article.disabled = True | ||
|
||
await self.message.edit(view = self) | ||
|
||
super().stop() | ||
|
Oops, something went wrong.