Skip to content

[WIP] Intro autopost on new intro creation#113

Open
Sukhpreet-s wants to merge 23 commits into
mainfrom
sukhpreet-s-intro-autopost-plan
Open

[WIP] Intro autopost on new intro creation#113
Sukhpreet-s wants to merge 23 commits into
mainfrom
sukhpreet-s-intro-autopost-plan

Conversation

@Sukhpreet-s

@Sukhpreet-s Sukhpreet-s commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

This PR implements a feature to auto-post in newly created intro posts + provides a button to lookup game threads for the mentioned games in the post.

Something like this:
image

Changes are made in following areas:

Sukhpreet-s and others added 10 commits June 21, 2026 01:18
- Add lfg_batch_search agent tool to support batch game thread lookups
  - Takes list of game names as input
  - Returns found threads grouped by game with missing games list
  - Queries forum cache for each game and aggregates results

- Create intro/interactions.go with button handler for game thread lookup
  - Handles intro_lookup_games:: custom ID from button clicks
  - Extracts thread ID and user ID from custom ID format
  - Defers response and logs action
  - Dispatches to agent for full orchestration

- Update module_handler.go to route intro button interactions
  - Added case for intro_lookup_games:: prefix
  - Routes to intro module's HandleComponent method

- Add comprehensive tests
  - agent_tools_test.go: tests batch search with various scenarios
  - interactions_test.go: tests button routing and component handling

Contract:
- Button custom ID format: intro_lookup_games::<thread_id>::<user_id>
- Agent tool lfg_batch_search accepts game_names []string
- Returns batchSearchResult with games and missingGames fields

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Changed button custom_id format from 'intro_lookup_games::<thread_id>::<user_id>'
to 'intro:lookup-games' (simple prefix) for consistency with existing LFG patterns.

Thread ID and user ID now extracted from interaction metadata:
- threadID from i.ChannelID (threads are channels in Discord)
- userID from i.Member.User.ID or i.User.ID

This aligns with simpler LFG button IDs like 'lfg_panel_open_modal' and reduces
custom_id parsing complexity.

Updated:
- interactions.go: Simplified to extract context from metadata instead of parsing custom_id
- interactions_test.go: Updated test helper to use new format
- module_handler.go: Updated prefix check to 'intro:lookup-games'

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add PostAutoMessageToThread() to IntroFeedService that posts an embed with:
  * Feed channel link/mention
  * /intro command help text
  * /bump-intro command help text
  * 'Lookup Game Threads' button with custom_id 'intro:lookup-games'

- Modify HandleNewIntroThread() to call PostAutoMessageToThread() after
  successful feed post. Auto-post errors don't fail the overall flow.

- Add HandleComponent() to intro module to handle 'intro:lookup-games' button
  clicks. Responds with ephemeral placeholder message (actual game-thread
  lookup deferred to future session).

- Update module_handler HandleComponentInteraction() to route 'intro:' custom_id
  prefixes to intro module instead of LFG catch-all. Prevents intro buttons
  from being mishandled by LFG routing.

- Add unit tests for PostAutoMessageToThread() error handling
- Add tests for HandleComponent() button recognition
- Verify routing and module availability

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- route intro component custom_id intro:lookup-games in module handler
- add intro component handler that defers interaction, calls agent with exact
  prompt Find the game threads for the games <@{userID}> plays. and parses
  JSON response into deterministic markdown output
- inject agent into shared command dependencies via ComponentAgent interface
- add Agent.HandleComponent(s, i, prompt) entrypoint that receives full
  InteractionCreate context and enforces JSON-only output contract
- extend lfg agent tools with lfg_batch_search for multi-game lookup,
  returning games, missing_games, and create-a-thread note fallback/mention
- add tests for intro component flow, lfg batch lookup, and agent JSON
  normalization behavior

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- sync internal request prompt artifacts from planning session by adding
  internal_request_mode.md and prompt-contract tests
- update agent run path to accept explicit system prompt + mode, keeping
  base queries on original sys_prompt behavior and internal queries on
  internal-only prompt behavior
- replace component interaction entrypoint with HandleInternal(s, prompt)
  returning raw model response text
- update intro lookup flow to call internal handle, parse internal JSON
  shape, and build deterministic markdown inline in handler
- remove obsolete agent JSON normalization component tests and add prompt
  contract tests for internal request mode

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- change NewModuleHandler to receive the agent instance from bot.New
  instead of deriving it inside module handler
- pass the single shared agent from bot.New to module handler deps
- update agentadapter module to wrap the injected agent and stop creating
  a second agent instance

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Sukhpreet-s Sukhpreet-s requested a review from BagToad as a code owner June 23, 2026 02:44
@Sukhpreet-s Sukhpreet-s added the deploy-dev Request a deployment to the dev bot label Jun 23, 2026
@github-actions github-actions Bot removed the deploy-dev Request a deployment to the dev bot label Jun 23, 2026
Sukhpreet-s and others added 5 commits June 23, 2026 00:36
@Sukhpreet-s Sukhpreet-s added the deploy-dev Request a deployment to the dev bot label Jun 23, 2026
@github-actions github-actions Bot removed the deploy-dev Request a deployment to the dev bot label Jun 23, 2026
@Sukhpreet-s Sukhpreet-s changed the title sukhpreet s intro autopost plan Intro autopost on new intro creation Jun 23, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Sukhpreet-s Sukhpreet-s added the deploy-dev Request a deployment to the dev bot label Jun 24, 2026
@github-actions github-actions Bot removed the deploy-dev Request a deployment to the dev bot label Jun 24, 2026
@Sukhpreet-s Sukhpreet-s changed the title Intro autopost on new intro creation [WIP] Intro autopost on new intro creation Jun 25, 2026
Squashed from sub-session commits: b770ce4, ce2ac1c, ac098d8 (excluding 9c63fd4).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Sukhpreet-s Sukhpreet-s added the deploy-dev Request a deployment to the dev bot label Jun 26, 2026
@github-actions github-actions Bot removed the deploy-dev Request a deployment to the dev bot label Jun 26, 2026

BagToad commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Bug review — "Lookup Game Threads" button

Investigated the reported issue that clicking the refresh/lookup button "doesn't work." Build and tests pass, so these are behavioral/robustness issues rather than compile errors.

1. The button is destroyed on every path, so it can never be retried (the reported symptom)

In internal/commands/modules/intro/interactions.go, every response uses clearComponents (an empty component slice), including all failure paths in handleLookupGamesComponent:

  • agent unavailable (line 132), empty reply (line 140), invalid JSON (line 147), and success (line 153).

The moment the button is clicked it disappears. If the lookup fails for any reason, the user is left with an error message and no button to click again — even though two of those messages say "Please try again." From the user's perspective: one click, an error, and it's gone. A retry/refresh button should keep its components on the error paths.

2. The lookup fails silently and brittly on non-JSON agent output

  • Line 137: jsonReply := m.config.Agent.HandleInternal(...)
  • Line 145: json.Unmarshal([]byte(jsonReply), &agentResult) with no tolerance for markdown code fences.

The internal prompt (internal/agentengine/prompts/internal_request_mode.md) asks the model not to wrap output in ```json fences, but LLMs frequently do anyway. Any fenced or prose-prefixed response makes Unmarshal fail → "❌ The lookup response was not valid JSON" → button removed (see #1). This makes the feature appear broken intermittently. Stripping/extracting a fenced JSON block before unmarshalling would be much more robust.

3. All interaction errors are swallowed

Every introRespond/introEdit call ignores its error (_ = ... / _, _ = ...), e.g. lines 132/140/147/153. If InteractionResponseEdit fails (e.g. content exceeding Discord's 2000-char limit once the intro preamble + game list are concatenated, or an expired interaction token), the message simply doesn't update and nothing visible happens — with no log to diagnose it. At minimum these failures should be logged.

4. Import block isn't gofmt-clean

internal/agentengine/agent.go adds "regexp" after "slices", so gofmt -l flags the file:

-	"slices"
 	"regexp"
+	"slices"

It compiles and tests.yml only runs go build + go test (no fmt gate), so CI stays green — but go fmt/editors will keep reordering it.

Minor observations (not bugs)

  • The button label is "🎮 Lookup Game Threads" but it behaves as a one-shot action, not a repeatable "refresh." If repeatable interaction is intended, Bump golang.org/x/crypto from 0.14.0 to 0.35.0 #1 must be fixed and the success path should retain the button.
  • HandleNewIntroThread (service.go) only posts the auto-message + button when the intro is actually forwarded; users skipped due to cooldown never get the button (likely intended).

The single change most likely to resolve the "doesn't work" report is #1 (don't strip the button on failure), closely followed by #2 (tolerate fenced JSON).

Sukhpreet-s and others added 4 commits June 29, 2026 18:37
- Refactor intro lookup auto-post state flow

- Use DB timestamp for lookup execution upsert

- Adjust intro lookup logs

- Add intro auto-message service logs

- Remove AccentColor from intro auto-message container

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- strip fenced JSON in HandleInternal

- move system prompt assembly to Handle/HandleInternal callers

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Combined commit messages:

refactor: enhance auto-message handling and component parsing for intro threads

refactor: rename `AutoMessage` to `AutoPost`

refactor intro auto post state handling

add intro auto post helpers

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@Sukhpreet-s Sukhpreet-s added the deploy-dev Request a deployment to the dev bot label Jul 1, 2026
@github-actions github-actions Bot removed the deploy-dev Request a deployment to the dev bot label Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

❌ Development deployment to Azure Container Apps failed.

View workflow run

@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

❌ Development deployment to Azure Container Apps failed.

View workflow run

@Sukhpreet-s Sukhpreet-s added the deploy-dev Request a deployment to the dev bot label Jul 2, 2026
@github-actions github-actions Bot removed the deploy-dev Request a deployment to the dev bot label Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

❌ Development deployment to Azure Container Apps failed.

View workflow run

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

❌ Development deployment to Azure Container Apps failed.

View workflow run

@Sukhpreet-s Sukhpreet-s added the deploy-dev Request a deployment to the dev bot label Jul 2, 2026
@github-actions github-actions Bot removed the deploy-dev Request a deployment to the dev bot label Jul 2, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@Sukhpreet-s Sukhpreet-s added the deploy-dev Request a deployment to the dev bot label Jul 4, 2026
@github-actions github-actions Bot removed the deploy-dev Request a deployment to the dev bot label Jul 4, 2026
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