Skip to content

Commit 97506cc

Browse files
committed
feat: discord changelog endpoint
1 parent 8f8d1b1 commit 97506cc

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

src/handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { index } from "@/routes/index";
77
import { getGameId } from "@/routes/games/get-game-id";
88
import { getAsset } from "@/routes/games/get-game-category";
99
import { getGames } from "@/routes/games/list-games";
10+
import { getChangelog } from "@/routes/discord/changelog";
1011

1112
const router = AutoRouter();
1213

@@ -17,6 +18,7 @@ router
1718
.get("/game/:gameId/:asset", errorHandler(getAsset))
1819
.get("/discord/contributors", errorHandler(getContributors))
1920
.get("/discord/members", errorHandler(getMembers))
21+
.get("/discord/changelog", errorHandler(getChangelog))
2022
.all("*", (): Response => {
2123
return new Response(
2224
JSON.stringify({

src/lib/types/discord.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,78 @@ export interface GuildMember {
1515
avatar: string;
1616
};
1717
}
18+
19+
export interface DiscordAPIResponse {
20+
success: boolean;
21+
status: string;
22+
path: string;
23+
messages: DiscordMessage[];
24+
}
25+
export interface DiscordMessage {
26+
type: number;
27+
content: string;
28+
mentions: DiscordUser[];
29+
mention_roles: string[];
30+
attachments: any[];
31+
embeds: any[];
32+
timestamp: string;
33+
edited_timestamp: string | null;
34+
flags: number;
35+
components: any[];
36+
id: string;
37+
channel_id: string;
38+
author: DiscordUser;
39+
pinned: boolean;
40+
mention_everyone: boolean;
41+
tts: boolean;
42+
reactions?: DiscordReaction[];
43+
message_reference?: MessageReference;
44+
referenced_message?: DiscordMessage;
45+
position?: number;
46+
}
47+
48+
export interface DiscordUser {
49+
id: string;
50+
username: string;
51+
avatar: string;
52+
discriminator: string;
53+
public_flags: number;
54+
flags: number;
55+
banner: string | null;
56+
accent_color: number | null;
57+
global_name: string | null;
58+
avatar_decoration_data: AvatarDecorationData | null;
59+
banner_color: string | null;
60+
clan: any | null;
61+
}
62+
63+
export interface AvatarDecorationData {
64+
asset: string;
65+
sku_id: string;
66+
expires_at: string | null;
67+
}
68+
69+
export interface DiscordReaction {
70+
emoji: {
71+
id: string | null;
72+
name: string;
73+
animated?: boolean;
74+
};
75+
count: number;
76+
count_details: {
77+
burst: number;
78+
normal: number;
79+
};
80+
burst_colors: any[];
81+
me_burst: boolean;
82+
burst_me: boolean;
83+
me: boolean;
84+
burst_count: number;
85+
}
86+
87+
export interface MessageReference {
88+
type: number;
89+
channel_id: string;
90+
message_id: string;
91+
guild_id: string;
92+
}

src/routes/discord/changelog.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { responseHeaders } from "@/lib/responseHeaders";
2+
import { DiscordMessage } from "@/lib/types/discord";
3+
4+
export const getChangelog = async (
5+
request: Request,
6+
env: Env,
7+
ctx: ExecutionContext
8+
): Promise<Response> => {
9+
const CHANNEL_ID = "1112527121848483920";
10+
const API_ENDPOINT = `https://discord.com/api/v10/channels/${CHANNEL_ID}/messages?limit=15`;
11+
12+
const res = await fetch(API_ENDPOINT, {
13+
headers: {
14+
Authorization: `Bot ${env.DISCORD_TOKEN}`,
15+
},
16+
});
17+
18+
const messages = (await res.json()) as DiscordMessage[];
19+
20+
return new Response(
21+
JSON.stringify({
22+
success: true,
23+
status: "ok",
24+
path: `/discord/changelog`,
25+
messages,
26+
}),
27+
responseHeaders
28+
);
29+
};

0 commit comments

Comments
 (0)