gistfile1.txt
· 1.4 KiB · Text
Raw
export async function showActiveCharSwitching(interaction: ButtonInteraction): Promise<void> {
const userId = interaction.user.id;
const member = interaction.guild!.members.cache.get(userId)
?? await interaction.guild!.members.fetch(userId);
const user = await resolveUser(member);
const impersonating = getImpersonation(userId);
const voteId = impersonating ? `impersonated:${impersonating}` : userId;
const clicks = clickCounts.get(voteId)!;
const votedYes = interaction.customId === "tg_yes";
const clickCount = votedYes ? clicks.yes : clicks.no;
const locked = clickCount >= LOCK_AT;
// Yes vote companion — show active char + switch buttons
if (votedYes && user.userKey && !locked) {
const { char, borrowedFrom } = getEffectiveCharacter(user.userKey);
if (char) {
const starEmoji = process.env.ACTIVE_CHAR_EMOJI || "⭐";
const borrowNote = borrowedFrom ? ` 🔗` : "";
const buttons = buildCharSelectButtons(user.userKey, {
customIdPrefix: `companion_switch:${user.userKey}`,
excludeCharName: char.name,
appendToCustomId: ":yes",
});
if (buttons.length > 0) {
await interaction.followUp({
content: `${starEmoji} ${format.char(char)}${borrowNote}`,
components: buttons,
ephemeral: true,
});
}
}
}
}
| 1 | export async function showActiveCharSwitching(interaction: ButtonInteraction): Promise<void> { |
| 2 | const userId = interaction.user.id; |
| 3 | const member = interaction.guild!.members.cache.get(userId) |
| 4 | ?? await interaction.guild!.members.fetch(userId); |
| 5 | const user = await resolveUser(member); |
| 6 | |
| 7 | const impersonating = getImpersonation(userId); |
| 8 | const voteId = impersonating ? `impersonated:${impersonating}` : userId; |
| 9 | const clicks = clickCounts.get(voteId)!; |
| 10 | |
| 11 | const votedYes = interaction.customId === "tg_yes"; |
| 12 | const clickCount = votedYes ? clicks.yes : clicks.no; |
| 13 | |
| 14 | const locked = clickCount >= LOCK_AT; |
| 15 | |
| 16 | // Yes vote companion — show active char + switch buttons |
| 17 | if (votedYes && user.userKey && !locked) { |
| 18 | const { char, borrowedFrom } = getEffectiveCharacter(user.userKey); |
| 19 | if (char) { |
| 20 | const starEmoji = process.env.ACTIVE_CHAR_EMOJI || "⭐"; |
| 21 | const borrowNote = borrowedFrom ? ` 🔗` : ""; |
| 22 | const buttons = buildCharSelectButtons(user.userKey, { |
| 23 | customIdPrefix: `companion_switch:${user.userKey}`, |
| 24 | excludeCharName: char.name, |
| 25 | appendToCustomId: ":yes", |
| 26 | }); |
| 27 | if (buttons.length > 0) { |
| 28 | await interaction.followUp({ |
| 29 | content: `${starEmoji} ${format.char(char)}${borrowNote}`, |
| 30 | components: buttons, |
| 31 | ephemeral: true, |
| 32 | }); |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | } |