Naposledy aktivní 1 month ago

nuno revidoval tento gist 1 month ago. Přejít na revizi

1 file changed, 55 insertions

gistfile1.txt(vytvořil soubor)

@@ -0,0 +1,55 @@
1 + // Click tracking
2 + if (!clickCounts.has(voteId)) clickCounts.set(voteId, { yes: 0, no: 0 });
3 + const clicks = clickCounts.get(voteId)!;
4 +
5 + if (votedYes && clicks.yes >= LOCK_AT) return;
6 + if (!votedYes && clicks.no >= LOCK_AT) return;
7 +
8 + // Ignore same vote
9 + if (votedYes && state.yes.has(voteId)) return;
10 + if (!votedYes && state.no.has(voteId)) return;
11 +
12 + if (votedYes) clicks.yes += 1;
13 + else clicks.no += 1;
14 +
15 + const clickCount = votedYes ? clicks.yes : clicks.no;
16 +
17 + // Resolve messages — officer override takes priority
18 + const publicMsg = getPublicOverride(voteId, votedYes ? "yes" : "no")
19 + ?? resolveMessage("public", votedYes ? "yes" : "no", clickCount, lookupUsername, user.serverNickname, user.globalNickname);
20 +
21 + const ephemeralMsg = getEphemeralOverride(voteId, votedYes ? "yes" : "no")
22 + ?? resolveMessage("ephemeral", votedYes ? "yes" : "no", clickCount, lookupUsername, user.serverNickname, user.globalNickname);
23 +
24 + const baseEntry = createVoteEntry(voteId, member, user.userKey, lookupUsername);
25 +
26 + // Check if character is already in use by another voter
27 + if (baseEntry.characterName) {
28 + console.log(`[vote] voteId=${voteId} yes keys:`, [...state.yes.keys()], 'no keys:', [...state.no.keys()]);
29 + for (const [otherId, entry] of [...state.yes.entries(), ...state.no.entries()]) {
30 + if (otherId !== voteId && otherId !== userId && entry.characterName === baseEntry.characterName) {
31 + // Check if this user is the owner of the character
32 + const ownerKey = entry.borrowedFrom ?? entry.userKey;
33 + const isOwner = user.userKey === ownerKey ||
34 + // Also check if voter is the actual owner via characters.json
35 + (() => {
36 + const chars = getCharacters(user.userKey ?? "");
37 + return chars.some((c) => c.name === entry.characterName);
38 + })();
39 + console.log(`[conflict] user.userKey=${user.userKey} entry.userKey=${entry.userKey} borrowedFrom=${entry.borrowedFrom} ownerKey=${ownerKey} isOwner=${isOwner}`);
40 +
41 + if (isOwner && baseEntry.userKey) {
42 + // Owner trying to reclaim — show conflict embed
43 + const allChars = getCharacters(baseEntry.userKey);
44 + const borrowedChar = allChars.find((c) => c.name === baseEntry.characterName);
45 + if (borrowedChar) {
46 + await showConflictEmbed(interaction, baseEntry.userKey, entry.userKey, borrowedChar, allChars);
47 + return;
48 + }
49 + }
50 +
51 + await pollReplyAndDelete(interaction,
52 + `❌ **${baseEntry.characterName}** is already in the poll by another player.`
53 + );
54 + return;
55 + }
Novější Starší