Skip to content

Compact doc feature #3295

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

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Conversation

anand2312
Copy link
Member

@anand2312 anand2312 commented Mar 14, 2025

As per @decorator-factory 's suggestion:

!d provides a pretty huge embed that takes a lot of space, and you need to post a message for each documentation entry. I almost always click the docs link anyway, because the text gets cut off for all but the most trivial items.
It's common for gaming communities on Reddit to have a bot that scans messages for specially formatted mentions of items and gives some very brief information on all of them (and most importantly a documentation link) in a single message: see screenshot. I think it would be pretty cool to be able to type something like

You'll need to use [[zip]] or [[itertools.zip_longest]]

and have the bot reply with a compact message linking to the documentation, like:

This PR implements the feature described, and also reacts to message edits and edits the bot's response.
The bot will only link up to 10 doc items, after which it ignores the rest.

msedge_dkJP218f35

@anand2312
Copy link
Member Author

Sorry for the formatting changes to the unrelated lines. I think they're because I ran ruff format on the file; I can revert those changes if needed

@decorator-factory
Copy link
Member

Sorry for the formatting changes to the unrelated lines. I think they're because I ran ruff format on the file; I can revert those changes if needed

Yeah, I think it's better not to change unrelated lines if we're not checking exactly matching ruff format in the CI

return (
original.id == before.id
and before.content != after.content
and len(re.findall(COMPACT_DOC_REGEX, after.content.replace("`", ""))) > 0
Copy link
Member

Choose a reason for hiding this comment

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

and re.search(COMPACT_DOC_REGEX, after.content.replace("`", "")) is not None

@@ -42,6 +44,10 @@

COMMAND_LOCK_SINGLETON = "inventory refresh"

REDO_EMOJI = "\U0001f501" # :repeat:
REDO_TIMEOUT = 30
COMPACT_DOC_REGEX = r"\[\[(?P<symbol>\S*)\]\]"
Copy link
Member

Choose a reason for hiding this comment

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

The reason I suggested matching specifically

[[`item`]]

is that this won't match Python lists like [[]] or [[initial]] or [[1,2,3]] and lead to confusing/noisy messages from the bot. Maybe this could be changed to

r"\[\[`(?P<symbol>[^\s\]`]*)`\]\]"

? This would also remove the need to strip ` from matches

log.debug("Waiting for inventories to be refreshed before processing item.")
await self.refresh_event.wait()

# Ensure a refresh can't run in case of a context switch until the with block is exited
Copy link
Member

Choose a reason for hiding this comment

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

But a context switch cannot happen if there's no await/async for/async with

Copy link
Member

@vivekashok1221 vivekashok1221 Mar 15, 2025

Choose a reason for hiding this comment

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

I believe the code is fine but the comment needs adjusting. Not sure if context switch in the asyncio sense is what the original author (before anand moved it around) meant.
Ignore

log.debug("Waiting for inventories to be refreshed before processing item.")
await self.refresh_event.wait()

# Ensure a refresh can't run in case of a context switch until the with block is exited
Copy link
Member

@vivekashok1221 vivekashok1221 Mar 15, 2025

Choose a reason for hiding this comment

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

I believe the code is fine but the comment needs adjusting. Not sure if context switch in the asyncio sense is what the original author (before anand moved it around) meant.
Ignore

@@ -439,8 +537,7 @@ async def refresh_command(self, ctx: commands.Context) -> None:
removed = "- " + removed

embed = discord.Embed(
title="Inventories refreshed",
description=f"```diff\n{added}\n{removed}```" if added or removed else ""
title="Inventories refreshed", description=f"```diff\n{added}\n{removed}```" if added or removed else ""
Copy link
Member

Choose a reason for hiding this comment

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

You forgot to revert this formatting change.

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.

3 participants