mirror of
https://github.com/prosolis/gogobee.git
synced 2026-07-16 08:52:42 +00:00
boredom: the idle clock has to be seeded, or the deploy empties the town
last_player_action_at is NULL for every existing row on the deploy that adds it, and loadBoredomCandidates COALESCEs the NULL onto created_at. created_at is account age, not an idle clock: for anyone who has been playing for a month it is a month old. So the first tick after restart would read the entire server as idle-since-creation and march all of them into a dungeon thirty minutes later, coins debited, including the player who typed a command a minute before the deploy. Seed the column once from last_active_at instead — the best "did something recently" proxy that exists at deploy time, recent for the regulars and stale for the lapsed. It stays unusable as the clock itself (the autopilot bumps it), which is why this is a one-time seed and not a fallback in the query. Re-running on every boot is a no-op, and it skips rows that already have last_boredom_at set, so a restart mid-boredom can't hand a bored character a fresh idle clock off its own autopilot writes and un-bore it permanently. Two smaller ones in the same clock: - a pending prompt counted as an action regardless of ExpiresAt, and nothing sweeps p.pending. One offered-and-ignored treasure prompt and every idle remark that player ever made would read as tending their adventurer, forever. - the command test ran 50 IsCommand passes over the body on every message the bot sees, in every room. One tokenise-and-look-up does the same job.
This commit is contained in:
@@ -100,14 +100,33 @@ var advActionCommands = map[string]bool{
|
||||
// something to their adventurer — an Adventure command, or a reply to a prompt
|
||||
// we're holding open for them (shop, blacksmith, pet, treasure). Both count:
|
||||
// answering "2" to a shop menu is as much an action as typing `!shop`.
|
||||
//
|
||||
// This runs on every message the bot sees, in every room, so the command test
|
||||
// is a single tokenise-and-look-up rather than 50 passes of IsCommand over the
|
||||
// body. It matches util.IsCommand's rule exactly: trimmed, lowercased, the
|
||||
// command is the whole body or is followed by a space.
|
||||
//
|
||||
// The pending-prompt check honours ExpiresAt. Nothing sweeps p.pending, so an
|
||||
// abandoned prompt (offered, never answered) sits there forever — without the
|
||||
// expiry test, every idle remark that player ever makes in any room would read
|
||||
// as tending their adventurer, and the clock would never run down.
|
||||
func (p *AdventurePlugin) isPlayerAdventureAction(ctx MessageContext) bool {
|
||||
for name := range advActionCommands {
|
||||
if p.IsCommand(ctx.Body, name) {
|
||||
body := strings.ToLower(strings.TrimSpace(ctx.Body))
|
||||
if strings.HasPrefix(body, p.Prefix) {
|
||||
word := strings.TrimPrefix(body, p.Prefix)
|
||||
if i := strings.IndexByte(word, ' '); i >= 0 {
|
||||
word = word[:i]
|
||||
}
|
||||
if advActionCommands[word] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if _, pending := p.pending.Load(string(ctx.Sender)); pending {
|
||||
return true
|
||||
if v, ok := p.pending.Load(string(ctx.Sender)); ok {
|
||||
pi, isPrompt := v.(*advPendingInteraction)
|
||||
// A zero ExpiresAt is a prompt with no deadline, not an expired one.
|
||||
if isPrompt && (pi.ExpiresAt.IsZero() || time.Now().Before(pi.ExpiresAt)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user