Refactor Discord channel resource management and update imports

- Consolidated channel type definitions by moving them to discord-channel-types.ts for better organization.
- Removed redundant DASHBOARD_CHANNEL_TYPES and updated exports to streamline channel handling in the application.
- Enhanced type safety by utilizing the ChannelKind type in the discord-channel-select component.
This commit is contained in:
TheOnlyMace
2026-07-22 21:25:58 +02:00
parent ed2ea23e87
commit 042f68e777
3 changed files with 34 additions and 30 deletions

View File

@@ -1,28 +1,11 @@
import type { DiscordChannelOption, DiscordRoleOption } from '@nexumi/shared';
import { DASHBOARD_CHANNEL_TYPES } from './discord-channel-types';
import { env } from './env';
import { redis } from './redis';
const DISCORD_API_BASE = 'https://discord.com/api/v10';
const CACHE_TTL_SECONDS = 60;
/** Channel types useful in the dashboard (text, voice, category, forum, …). */
const DASHBOARD_CHANNEL_TYPES = new Set([
0, // GUILD_TEXT
2, // GUILD_VOICE
4, // GUILD_CATEGORY
5, // GUILD_ANNOUNCEMENT
13, // GUILD_STAGE_VOICE
15, // GUILD_FORUM
16 // GUILD_MEDIA
]);
export const CHANNEL_TYPES = {
text: [0, 5, 15, 16],
voice: [2, 13],
category: [4],
messageable: [0, 5, 15, 16]
} as const;
async function discordBotFetch<T>(path: string): Promise<T> {
const response = await fetch(`${DISCORD_API_BASE}${path}`, {
headers: { Authorization: `Bot ${env.BOT_TOKEN}` },
@@ -94,12 +77,4 @@ export async function listGuildRolesForDashboard(guildId: string): Promise<Disco
return options;
}
export function channelPrefix(type: number): string {
if (type === 2 || type === 13) {
return '🔊 ';
}
if (type === 4) {
return '📁 ';
}
return '#';
}
export { CHANNEL_TYPES, channelPrefix, type ChannelKind } from './discord-channel-types';