Skip to content

Commit 041c625

Browse files
committed
feat(DiscordHook): add hook to fetch single channel by id
1 parent 6d5f13c commit 041c625

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

constants/Discord.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const BOT_COMMANDS = {
1616
channels: "guilds/{guildId}/channels",
1717
member: "guilds/{guildId}/members",
1818
roles: "guilds/{guildId}/roles",
19+
channel: "channels/{channelId}",
1920
// doc: https://discord.com/developers/docs/resources/message#get-channel-messages
2021
messages: "channels/{channelId}/messages?limit={limit}",
2122
};

models/DiscordTypes.ts

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export interface DiscordGuild {
2626
approximate_presence_count: number;
2727
}
2828

29+
export interface DiscordChannelMetadata {
30+
archived: boolean;
31+
create_timestamp?: string;
32+
}
33+
2934
export interface DiscordChannel {
3035
id: string;
3136
name: string;
@@ -47,6 +52,7 @@ export interface DiscordChannel {
4752
member_count?: number;
4853
message_count?: number;
4954
total_message_sent?: number;
55+
thread_metadata?: DiscordChannelMetadata;
5056
}
5157

5258
export interface DiscordRole {

utils/hooks/DiscordHooks.ts

+13
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ export function useFetchDiscordChannels(
9090
);
9191
}
9292

93+
export function useDiscordChannel(
94+
channelId: string | undefined,
95+
shouldFetch: boolean = true
96+
) {
97+
const command = BOT_COMMANDS.channel.replace("{channelId}", channelId || "");
98+
return useSWR<DiscordChannel, string>(
99+
shouldFetch && channelId
100+
? `${DISCORD_PROXY_BOT_URL}?command=${command}`
101+
: null,
102+
jsonFetcher()
103+
);
104+
}
105+
93106
export function useIsBotMemberOfGuild(
94107
guildId: string | undefined,
95108
shouldFetch: boolean = true

0 commit comments

Comments
 (0)