diff options
Diffstat (limited to 'src/server.ts')
| -rw-r--r-- | src/server.ts | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/src/server.ts b/src/server.ts index 5f43763..bf3acf2 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,37 +1,37 @@ -import { AutoRouter } from 'itty-router'; -import { InteractionResponseType, InteractionType } from 'discord-interactions'; +import { AutoRouter } from "itty-router"; +import { InteractionResponseType, InteractionType } from "discord-interactions"; import { HOT_COMMAND, ROLEPLAY_COMMAND, NSFW_COMMAND, TOP_COMMAND, -} from './discord/commands.ts'; +} from "./discord/commands.ts"; import { getCutePost, getRoleplayPost, getNSFWPost, getTopPost, -} from './reddit.ts'; -import type { TimePeriod } from './discord/types.ts'; -import type { Environment } from './discord/interfaces.ts'; -import { createPostEmbed } from './discord/embeds.ts'; -import { JSONResponse } from './discord/responses.ts'; -import { verifyDiscordRequest } from './discord/verification.ts'; +} from "./reddit.ts"; +import type { TimePeriod } from "./discord/types.ts"; +import type { Environment } from "./discord/interfaces.ts"; +import { createPostEmbed } from "./discord/embeds.ts"; +import { JSONResponse } from "./discord/responses.ts"; +import { verifyDiscordRequest } from "./discord/verification.ts"; const router = AutoRouter(); -router.get('/', (_request: Request, environment: Environment) => { +router.get("/", (_request: Request, environment: Environment) => { return new Response(`👋 ${environment.DISCORD_APPLICATION_ID}`); }); -router.post('/', async (request: Request, environment: Environment) => { +router.post("/", async (request: Request, environment: Environment) => { const { isValid, interaction } = await server.verifyDiscordRequest( request, environment, ); if (!isValid || !interaction) - return new Response('Bad request signature.', { status: 401 }); + return new Response("Bad request signature.", { status: 401 }); if (interaction.type === InteractionType.PING) return new JSONResponse({ @@ -52,12 +52,12 @@ router.post('/', async (request: Request, environment: Environment) => { }, }); } catch (error) { - console.error('Error in hot command:', error); + console.error("Error in hot command:", error); return new JSONResponse({ type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, data: { - content: '❌ No posts found. Try again later!', + content: "❌ No posts found. Try again later!", flags: 64, }, }); @@ -76,12 +76,12 @@ router.post('/', async (request: Request, environment: Environment) => { }, }); } catch (error) { - console.error('Error in roleplay command:', error); + console.error("Error in roleplay command:", error); return new JSONResponse({ type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, data: { - content: '❌ No roleplay posts found. Try again later!', + content: "❌ No roleplay posts found. Try again later!", flags: 64, }, }); @@ -93,7 +93,7 @@ router.post('/', async (request: Request, environment: Environment) => { return new JSONResponse({ type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, data: { - content: '❌ This command can only be used in NSFW channels.', + content: "❌ This command can only be used in NSFW channels.", flags: 64, }, }); @@ -110,12 +110,12 @@ router.post('/', async (request: Request, environment: Environment) => { }, }); } catch (error) { - console.error('Error in NSFW command:', error); + console.error("Error in NSFW command:", error); return new JSONResponse({ type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, data: { - content: '❌ No NSFW posts found. Try again later!', + content: "❌ No NSFW posts found. Try again later!", flags: 64, }, }); @@ -125,7 +125,7 @@ router.post('/', async (request: Request, environment: Environment) => { case TOP_COMMAND.name.toLowerCase(): { try { const time = - (interaction.data.options?.[0]?.value as TimePeriod) || 'day'; + (interaction.data.options?.[0]?.value as TimePeriod) || "day"; const post = await getTopPost(time); const embed = createPostEmbed(post); @@ -136,12 +136,12 @@ router.post('/', async (request: Request, environment: Environment) => { }, }); } catch (error) { - console.error('Error in top command:', error); + console.error("Error in top command:", error); return new JSONResponse({ type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE, data: { - content: '❌ No top posts found. Try again later!', + content: "❌ No top posts found. Try again later!", flags: 64, }, }); @@ -149,16 +149,16 @@ router.post('/', async (request: Request, environment: Environment) => { } default: - return new JSONResponse({ error: 'Unknown Type' }, { status: 400 }); + return new JSONResponse({ error: "Unknown Type" }, { status: 400 }); } } - console.error('Unknown Type'); + console.error("Unknown Type"); - return new JSONResponse({ error: 'Unknown Type' }, { status: 400 }); + return new JSONResponse({ error: "Unknown Type" }, { status: 400 }); }); -router.all('*', () => new Response('Not Found.', { status: 404 })); +router.all("*", () => new Response("Not Found.", { status: 404 })); const server = { verifyDiscordRequest, |