gistfile1.txt
· 1.8 KiB · Text
原始文件
if (baseEntry.characterName) {
console.log(`[vote] voteId=${voteId} yes keys:`, [...state.yes.keys()], 'no keys:', [...state.no.keys()]);
for (const [otherId, entry] of [...state.yes.entries(), ...state.no.entries()]) {
if (otherId !== userId && entry.characterName === baseEntry.characterName) {
// Check if this user is the owner of the character
const borrowerKey = entry.borrowedFrom ? entry.userKey : null;
const ownerKey = entry.borrowedFrom ?? entry.userKey;
const isOwner = user.userKey === ownerKey;
console.log(`[conflict] user.userKey=${user.userKey} entry.userKey=${entry.userKey} borrowedFrom=${entry.borrowedFrom} ownerKey=${ownerKey} isOwner=${isOwner}`);
if (isOwner && baseEntry.userKey) {
// Owner trying to reclaim — show conflict embed
const allChars = getCharacters(baseEntry.userKey);
const borrowedChar = allChars.find((c) => c.name === baseEntry.characterName);
if (borrowedChar) {
await showConflictEmbed(interaction, baseEntry.userKey, entry.userKey, borrowedChar, allChars);
return;
}
}
await pollReplyAndDelete(interaction,
`❌ **${baseEntry.characterName}** is already in the poll by another player.`
);
return;
}
}
}
if (votedYes) {
const previousNo = state.no.get(voteId);
state.no.delete(voteId);
state.yes.set(voteId, {
...baseEntry,
votedAt: now,
previousNoAt: previousNo?.votedAt,
publicMessage: publicMsg ?? undefined,
});
} else {
const previousYes = state.yes.get(voteId);
state.yes.delete(voteId);
state.no.set(voteId, {
...baseEntry,
votedAt: now,
previousYesAt: previousYes?.votedAt,
publicMessage: publicMsg ?? undefined,
});
}
| 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 | } |