671632a6a0
- Nuevo servicio de pago `restore-item` (getRestoreItemPrice default 1€, fulfill SOAP `.item restore <recover_id> <char>`). Al pulsar "Recuperar" se crea un checkout de SumUp y al pagar se ejecuta el restore. - Se quita el descuento de 100 PD y el gate "No tienes PD suficientes". - La búsqueda sigue igual (gratis, cooldown 8h, Turnstile). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
76 lines
2.7 KiB
TypeScript
76 lines
2.7 KiB
TypeScript
import type { RowDataPacket } from 'mysql2'
|
|
import { db, DB } from './db'
|
|
import { executeSoapCommand } from './soap'
|
|
import { getGameCharacters } from './characters'
|
|
|
|
/**
|
|
* Recuperar ítems (/restore-items): usa el sistema de recuperación de AzerothCore
|
|
* por SOAP. `.item restore list <char>` lista los ítems borrados recuperables (el
|
|
* core aplica las condiciones: calidad Raro+, equipable, se liga al recoger,
|
|
* borrado < 7 días). La consulta tiene cooldown de 8 h por personaje. La restauración
|
|
* de cada ítem se paga por **SumUp** (servicio `restore-item`, ejecuta `.item restore`).
|
|
*/
|
|
|
|
const SEARCH_COOLDOWN_MS = 8 * 60 * 60 * 1000
|
|
const SAFE_NAME = /^[A-Za-z]{1,12}$/
|
|
|
|
export interface DeletedItem {
|
|
recoverId: number
|
|
itemId: number
|
|
name: string
|
|
count: number
|
|
}
|
|
|
|
/** Parsea la salida de `.item restore list` (líneas "Recover id: X | Item: NAME (ID) | Count: N"). */
|
|
export function parseRecoverList(soap: string): DeletedItem[] {
|
|
const items: DeletedItem[] = []
|
|
const re = /Recover id:\s*(\d+)\s*\|\s*Item:\s*(.+?)\s*\((\d+)\)\s*\|\s*Count:\s*(\d+)/g
|
|
let m: RegExpExecArray | null
|
|
while ((m = re.exec(soap)) !== null) {
|
|
items.push({ recoverId: Number(m[1]), name: m[2].trim(), itemId: Number(m[3]), count: Number(m[4]) })
|
|
}
|
|
return items
|
|
}
|
|
|
|
async function ownsCharacter(accountId: number, character: string): Promise<boolean> {
|
|
if (!SAFE_NAME.test(character)) return false
|
|
const chars = await getGameCharacters(accountId)
|
|
return chars.some((c) => c.name === character)
|
|
}
|
|
|
|
export interface ListResult {
|
|
success: boolean
|
|
error?: string
|
|
minutes?: number
|
|
items?: DeletedItem[]
|
|
}
|
|
|
|
/** Lista los ítems borrados recuperables de un personaje (cooldown 8 h). */
|
|
export async function listDeletedItems(accountId: number, character: string): Promise<ListResult> {
|
|
if (!(await ownsCharacter(accountId, character))) return { success: false, error: 'characterNotOwned' }
|
|
|
|
// Cooldown de 8 h por personaje.
|
|
try {
|
|
const [last] = await db(DB.default).query<RowDataPacket[]>(
|
|
'SELECT used_at FROM home_itemsearchhistory WHERE character_name = ? ORDER BY used_at DESC LIMIT 1',
|
|
[character],
|
|
)
|
|
if (last[0]) {
|
|
const diff = Date.now() - new Date(last[0].used_at).getTime()
|
|
if (diff < SEARCH_COOLDOWN_MS) {
|
|
return { success: false, error: 'cooldown', minutes: Math.ceil((SEARCH_COOLDOWN_MS - diff) / 60000) }
|
|
}
|
|
}
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
|
|
const soap = await executeSoapCommand(`.item restore list ${character}`)
|
|
if (soap === null) return { success: false, error: 'soapError' }
|
|
|
|
await db(DB.default)
|
|
.query('INSERT INTO home_itemsearchhistory (character_name, used_at) VALUES (?, NOW())', [character])
|
|
.catch(() => {})
|
|
return { success: true, items: parseRecoverList(soap) }
|
|
}
|