mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-09-20 04:23:43 +00:00
- Add new modules: doantu, semantle, twentyq, ai (Gemini integration) - Update module registry with new command registration - Update tests and documentation for module system - Update README with new module references
53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package twentyq
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/binary"
|
|
mrand "math/rand/v2"
|
|
|
|
"github.com/tiennm99/miti99bot-go/internal/ai"
|
|
"github.com/tiennm99/miti99bot-go/internal/modules"
|
|
)
|
|
|
|
// New is the twentyq module Factory. If Deps.Chatter is nil
|
|
// (GEMINI_API_KEY unset) the module loads but every command replies with a
|
|
// config-error message — keeps the rest of the bot functional.
|
|
func New(deps modules.Deps) modules.Module {
|
|
s := &state{
|
|
kv: deps.KV,
|
|
chatter: deps.Chatter,
|
|
limiter: ai.NewPerUserLimiter(5.0/60.0, 5),
|
|
rng: newRNG(),
|
|
}
|
|
return modules.Module{
|
|
Commands: []modules.Command{
|
|
{
|
|
Name: "twentyq",
|
|
Visibility: modules.VisibilityPublic,
|
|
Description: "20 questions — bot picks an object, you ask yes/no questions",
|
|
Handler: s.handleTwentyq,
|
|
},
|
|
{
|
|
Name: "twentyq_giveup",
|
|
Visibility: modules.VisibilityPublic,
|
|
Description: "Reveal the current twentyq answer (auto-starts a fresh round)",
|
|
Handler: s.handleGiveup,
|
|
},
|
|
{
|
|
Name: "twentyq_stats",
|
|
Visibility: modules.VisibilityPublic,
|
|
Description: "Show your twentyq stats (played, solved, best round)",
|
|
Handler: s.handleStats,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func newRNG() *mrand.Rand {
|
|
var seed [16]byte
|
|
_, _ = rand.Read(seed[:])
|
|
s1 := binary.LittleEndian.Uint64(seed[0:8])
|
|
s2 := binary.LittleEndian.Uint64(seed[8:16])
|
|
return mrand.New(mrand.NewPCG(s1, s2))
|
|
}
|