gistfile1.txt
· 2.2 KiB · Text
Неформатований
export namespace score {
/**
* Resolve, validate and persist a score submission for a given userKey.
* Used by both the slash command handler and the modal submit handler.
*/
export async function submitForUser(input: ScoreSubmitInput): Promise<ScoreSubmitResult> {
const { userKey, pts, k, d, atk, def, heal, submittedByOfficer = false } = input;
const { char, borrowedFrom } = getEffectiveCharacter(userKey);
if (!char) {
return { ok: false, message: "❌ No active character found. Use `/tg char set-active` first." };
}
// Resolve slot
let slot: number | null = null;
if (typeof input.slot === "number") {
slot = input.slot;
} else if (typeof input.slot === "string") {
slot = normalizeSlot(input.slot);
if (slot === null) {
return { ok: false, message: `❌ Could not parse slot "${input.slot}".` };
}
} else {
slot = detectSlot() ?? Config.get({ section: "poll", key: "slots" }).find((s) => s.active)?.tgHour ?? 20;
}
await submitScore({
userKey: borrowedFrom ?? userKey,
playedBy: borrowedFrom ? userKey : undefined,
characterName: char.name,
cls: char.class,
nation: char.nation,
pts,
k,
d,
slot,
atk,
def,
heal,
submittedByOfficer,
});
const scoreEmoji = getEmoji("score") || "📊";
const kdEmoji = getEmoji("kd") || "⚔️";
const borrowNote = borrowedFrom ? ` *(borrowed from ${borrowedFrom})*` : "";
const kdNote = k !== undefined && d !== undefined ? `\n${kdEmoji} ${k}/${d}` : "";
const statsNote = [
atk !== undefined ? `ATK: ${atk}` : null,
def !== undefined ? `DEF: ${def}` : null,
heal !== undefined ? `HEAL: ${heal}` : null,
].filter(Boolean).join(" · ");
const charDisplay = format.char(char);
return {
ok: true,
message: `✅ ${scoreEmoji} **${pts}** submitted for ${charDisplay}${borrowNote} (${slot}:00 TG)${kdNote}${statsNote ? `\n${statsNote}` : ""}`,
// message: `✅ ${scoreEmoji} **${pts}** submitted for ${charDisplay}${borrowNote} (${slot}:00 TG)${kdNote}${statsNote ? `\n${statsNote}` : ""}`,
};
}
}
| 1 | export namespace score { |
| 2 | /** |
| 3 | * Resolve, validate and persist a score submission for a given userKey. |
| 4 | * Used by both the slash command handler and the modal submit handler. |
| 5 | */ |
| 6 | export async function submitForUser(input: ScoreSubmitInput): Promise<ScoreSubmitResult> { |
| 7 | const { userKey, pts, k, d, atk, def, heal, submittedByOfficer = false } = input; |
| 8 | |
| 9 | const { char, borrowedFrom } = getEffectiveCharacter(userKey); |
| 10 | if (!char) { |
| 11 | return { ok: false, message: "❌ No active character found. Use `/tg char set-active` first." }; |
| 12 | } |
| 13 | |
| 14 | // Resolve slot |
| 15 | let slot: number | null = null; |
| 16 | if (typeof input.slot === "number") { |
| 17 | slot = input.slot; |
| 18 | } else if (typeof input.slot === "string") { |
| 19 | slot = normalizeSlot(input.slot); |
| 20 | if (slot === null) { |
| 21 | return { ok: false, message: `❌ Could not parse slot "${input.slot}".` }; |
| 22 | } |
| 23 | } else { |
| 24 | slot = detectSlot() ?? Config.get({ section: "poll", key: "slots" }).find((s) => s.active)?.tgHour ?? 20; |
| 25 | } |
| 26 | |
| 27 | await submitScore({ |
| 28 | userKey: borrowedFrom ?? userKey, |
| 29 | playedBy: borrowedFrom ? userKey : undefined, |
| 30 | characterName: char.name, |
| 31 | cls: char.class, |
| 32 | nation: char.nation, |
| 33 | pts, |
| 34 | k, |
| 35 | d, |
| 36 | slot, |
| 37 | atk, |
| 38 | def, |
| 39 | heal, |
| 40 | submittedByOfficer, |
| 41 | }); |
| 42 | |
| 43 | const scoreEmoji = getEmoji("score") || "📊"; |
| 44 | const kdEmoji = getEmoji("kd") || "⚔️"; |
| 45 | const borrowNote = borrowedFrom ? ` *(borrowed from ${borrowedFrom})*` : ""; |
| 46 | const kdNote = k !== undefined && d !== undefined ? `\n${kdEmoji} ${k}/${d}` : ""; |
| 47 | const statsNote = [ |
| 48 | atk !== undefined ? `ATK: ${atk}` : null, |
| 49 | def !== undefined ? `DEF: ${def}` : null, |
| 50 | heal !== undefined ? `HEAL: ${heal}` : null, |
| 51 | ].filter(Boolean).join(" · "); |
| 52 | |
| 53 | const charDisplay = format.char(char); |
| 54 | return { |
| 55 | ok: true, |
| 56 | message: `✅ ${scoreEmoji} **${pts}** submitted for ${charDisplay}${borrowNote} (${slot}:00 TG)${kdNote}${statsNote ? `\n${statsNote}` : ""}`, |
| 57 | // message: `✅ ${scoreEmoji} **${pts}** submitted for ${charDisplay}${borrowNote} (${slot}:00 TG)${kdNote}${statsNote ? `\n${statsNote}` : ""}`, |
| 58 | }; |
| 59 | } |
| 60 | } |