summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-09-13 16:12:15 -0700
committerFuwn <[email protected]>2025-09-13 16:12:15 -0700
commite057df4be5fce92b52a44961a10dfc36c4f1189c (patch)
tree33b0b18b7f291bf849056bd49b125d4f68d42ff9
parentfeat: Colour role distribution command (diff)
downloadumabotdiscord-e057df4be5fce92b52a44961a10dfc36c4f1189c.tar.xz
umabotdiscord-e057df4be5fce92b52a44961a10dfc36c4f1189c.zip
refactor(server): Move role distribution embed to embeds module
-rw-r--r--src/discord/embeds.ts23
-rw-r--r--src/server.ts24
2 files changed, 29 insertions, 18 deletions
diff --git a/src/discord/embeds.ts b/src/discord/embeds.ts
index db23f80..2eeb800 100644
--- a/src/discord/embeds.ts
+++ b/src/discord/embeds.ts
@@ -89,6 +89,29 @@ export const createPostEmbed = (post: RedditPost): DiscordEmbed => {
return embed;
};
+export const createRoleDistributionEmbed = (
+ roleDistribution: Array<{ name: string; count: number }>,
+): DiscordEmbed => {
+ const totalMembers = roleDistribution.reduce(
+ (sum, role) => sum + role.count,
+ 0,
+ );
+
+ return {
+ title: "🎨 Colour Role Distribution",
+ description: `Total members with colour roles: **${totalMembers}**`,
+ color: 0x5865f2,
+ fields: roleDistribution.map((role) => ({
+ name: role.name,
+ value: `${role.count} member${role.count !== 1 ? "s" : ""}`,
+ inline: true,
+ })),
+ footer: {
+ text: "Sorted by member count (highest to lowest)",
+ },
+ };
+};
+
export const createComplaintEmbed = (
complaintContent: string,
complainant: { username: string; id: string; avatar?: string },
diff --git a/src/server.ts b/src/server.ts
index ce7e8c7..2252ea7 100644
--- a/src/server.ts
+++ b/src/server.ts
@@ -16,7 +16,11 @@ import {
} from "./reddit.ts";
import type { TimePeriod } from "./discord/types.ts";
import type { Environment, DiscordEmbed } from "./discord/interfaces.ts";
-import { createPostEmbed, createComplaintEmbed } from "./discord/embeds.ts";
+import {
+ createPostEmbed,
+ createComplaintEmbed,
+ createRoleDistributionEmbed,
+} from "./discord/embeds.ts";
import { JSONResponse } from "./discord/responses.ts";
import { verifyDiscordRequest } from "./discord/verification.ts";
@@ -432,23 +436,7 @@ router.post("/", async (request: Request, environment: Environment) => {
},
});
- const totalMembers = roleDistribution.reduce(
- (sum, role) => sum + role.count,
- 0,
- );
- const embed: DiscordEmbed = {
- title: "🎨 Colour Role Distribution",
- description: `Total members with colour roles: **${totalMembers}**`,
- color: 0x5865F2,
- fields: roleDistribution.map((role) => ({
- name: role.name,
- value: `${role.count} member${role.count !== 1 ? "s" : ""}`,
- inline: true,
- })),
- footer: {
- text: "Sorted by member count (highest to lowest)",
- },
- };
+ const embed = createRoleDistributionEmbed(roleDistribution);
return new JSONResponse({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,