-
-
Notifications
You must be signed in to change notification settings - Fork 43
feat(wiki): Add subcommand to search wikipedia #975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Reviewer's GuideThis PR extends the existing wiki cog by integrating a new Wikipedia subcommand: it registers the Wikipedia API URL, updates URL routing logic to support Wikipedia articles, and adds the Sequence diagram for the new Wikipedia subcommand flowsequenceDiagram
actor User
participant Bot
participant WikiCog
User->>Bot: !wiki wikipedia <query>
Bot->>WikiCog: wikipedia(ctx, query)
WikiCog->>WikiCog: query_wiki(wikipedia_api_url, query)
WikiCog->>WikiCog: create_embed(title, ctx)
WikiCog->>Bot: send(embed)
Bot->>User: Display Wikipedia result embed
Class diagram for updated Wiki cog with Wikipedia supportclassDiagram
class Wiki {
- bot: Tux
- arch_wiki_api_url: str
- atl_wiki_api_url: str
- wikipedia_api_url: str
+ __init__(bot: Tux)
+ create_embed(title: tuple[str, str], ctx: commands.Context[Tux]) : discord.Embed
+ query_wiki(base_url: str, search_term: str) : tuple[str, str]
+ arch_wiki(ctx: commands.Context[Tux], query: str)
+ atl_wiki(ctx: commands.Context[Tux], query: str)
+ wikipedia(ctx: commands.Context[Tux], query: str) <<added>>
}
Wiki : +wikipedia_api_url <<added>>
Wiki : +wikipedia(ctx, query) <<added>>
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @Atmois - I've reviewed your changes - here's some feedback:
- The URL construction in query_wiki relies on string matching; consider using the API’s fullurl field for Wikipedia (and other wikis) to generate more reliable links.
- The new wikipedia subcommand logic is almost identical to the existing ones—refactor into a generic helper that takes the wiki identifier and API URL to avoid code duplication.
- There’s no handling for cases where the search returns no results; adding a user-friendly message or fallback in query_wiki/create_embed would improve the UX.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The URL construction in query_wiki relies on string matching; consider using the API’s fullurl field for Wikipedia (and other wikis) to generate more reliable links.
- The new wikipedia subcommand logic is almost identical to the existing ones—refactor into a generic helper that takes the wiki identifier and API URL to avoid code duplication.
- There’s no handling for cases where the search returns no results; adding a user-friendly message or fallback in query_wiki/create_embed would improve the UX.
## Individual Comments
### Comment 1
<location> `tux/cogs/utility/wiki.py:166` </location>
<code_context>
+ name="wikipedia",
+ aliases=["wp"],
+ )
+ async def wikipedia(self, ctx: commands.Context[Tux], *, query: str) -> None:
+ """
+ Search Wikipedia
+
+ Parameters
+ ----------
+ ctx : commands.Context[Tux]
+ The context object for the command.
+ query : str
+ The search query.
+ """
+
+ title: tuple[str, str] = self.query_wiki(self.wikipedia_api_url, query)
+
+ embed = self.create_embed(title, ctx)
+
+ await ctx.send(embed=embed)
+
</code_context>
<issue_to_address>
No error handling for failed or empty Wikipedia queries.
Add error handling to manage cases where no Wikipedia article is found or the query fails, to prevent incomplete or misleading embeds.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
async def wikipedia(self, ctx: commands.Context[Tux], *, query: str) -> None:
"""
Search Wikipedia
Parameters
----------
ctx : commands.Context[Tux]
The context object for the command.
query : str
The search query.
"""
title: tuple[str, str] = self.query_wiki(self.wikipedia_api_url, query)
embed = self.create_embed(title, ctx)
await ctx.send(embed=embed)
=======
async def wikipedia(self, ctx: commands.Context[Tux], *, query: str) -> None:
"""
Search Wikipedia
Parameters
----------
ctx : commands.Context[Tux]
The context object for the command.
query : str
The search query.
"""
title: tuple[str, str] | None = self.query_wiki(self.wikipedia_api_url, query)
if not title:
await ctx.send("❌ No Wikipedia article found for your query, or the request failed.")
return
embed = self.create_embed(title, ctx)
await ctx.send(embed=embed)
>>>>>>> REPLACE
</suggested_fix>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
async def wikipedia(self, ctx: commands.Context[Tux], *, query: str) -> None: | ||
""" | ||
Search Wikipedia | ||
|
||
Parameters | ||
---------- | ||
ctx : commands.Context[Tux] | ||
The context object for the command. | ||
query : str | ||
The search query. | ||
""" | ||
|
||
title: tuple[str, str] = self.query_wiki(self.wikipedia_api_url, query) | ||
|
||
embed = self.create_embed(title, ctx) | ||
|
||
await ctx.send(embed=embed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: No error handling for failed or empty Wikipedia queries.
Add error handling to manage cases where no Wikipedia article is found or the query fails, to prevent incomplete or misleading embeds.
async def wikipedia(self, ctx: commands.Context[Tux], *, query: str) -> None: | |
""" | |
Search Wikipedia | |
Parameters | |
---------- | |
ctx : commands.Context[Tux] | |
The context object for the command. | |
query : str | |
The search query. | |
""" | |
title: tuple[str, str] = self.query_wiki(self.wikipedia_api_url, query) | |
embed = self.create_embed(title, ctx) | |
await ctx.send(embed=embed) | |
async def wikipedia(self, ctx: commands.Context[Tux], *, query: str) -> None: | |
""" | |
Search Wikipedia | |
Parameters | |
---------- | |
ctx : commands.Context[Tux] | |
The context object for the command. | |
query : str | |
The search query. | |
""" | |
title: tuple[str, str] | None = self.query_wiki(self.wikipedia_api_url, query) | |
if not title: | |
await ctx.send("❌ No Wikipedia article found for your query, or the request failed.") | |
return | |
embed = self.create_embed(title, ctx) | |
await ctx.send(embed=embed) |
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found.
Additional details and impacted files@@ Coverage Diff @@
## main #975 +/- ##
========================================
+ Coverage 9.26% 9.29% +0.03%
========================================
Files 123 123
Lines 10390 10399 +9
Branches 1276 1277 +1
========================================
+ Hits 963 967 +4
- Misses 9325 9328 +3
- Partials 102 104 +2
*This pull request uses carry forward flags. Click here to find out more.
☔ View full report in Codecov by Sentry. |
Deploying tux with
|
Latest commit: |
97c3f9d
|
Status: | ✅ Deploy successful! |
Preview URL: | https://9817e2a3.tux-afh.pages.dev |
Branch Preview URL: | https://wikicmd.tux-afh.pages.dev |
Add subcommand to search wikipedia
Summary by Sourcery
Add support for searching Wikipedia from the wiki command by adding a new 'wikipedia' subcommand, configuring its API endpoint, and extending URL generation for Wikipedia results.
New Features:
Enhancements: