summaryrefslogtreecommitdiff
path: root/src/discord
diff options
context:
space:
mode:
Diffstat (limited to 'src/discord')
-rw-r--r--src/discord/commands.ts46
-rw-r--r--src/discord/embeds.ts42
-rw-r--r--src/discord/responses.ts4
-rw-r--r--src/discord/types.ts2
-rw-r--r--src/discord/verification.ts8
5 files changed, 51 insertions, 51 deletions
diff --git a/src/discord/commands.ts b/src/discord/commands.ts
index dec18e6..b4436d6 100644
--- a/src/discord/commands.ts
+++ b/src/discord/commands.ts
@@ -1,57 +1,57 @@
-import type { DiscordCommand } from './interfaces.ts';
+import type { DiscordCommand } from "./interfaces.ts";
export type { DiscordCommand };
export const HOT_COMMAND: DiscordCommand = {
- name: 'hot',
- description: 'Fetch a random hot post from r/okbuddyumamusume',
+ name: "hot",
+ description: "Fetch a random hot post from r/okbuddyumamusume",
};
export const ROLEPLAY_COMMAND: DiscordCommand = {
- name: 'roleplay',
- description: 'Fetch a random hot roleplay post from r/okbuddyumamusume',
+ name: "roleplay",
+ description: "Fetch a random hot roleplay post from r/okbuddyumamusume",
};
export const NSFW_COMMAND: DiscordCommand = {
- name: 'nsfw',
+ name: "nsfw",
description:
- 'Fetch a random NSFW post from r/okbuddyumamusume (NSFW channels only)',
+ "Fetch a random NSFW post from r/okbuddyumamusume (NSFW channels only)",
};
export const TOP_COMMAND: DiscordCommand = {
- name: 'top',
+ name: "top",
description:
- 'Fetch a random top post from r/okbuddyumamusume (defaults to today)',
+ "Fetch a random top post from r/okbuddyumamusume (defaults to today)",
options: [
{
type: 3,
- name: 'time',
- description: 'Time period for top posts (defaults to today)',
+ name: "time",
+ description: "Time period for top posts (defaults to today)",
required: false,
choices: [
{
- name: 'Now',
- value: 'hour',
+ name: "Now",
+ value: "hour",
},
{
- name: 'Today',
- value: 'day',
+ name: "Today",
+ value: "day",
},
{
- name: 'This Week',
- value: 'week',
+ name: "This Week",
+ value: "week",
},
{
- name: 'This Month',
- value: 'month',
+ name: "This Month",
+ value: "month",
},
{
- name: 'This Year',
- value: 'year',
+ name: "This Year",
+ value: "year",
},
{
- name: 'All Time',
- value: 'all',
+ name: "All Time",
+ value: "all",
},
],
},
diff --git a/src/discord/embeds.ts b/src/discord/embeds.ts
index 833c831..1fad102 100644
--- a/src/discord/embeds.ts
+++ b/src/discord/embeds.ts
@@ -1,16 +1,16 @@
-import type { DiscordEmbed } from './interfaces.ts';
-import type { RedditPost } from '../reddit.ts';
+import type { DiscordEmbed } from "./interfaces.ts";
+import type { RedditPost } from "../reddit.ts";
const decodeHtmlEntities = (str: string): string => {
return str
- .replace(/&/g, '&')
- .replace(/&lt;/g, '<')
- .replace(/&gt;/g, '>')
+ .replace(/&amp;/g, "&")
+ .replace(/&lt;/g, "<")
+ .replace(/&gt;/g, ">")
.replace(/&quot;/g, '"')
.replace(/&#x27;/g, "'")
- .replace(/&#x2F;/g, '/')
- .replace(/&#x60;/g, '`')
- .replace(/&#x3D;/g, '=');
+ .replace(/&#x2F;/g, "/")
+ .replace(/&#x60;/g, "`")
+ .replace(/&#x3D;/g, "=");
};
export const createPostEmbed = (post: RedditPost): DiscordEmbed => {
@@ -19,10 +19,10 @@ export const createPostEmbed = (post: RedditPost): DiscordEmbed => {
post.secure_media?.reddit_video?.fallback_url ||
post.url;
- let description = post.selftext || '';
+ let description = post.selftext || "";
if (description.length > 1000)
- description = description.substring(0, 997).trim() + ' ...';
+ description = description.substring(0, 997).trim() + " ...";
const embed: DiscordEmbed = {
title: post.title,
@@ -35,30 +35,30 @@ export const createPostEmbed = (post: RedditPost): DiscordEmbed => {
},
fields: [
{
- name: 'Score',
+ name: "Score",
value: `${post.score} ⬆️`,
inline: true,
},
{
- name: 'Comments',
+ name: "Comments",
value: `${post.num_comments} 💬`,
inline: true,
},
],
timestamp: new Date(post.created_utc * 1000).toISOString(),
footer: {
- text: 'r/okbuddyumamusume',
+ text: "r/okbuddyumamusume",
},
};
if (mediaUrl)
if (post.media?.reddit_video || post.secure_media?.reddit_video) {
- if (!description) description = '';
+ if (!description) description = "";
description +=
- '\n\n📹 **This post contains a video** - [Click here to view](' +
+ "\n\n📹 **This post contains a video** - [Click here to view](" +
mediaUrl +
- ')';
+ ")";
embed.description = description;
if (post.preview?.images?.[0]?.source?.url) {
@@ -66,21 +66,21 @@ export const createPostEmbed = (post: RedditPost): DiscordEmbed => {
post.preview.images[0].source.url,
);
- console.log('Using preview image:', decodedURL);
+ console.log("Using preview image:", decodedURL);
embed.image = { url: decodedURL };
} else if (
post.thumbnail &&
- post.thumbnail !== 'self' &&
- post.thumbnail !== 'default'
+ post.thumbnail !== "self" &&
+ post.thumbnail !== "default"
) {
const decodedThumbnail = decodeHtmlEntities(post.thumbnail);
- console.log('Using thumbnail:', decodedThumbnail);
+ console.log("Using thumbnail:", decodedThumbnail);
embed.image = { url: decodedThumbnail };
} else {
- console.log('No suitable thumbnail found for video post');
+ console.log("No suitable thumbnail found for video post");
}
} else {
embed.image = { url: mediaUrl };
diff --git a/src/discord/responses.ts b/src/discord/responses.ts
index da72967..4dcc777 100644
--- a/src/discord/responses.ts
+++ b/src/discord/responses.ts
@@ -1,4 +1,4 @@
-import type { DiscordResponse } from './interfaces.ts';
+import type { DiscordResponse } from "./interfaces.ts";
export class JSONResponse extends Response {
constructor(body: DiscordResponse | { error: string }, init?: ResponseInit) {
@@ -6,7 +6,7 @@ export class JSONResponse extends Response {
init = init || {
headers: {
- 'content-type': 'application/json;charset=UTF-8',
+ "content-type": "application/json;charset=UTF-8",
},
};
diff --git a/src/discord/types.ts b/src/discord/types.ts
index 9b1d6c5..4f6e85e 100644
--- a/src/discord/types.ts
+++ b/src/discord/types.ts
@@ -1 +1 @@
-export type TimePeriod = 'hour' | 'day' | 'week' | 'month' | 'year' | 'all';
+export type TimePeriod = "hour" | "day" | "week" | "month" | "year" | "all";
diff --git a/src/discord/verification.ts b/src/discord/verification.ts
index e4679db..89d26db 100644
--- a/src/discord/verification.ts
+++ b/src/discord/verification.ts
@@ -1,12 +1,12 @@
-import { verifyKey } from 'discord-interactions';
-import type { Environment, DiscordInteraction } from './interfaces.ts';
+import { verifyKey } from "discord-interactions";
+import type { Environment, DiscordInteraction } from "./interfaces.ts";
export const verifyDiscordRequest = async (
request: Request,
environment: Environment,
): Promise<{ isValid: boolean; interaction?: DiscordInteraction }> => {
- const signature = request.headers.get('x-signature-ed25519');
- const timestamp = request.headers.get('x-signature-timestamp');
+ const signature = request.headers.get("x-signature-ed25519");
+ const timestamp = request.headers.get("x-signature-timestamp");
const body = await request.text();
const isValidRequest =
signature &&