gistfile1.txt
· 2.6 KiB · Text
Surowy
// Click tracking
if (!clickCounts.has(voteId)) clickCounts.set(voteId, { yes: 0, no: 0 });
const clicks = clickCounts.get(voteId)!;
if (votedYes && clicks.yes >= LOCK_AT) return;
if (!votedYes && clicks.no >= LOCK_AT) return;
// Ignore same vote
if (votedYes && state.yes.has(voteId)) return;
if (!votedYes && state.no.has(voteId)) return;
if (votedYes) clicks.yes += 1;
else clicks.no += 1;
const clickCount = votedYes ? clicks.yes : clicks.no;
// Resolve messages — officer override takes priority
const publicMsg = getPublicOverride(voteId, votedYes ? "yes" : "no")
?? resolveMessage("public", votedYes ? "yes" : "no", clickCount, lookupUsername, user.serverNickname, user.globalNickname);
const ephemeralMsg = getEphemeralOverride(voteId, votedYes ? "yes" : "no")
?? resolveMessage("ephemeral", votedYes ? "yes" : "no", clickCount, lookupUsername, user.serverNickname, user.globalNickname);
const baseEntry = createVoteEntry(voteId, member, user.userKey, lookupUsername);
// Check if character is already in use by another voter
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 !== voteId && otherId !== userId && entry.characterName === baseEntry.characterName) {
// Check if this user is the owner of the character
const ownerKey = entry.borrowedFrom ?? entry.userKey;
const isOwner = user.userKey === ownerKey ||
// Also check if voter is the actual owner via characters.json
(() => {
const chars = getCharacters(user.userKey ?? "");
return chars.some((c) => c.name === entry.characterName);
})();
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;
}
| 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 | } |