Skip to content

Commit

Permalink
feat: discord changelog endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dromzeh committed Sep 1, 2024
1 parent 8f8d1b1 commit 97506cc
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { index } from "@/routes/index";
import { getGameId } from "@/routes/games/get-game-id";
import { getAsset } from "@/routes/games/get-game-category";
import { getGames } from "@/routes/games/list-games";
import { getChangelog } from "@/routes/discord/changelog";

const router = AutoRouter();

Expand All @@ -17,6 +18,7 @@ router
.get("/game/:gameId/:asset", errorHandler(getAsset))
.get("/discord/contributors", errorHandler(getContributors))
.get("/discord/members", errorHandler(getMembers))
.get("/discord/changelog", errorHandler(getChangelog))
.all("*", (): Response => {
return new Response(
JSON.stringify({
Expand Down
75 changes: 75 additions & 0 deletions src/lib/types/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,78 @@ export interface GuildMember {
avatar: string;
};
}

export interface DiscordAPIResponse {
success: boolean;
status: string;
path: string;
messages: DiscordMessage[];
}
export interface DiscordMessage {
type: number;
content: string;
mentions: DiscordUser[];
mention_roles: string[];
attachments: any[];
embeds: any[];
timestamp: string;
edited_timestamp: string | null;
flags: number;
components: any[];
id: string;
channel_id: string;
author: DiscordUser;
pinned: boolean;
mention_everyone: boolean;
tts: boolean;
reactions?: DiscordReaction[];
message_reference?: MessageReference;
referenced_message?: DiscordMessage;
position?: number;
}

export interface DiscordUser {
id: string;
username: string;
avatar: string;
discriminator: string;
public_flags: number;
flags: number;
banner: string | null;
accent_color: number | null;
global_name: string | null;
avatar_decoration_data: AvatarDecorationData | null;
banner_color: string | null;
clan: any | null;
}

export interface AvatarDecorationData {
asset: string;
sku_id: string;
expires_at: string | null;
}

export interface DiscordReaction {
emoji: {
id: string | null;
name: string;
animated?: boolean;
};
count: number;
count_details: {
burst: number;
normal: number;
};
burst_colors: any[];
me_burst: boolean;
burst_me: boolean;
me: boolean;
burst_count: number;
}

export interface MessageReference {
type: number;
channel_id: string;
message_id: string;
guild_id: string;
}
29 changes: 29 additions & 0 deletions src/routes/discord/changelog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { responseHeaders } from "@/lib/responseHeaders";
import { DiscordMessage } from "@/lib/types/discord";

export const getChangelog = async (
request: Request,
env: Env,
ctx: ExecutionContext
): Promise<Response> => {
const CHANNEL_ID = "1112527121848483920";
const API_ENDPOINT = `https://discord.com/api/v10/channels/${CHANNEL_ID}/messages?limit=15`;

const res = await fetch(API_ENDPOINT, {
headers: {
Authorization: `Bot ${env.DISCORD_TOKEN}`,
},
});

const messages = (await res.json()) as DiscordMessage[];

return new Response(
JSON.stringify({
success: true,
status: "ok",
path: `/discord/changelog`,
messages,
}),
responseHeaders
);
};

0 comments on commit 97506cc

Please sign in to comment.