最終更新 3 weeks ago

nuno revised this gist 3 weeks ago. Go to revision

1 file changed, 48 insertions

gistfile1.txt(file created)

@@ -0,0 +1,48 @@
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 + }
Newer Older