enchance farming/fix

This commit is contained in:
2026-04-29 23:22:25 +03:00
parent 2517538b88
commit 0643422a30
4 changed files with 154 additions and 73 deletions

View File

@@ -256,15 +256,29 @@ def sync_request():
@api.route('/api/commands/<int:cmd_id>/result', methods=['POST'])
def command_result(cmd_id):
data = request.get_json(silent=True) or {}
status = data.get('status', 'done') # 'done' | 'failed'
status = data.get('status', 'done') # 'done' | 'failed' | 'pending' (requeue)
msg = data.get('message', '')
now = datetime.utcnow().isoformat()
conn = get_db()
# Look up type + player_id for post-update hooks
cmd = conn.execute(
'SELECT type, player_id FROM commands WHERE id = ?', (cmd_id,)
).fetchone()
conn.execute('''
UPDATE commands
SET status = ?, result_msg = ?, updated_at = ?
WHERE id = ?
''', (status, msg, datetime.utcnow().isoformat(), cmd_id))
''', (status, msg, now, cmd_id))
# When an explicit farm_loot command succeeds, record the timestamp
if cmd and cmd['type'] == 'farm_loot' and status == 'done' and cmd['player_id']:
conn.execute('''
INSERT INTO kv_store (key, value, updated_at) VALUES (?, ?, ?)
ON CONFLICT(key) DO UPDATE SET value=excluded.value, updated_at=excluded.updated_at
''', (f'last_farmed_{cmd["player_id"]}', now, now))
conn.commit()
conn.close()
return jsonify({'ok': True})
@@ -334,10 +348,17 @@ def farm_status():
conn = get_db()
if request.method == 'POST':
data = request.get_json(silent=True) or {}
now = datetime.utcnow().isoformat()
conn.execute('''
INSERT INTO kv_store (key, value, updated_at) VALUES (?, ?, ?)
ON CONFLICT(key) DO UPDATE SET value=excluded.value, updated_at=excluded.updated_at
''', (kv_key, json.dumps(data), datetime.utcnow().isoformat()))
''', (kv_key, json.dumps(data), now))
# Auto-farm reports warehouse_full=false when it successfully looted something
if not data.get('warehouse_full', True):
conn.execute('''
INSERT INTO kv_store (key, value, updated_at) VALUES (?, ?, ?)
ON CONFLICT(key) DO UPDATE SET value=excluded.value, updated_at=excluded.updated_at
''', (f'last_farmed_{player_id}', now, now))
conn.commit()
conn.close()
return jsonify({'ok': True})