Files
tiennm99bot/src/modules/twentyq/index.js
T
tiennm99 0be7cc9a95 chore: project cleanup — purge stale function-calling refs + sync docs
Followed code-reviewer audit. Findings applied:
- twentyq/README.md, twentyq/index.js header — claimed "function calling"
  + ANSWER_FUNCTION_SCHEMA / submit_answer; rewrite to JSON-in-content
  matching what the code actually does. Added generateRoundStart line.
- wrangler.toml [ai] comment — list both bge-m3 (semantle/doantu) AND
  gemma-4 (twentyq) consumers; drop neuron math that no longer matched.
- scripts/stub-kv.js — drop reference to nonexistent REGISTER_DRYRUN flag.
- twentyq/ai-client.redactSecret — strip dead "if (out.length > 0)" branch
  (String.replace cannot produce empty string from the inputs we pass).
- handlers.test.js — drop noise saveGame() before "no games" stats assert;
  add ai.run call-count guards on two-AI-call flows.
- docs/codebase-summary.md — full rewrite of Active Modules table
  (semantle/doantu/lolschedule/twentyq were missing); fix vitest 2→4 +
  wrangler 3→4 versions; replace stale 200-test count with current ~450.
- docs/architecture.md — file tree includes lolschedule/semantle/doantu/
  twentyq + cron-dispatcher + sql-store* + scripts/migrate.js;
  moduleRegistry snippet matches src/modules/index.js.
- docs/todo.md — entire file obsolete (D1 UUID populated, cron live).
  Deleted.

Tests: 449 pass, lint clean.
2026-04-24 18:30:25 +07:00

51 lines
1.6 KiB
JavaScript

/**
* @file Twentyq module — reverse-Akinator yes/no guessing game.
*
* Bot picks a secret keyword from ./seeds.js. Workers AI
* (@cf/google/gemma-4-26b-a4b-it) generates {category, initialHint} at
* round start and emits a one-line JSON {is_guess, answer, hint} per turn.
* Round ends on a correct guess or /twentyq_giveup. Unlimited turns.
* Per-subject state in KV (user id in DMs, chat id in groups).
*
* `init` captures both the prefixed KV store AND the raw env so handlers can
* reach env.AI per request without changing the dispatcher contract.
*/
import { handleGiveup, handleStats, handleTwentyq } from "./handlers.js";
/** @type {import("../../db/kv-store-interface.js").KVStore | null} */
let db = null;
/** @type {any} */
let aiEnv = null;
/** @type {import("../registry.js").BotModule} */
const twentyqModule = {
name: "twentyq",
init: async ({ db: store, env }) => {
db = store;
aiEnv = env;
},
commands: [
{
name: "twentyq",
visibility: "public",
description: "20 questions — bot picks an object, you ask yes/no questions",
handler: (ctx) => handleTwentyq(ctx, { db, env: aiEnv }),
},
{
name: "twentyq_giveup",
visibility: "public",
description: "Reveal the current twentyq answer (auto-starts a fresh round)",
handler: (ctx) => handleGiveup(ctx, { db }),
},
{
name: "twentyq_stats",
visibility: "public",
description: "Show your twentyq stats (played, solved, best round)",
handler: (ctx) => handleStats(ctx, { db }),
},
],
};
export default twentyqModule;