Dernière activité 1 month ago

nuno a révisé ce gist 1 month ago. Aller à la révision

1 file changed, 47 insertions

gistfile1.txt(fichier créé)

@@ -0,0 +1,47 @@
1 + if (baseEntry.characterName) {
2 + console.log(`[vote] voteId=${voteId} yes keys:`, [...state.yes.keys()], 'no keys:', [...state.no.keys()]);
3 + for (const [otherId, entry] of [...state.yes.entries(), ...state.no.entries()]) {
4 + if (otherId !== userId && entry.characterName === baseEntry.characterName) {
5 + // Check if this user is the owner of the character
6 + const borrowerKey = entry.borrowedFrom ? entry.userKey : null;
7 + const ownerKey = entry.borrowedFrom ?? entry.userKey;
8 + const isOwner = user.userKey === ownerKey;
9 + console.log(`[conflict] user.userKey=${user.userKey} entry.userKey=${entry.userKey} borrowedFrom=${entry.borrowedFrom} ownerKey=${ownerKey} isOwner=${isOwner}`);
10 +
11 + if (isOwner && baseEntry.userKey) {
12 + // Owner trying to reclaim — show conflict embed
13 + const allChars = getCharacters(baseEntry.userKey);
14 + const borrowedChar = allChars.find((c) => c.name === baseEntry.characterName);
15 + if (borrowedChar) {
16 + await showConflictEmbed(interaction, baseEntry.userKey, entry.userKey, borrowedChar, allChars);
17 + return;
18 + }
19 + }
20 +
21 + await pollReplyAndDelete(interaction,
22 + `❌ **${baseEntry.characterName}** is already in the poll by another player.`
23 + );
24 + return;
25 + }
26 + }
27 + }
28 +
29 + if (votedYes) {
30 + const previousNo = state.no.get(voteId);
31 + state.no.delete(voteId);
32 + state.yes.set(voteId, {
33 + ...baseEntry,
34 + votedAt: now,
35 + previousNoAt: previousNo?.votedAt,
36 + publicMessage: publicMsg ?? undefined,
37 + });
38 + } else {
39 + const previousYes = state.yes.get(voteId);
40 + state.yes.delete(voteId);
41 + state.no.set(voteId, {
42 + ...baseEntry,
43 + votedAt: now,
44 + previousYesAt: previousYes?.votedAt,
45 + publicMessage: publicMsg ?? undefined,
46 + });
47 + }
Plus récent Plus ancien