Skip to content

Add dog command with random picture feature#347

Open
nekeal wants to merge 1 commit into
EuroPython:mainfrom
nekeal:add-random-dog-cog
Open

Add dog command with random picture feature#347
nekeal wants to merge 1 commit into
EuroPython:mainfrom
nekeal:add-random-dog-cog

Conversation

@nekeal

@nekeal nekeal commented May 25, 2026

Copy link
Copy Markdown

Summary

Add /dog hybrid command that fetches random dog pictures from dog.ceo (https://dog.ceo) API.

Changes

  • src/europython_discord/dog/dogclient.py — async HTTP client wrapping the Dog API, returns a random image URL or None on failure
  • src/europython_discord/dog/config.py — DogConfig model with configurable error messages
  • src/europython_discord/dog/cog.py — DogCog with /dog hybrid command; sends an embed on success or a random error message on failure
  • src/europython_discord/bot.py — registers DogCog with optional DogConfig
  • tests/dog/test_cog.py — unit tests for success and error paths
  • Config files — prod-config.toml and test-config.toml gain a [dog] section

Notes

  • Uses @commands.hybrid_command — works both as $dog prefix and /dog slash command

Resolves #341

image

def __init__(self) -> None:
self._session = aiohttp.ClientSession()

async def close(self) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this used?

Comment thread tests/dog/test_cog.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's a lot of setup and indirection for such simple tests. Can this be simplified?

@NMertsch

Copy link
Copy Markdown
Contributor

Hi @nekeal, sorry for the late response, I hope to be more responsive from now on.

Thank you for your work, I'm looking forward to participants' reaction! :)

Here is some feedback. My comments on the code are optional as well.

Required:

  • Please add an alt text to the posted image, e.g. "Random dog of breed [...]" (or just "Random dog image").
  • As discussed on Discord, let's restrict this command to a channel which can be configured in the config file (e.g. channel = "animal-appreciation-channel").
  • Please add a configurable per-user timeout to avoid spam. It's probably enough to keep a dict[userId, lastTimestamp] inside the cog class, and check/update the lastTimestamp on each usage.

Ideas (optional):

  • I think we should add the image source in some way (either https://dog.ceo/, or the actual image URL).
  • Make the source URL configurable.
  • Maybe add other animal generators as well, e.g. https://http.cat/ for /cat? A toml table could work as config.

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.

Random Dog Generator

2 participants