ban-history: alcance y estado multiidioma
getSanctions devuelve claves (scopeKey account/battlenet/character + scopeName;
statusKey active/activePermanent/expired) en vez de español. La página traduce
alcance ("Character: {name}") y estado; "Permanente" ya usaba clave. Motivo y
autor son datos del GM (no se traducen). Nuevas claves History.ban.scope/status.
Verificado con sanciones de prueba (todos los combos resuelven en es y en).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+18
-12
@@ -1,26 +1,31 @@
|
||||
import type { RowDataPacket } from 'mysql2'
|
||||
import { db, DB } from './db'
|
||||
|
||||
/** Una sanción (baneo o muteo) de la cuenta. */
|
||||
/** Una sanción (baneo o muteo) de la cuenta. Textos visibles como claves i18n. */
|
||||
export interface Sanction {
|
||||
scope: string // 'Cuenta' | 'Battle.net' | 'Personaje: Nombre'
|
||||
reason: string
|
||||
by: string
|
||||
scopeKey: 'account' | 'battlenet' | 'character'
|
||||
scopeName: string // nombre del personaje (solo para scopeKey='character')
|
||||
reason: string // motivo escrito por el GM (dato, no se traduce)
|
||||
by: string // quién sancionó (dato)
|
||||
date: Date
|
||||
expires: Date | null // null = permanente
|
||||
active: boolean
|
||||
status: string // etiqueta: Activo / Activo (permanente) / Expirado
|
||||
statusKey: 'active' | 'activePermanent' | 'expired'
|
||||
}
|
||||
|
||||
/** Estado de un baneo a partir de sus timestamps UNIX (segundos) y el flag active. */
|
||||
function banState(bandate: number, unbandate: number, active?: number): { active: boolean; status: string; expires: Date | null } {
|
||||
function banState(
|
||||
bandate: number,
|
||||
unbandate: number,
|
||||
active?: number,
|
||||
): { active: boolean; statusKey: Sanction['statusKey']; expires: Date | null } {
|
||||
const now = Math.floor(Date.now() / 1000)
|
||||
const permanent = unbandate === 0 || unbandate <= bandate
|
||||
const flagActive = active === undefined ? true : active === 1
|
||||
const stillActive = flagActive && (permanent || unbandate > now)
|
||||
return {
|
||||
active: stillActive,
|
||||
status: stillActive ? (permanent ? 'Activo (permanente)' : 'Activo') : 'Expirado',
|
||||
statusKey: stillActive ? (permanent ? 'activePermanent' : 'active') : 'expired',
|
||||
expires: permanent ? null : new Date(unbandate * 1000),
|
||||
}
|
||||
}
|
||||
@@ -46,7 +51,7 @@ export async function getSanctions(accountId: number, bnetId?: number): Promise<
|
||||
)
|
||||
for (const r of rows) {
|
||||
const s = banState(Number(r.bandate), Number(r.unbandate), Number(r.active))
|
||||
bans.push({ scope: 'Cuenta', reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s })
|
||||
bans.push({ scopeKey: 'account', scopeName: '', reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s })
|
||||
}
|
||||
} catch {
|
||||
/* AC no poblado */
|
||||
@@ -61,7 +66,7 @@ export async function getSanctions(accountId: number, bnetId?: number): Promise<
|
||||
)
|
||||
for (const r of rows) {
|
||||
const s = banState(Number(r.bandate), Number(r.unbandate))
|
||||
bans.push({ scope: 'Battle.net', reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s })
|
||||
bans.push({ scopeKey: 'battlenet', scopeName: '', reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s })
|
||||
}
|
||||
} catch {
|
||||
/* AC no poblado */
|
||||
@@ -80,7 +85,7 @@ export async function getSanctions(accountId: number, bnetId?: number): Promise<
|
||||
)
|
||||
for (const r of rows) {
|
||||
const s = banState(Number(r.bandate), Number(r.unbandate), Number(r.active))
|
||||
bans.push({ scope: `Personaje: ${nameByGuid.get(Number(r.guid)) ?? '?'}`, reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s })
|
||||
bans.push({ scopeKey: 'character', scopeName: nameByGuid.get(Number(r.guid)) ?? '?', reason: String(r.banreason || '—'), by: String(r.bannedby || '—'), date: new Date(Number(r.bandate) * 1000), ...s })
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
@@ -98,13 +103,14 @@ export async function getSanctions(accountId: number, bnetId?: number): Promise<
|
||||
const end = Number(r.mutetime)
|
||||
const active = end > now
|
||||
mutes.push({
|
||||
scope: 'Cuenta',
|
||||
scopeKey: 'account',
|
||||
scopeName: '',
|
||||
reason: String(r.mutereason || '—'),
|
||||
by: String(r.mutedby || '—'),
|
||||
date: new Date(Number(r.mutedate) * 1000),
|
||||
expires: end > 0 ? new Date(end * 1000) : null,
|
||||
active,
|
||||
status: active ? 'Activo' : 'Expirado',
|
||||
statusKey: active ? 'active' : 'expired',
|
||||
})
|
||||
}
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user