Skip to content

Wikipedia command port from grace to ada#15

Merged
PenguinBoi12 merged 5 commits intoCode-Society-Lab:mainfrom
Shadwz17:main
May 3, 2026
Merged

Wikipedia command port from grace to ada#15
PenguinBoi12 merged 5 commits intoCode-Society-Lab:mainfrom
Shadwz17:main

Conversation

@Shadwz17
Copy link
Copy Markdown
Contributor

@Shadwz17 Shadwz17 commented May 1, 2026

Ports Grace's Wikipedia command to Ada as !wiki <query>.

  • Adds bot/extensions/wikipedia_extension.py
  • No config, dependency, or database changes
  • Uses only Python stdlib modules: asyncio, json, and urllib

How it works

  • Calls Wikipedia's OpenSearch API, the same endpoint Grace uses.
  • Shows the top 3 results as inline links.
  • Runs the blocking HTTP request with asyncio.to_thread() so it does not block the bot.
  • Uses a 5-second timeout.
  • Sends a descriptive User-Agent with the bot name and project URL, following Wikimedia's User-Agent policy.
  • Handles:
    • Missing query
    • Query too long
    • No results
    • Wikipedia connection errors
    • Unexpected API response format

Example

User:

!wiki python

Response example:

#### Wikipedia results for "_python_"

> **1.** [Python](<https://en.wikipedia.org/wiki/Python>)
> **2.** [Python (programming language)](<https://en.wikipedia.org/wiki/Python_(programming_language)>)
> **3.** [Monty Python](<https://en.wikipedia.org/wiki/Monty_Python>)

Screenshot:

Screenshot 2026-05-01 192359

Error cases

  • !wikiPlease provide a search query. Usage: !wiki <search query>
  • !wiki asdfghjklqwertyNo results found for 'asdfghjklqwerty'.
  • Long query → Search query is too long. Please limit it to 300 characters or less.
  • Bad API response → Unexpected response format from Wikipedia API.
  • Wikipedia unreachable → Sorry, I couldn't reach Wikipedia.

Copy link
Copy Markdown
Collaborator

@PenguinBoi12 PenguinBoi12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good PR so far. It's clean, well typed and you used matrix.py very well. I've let a few comments but only simple stuff. GG so far.

Don't forget to run black . to format the code, add some unit tests and validate types with mypy (although it seems fine).

Well done!!! As always, don't hesitate if you have any questions.

Comment thread bot/extensions/wikipedia_extension.py Outdated
Comment thread bot/extensions/wikipedia_extension.py Outdated
Comment thread bot/extensions/wikipedia_extension.py Outdated
Comment thread bot/extensions/wikipedia_extension.py Outdated
Comment thread bot/extensions/wikipedia_extension.py Outdated
Copy link
Copy Markdown
Collaborator

@PenguinBoi12 PenguinBoi12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! One small change to do in tests (very nothing big) but otherwise it's good.

Comment thread bot/extensions/wikipedia_extension.py Outdated
Comment thread tests/extensions/test_wikipedia_extension.py Outdated
Comment thread tests/extensions/test_wikipedia_extension.py
Copy link
Copy Markdown
Collaborator

@PenguinBoi12 PenguinBoi12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, well done!

@PenguinBoi12 PenguinBoi12 merged commit 17f42be into Code-Society-Lab:main May 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants