最終更新 2 weeks ago

修正履歴 b267eff673ad297c85608da03c225d83641c7cb6

gistfile1.txt Raw
1export 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}