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>
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import type { RowDataPacket } from 'mysql2'
|
|
import { db, DB } from './db'
|
|
|
|
async function priceFrom(table: string, fallback: number): Promise<number> {
|
|
try {
|
|
const [rows] = await db(DB.default).query<RowDataPacket[]>(`SELECT price FROM ${table} LIMIT 1`)
|
|
return rows[0] ? Number(rows[0].price) : fallback
|
|
} catch {
|
|
return fallback
|
|
}
|
|
}
|
|
|
|
export const getRenamePrice = () => priceFrom('home_renameprice', 2.0)
|
|
export const getCustomizePrice = () => priceFrom('home_customizeprice', 1.0)
|
|
export const getChangeRacePrice = () => priceFrom('home_changeraceprice', 10.0)
|
|
export const getChangeFactionPrice = () => priceFrom('home_changefactionprice', 10.0)
|
|
export const getLevelUpPrice = () => priceFrom('home_levelupprice', 10.0)
|
|
export const getTransferPrice = () => priceFrom('home_transferprice', 10.0)
|
|
export const getRestoreItemPrice = () => priceFrom('home_restoreitemprice', 1.0)
|
|
|
|
export interface GoldOption {
|
|
gold_amount: number
|
|
price: number
|
|
}
|
|
|
|
export async function getGoldOptions(): Promise<GoldOption[]> {
|
|
try {
|
|
const [rows] = await db(DB.default).query<RowDataPacket[]>(
|
|
'SELECT gold_amount, price FROM home_goldprice ORDER BY gold_amount',
|
|
)
|
|
return rows.map((r) => ({ gold_amount: r.gold_amount, price: Number(r.price) }))
|
|
} catch {
|
|
return []
|
|
}
|
|
}
|
|
|
|
/** Precio de una cantidad de oro concreta (0 si no existe esa opción). */
|
|
export async function goldPriceFor(goldAmount: number): Promise<number> {
|
|
const opts = await getGoldOptions()
|
|
return opts.find((o) => o.gold_amount === goldAmount)?.price ?? 0
|
|
}
|