fix: rotate challenge each session
Stop hook clears active.challenge after reporting it. Start hook assigns a random challenge from the buddy's pool if none is set. Result: fresh challenge every session, no stale repeat.
This commit is contained in:
parent
95ffc92e7d
commit
1930bd29bd
2 changed files with 16 additions and 1 deletions
|
|
@ -101,6 +101,20 @@ if ch:
|
||||||
echo "${ctx}"
|
echo "${ctx}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Assign a fresh challenge if none is set
|
||||||
|
python3 << PYEOF
|
||||||
|
import json, random
|
||||||
|
catalog = json.load(open('${CATALOG}'))
|
||||||
|
active_file = '${ACTIVE_FILE}'
|
||||||
|
active = json.load(open(active_file))
|
||||||
|
buddy_id = active.get('buddymon_id')
|
||||||
|
if buddy_id and not active.get('challenge'):
|
||||||
|
pool = catalog.get('buddymon', {}).get(buddy_id, {}).get('challenges', [])
|
||||||
|
if pool:
|
||||||
|
active['challenge'] = random.choice(pool)
|
||||||
|
json.dump(active, open(active_file, 'w'), indent=2)
|
||||||
|
PYEOF
|
||||||
|
|
||||||
CONTEXT=$(build_context)
|
CONTEXT=$(build_context)
|
||||||
|
|
||||||
# Escape for JSON
|
# Escape for JSON
|
||||||
|
|
|
||||||
|
|
@ -87,12 +87,13 @@ print('\n'.join(lines))
|
||||||
PYEOF
|
PYEOF
|
||||||
)
|
)
|
||||||
|
|
||||||
# Reset session XP counter for next session (keep total in roster)
|
# Reset session XP + clear challenge so next session assigns a fresh one
|
||||||
python3 << PYEOF
|
python3 << PYEOF
|
||||||
import json
|
import json
|
||||||
active_file = '${BUDDYMON_DIR}/active.json'
|
active_file = '${BUDDYMON_DIR}/active.json'
|
||||||
active = json.load(open(active_file))
|
active = json.load(open(active_file))
|
||||||
active['session_xp'] = 0
|
active['session_xp'] = 0
|
||||||
|
active['challenge'] = None
|
||||||
json.dump(active, open(active_file, 'w'), indent=2)
|
json.dump(active, open(active_file, 'w'), indent=2)
|
||||||
PYEOF
|
PYEOF
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue