gistfile1.txt
· 1.7 KiB · Text
原始文件
function buildEmbed(state: PollState, options?: PollEmbedOptions): EmbedBuilder {
const yesByNation: Record<Nation, VoteEntry[]> = {
[Nation.Capella]: [],
[Nation.Procyon]: [],
};
const noVoters: VoteEntry[] = [];
const allMessages: { entry: VoteEntry; voteType: "yes" | "no" }[] = [];
const showNoInline = Config.get({ section: "poll", key: "showNoInNationField" });
for (const entry of state.yes.values()) {
const nation = entry.characterNation ?? Nation.Capella;
yesByNation[nation].push(entry);
allMessages.push({ entry, voteType: "yes" });
}
for (const entry of state.no.values()) {
noVoters.push(entry);
allMessages.push({ entry, voteType: "no" });
}
const capellaEmoji = Emoji.get("capella");
const procyonEmoji = Emoji.get("procyon");
const embed = new EmbedBuilder()
.setTitle(resolveTitle(state, yesByNation))
.setColor(resolveColor(state))
.addFields(
{
name: `${capellaEmoji} Capella (${yesByNation[Nation.Capella].length})`,
value: formatNationField(Nation.Capella, yesByNation[Nation.Capella], noVoters, showNoInline),
inline: false,
},
{ name: "\u200b", value: "\u200b", inline: false },
{
name: `${procyonEmoji} Procyon (${yesByNation[Nation.Procyon].length})`,
value: formatNationField(Nation.Procyon, yesByNation[Nation.Procyon], noVoters, showNoInline),
inline: false,
},
)
.setTimestamp();
const msgSection = formatMessages(allMessages);
if (msgSection) {
embed.addFields({ name: "\u200b", value: msgSection, inline: false });
}
embed.setFooter({ text: resolveFooter(state, noVoters.length, options?.overrideLockMsg) });
return embed;
}
| 1 | function buildEmbed(state: PollState, options?: PollEmbedOptions): EmbedBuilder { |
| 2 | const yesByNation: Record<Nation, VoteEntry[]> = { |
| 3 | [Nation.Capella]: [], |
| 4 | [Nation.Procyon]: [], |
| 5 | }; |
| 6 | const noVoters: VoteEntry[] = []; |
| 7 | const allMessages: { entry: VoteEntry; voteType: "yes" | "no" }[] = []; |
| 8 | const showNoInline = Config.get({ section: "poll", key: "showNoInNationField" }); |
| 9 | |
| 10 | for (const entry of state.yes.values()) { |
| 11 | const nation = entry.characterNation ?? Nation.Capella; |
| 12 | yesByNation[nation].push(entry); |
| 13 | allMessages.push({ entry, voteType: "yes" }); |
| 14 | } |
| 15 | for (const entry of state.no.values()) { |
| 16 | noVoters.push(entry); |
| 17 | allMessages.push({ entry, voteType: "no" }); |
| 18 | } |
| 19 | |
| 20 | const capellaEmoji = Emoji.get("capella"); |
| 21 | const procyonEmoji = Emoji.get("procyon"); |
| 22 | |
| 23 | const embed = new EmbedBuilder() |
| 24 | .setTitle(resolveTitle(state, yesByNation)) |
| 25 | .setColor(resolveColor(state)) |
| 26 | .addFields( |
| 27 | { |
| 28 | name: `${capellaEmoji} Capella (${yesByNation[Nation.Capella].length})`, |
| 29 | value: formatNationField(Nation.Capella, yesByNation[Nation.Capella], noVoters, showNoInline), |
| 30 | inline: false, |
| 31 | }, |
| 32 | { name: "\u200b", value: "\u200b", inline: false }, |
| 33 | { |
| 34 | name: `${procyonEmoji} Procyon (${yesByNation[Nation.Procyon].length})`, |
| 35 | value: formatNationField(Nation.Procyon, yesByNation[Nation.Procyon], noVoters, showNoInline), |
| 36 | inline: false, |
| 37 | }, |
| 38 | ) |
| 39 | .setTimestamp(); |
| 40 | |
| 41 | const msgSection = formatMessages(allMessages); |
| 42 | if (msgSection) { |
| 43 | embed.addFields({ name: "\u200b", value: msgSection, inline: false }); |
| 44 | } |
| 45 | |
| 46 | embed.setFooter({ text: resolveFooter(state, noVoters.length, options?.overrideLockMsg) }); |
| 47 | return embed; |
| 48 | } |