Skip to content

Commit

Permalink
引用投稿に対応
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogyuchi committed Nov 9, 2023
1 parent a8157b0 commit ce7212b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/createEmbeds.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import type { APIEmbed } from "@discordjs/core";
import type { APITweetResponse } from "./types.ts";
import type { APITweet, APITweetResponse } from "./types.ts";

const createDescriptin = (tweet: APITweet): string => {
const strings: string[] = [tweet.text];
if (tweet.quote !== undefined) {
strings.push(
[
`[${tweet.quote.author.name}(@${tweet.quote.author.screen_name}) <t:${tweet.quote.created_timestamp}:R>](${tweet.quote.url})`,
tweet.quote.text,
].join("\n").replaceAll(/^/gm,'> '),
);
}
strings.push(`<t:${tweet.created_timestamp}:R>`);
return strings.join("\n\n");
};

export const createEmbeds = async (
content: string,
Expand Down Expand Up @@ -35,13 +49,13 @@ export const createEmbeds = async (
return [];
}

if (tweet.poll ?? tweet.media?.videos ?? tweet.quote) {
if (tweet.poll ?? tweet.media?.videos) {
fixupxLinks.push(`[_ ︎ _](https://fixupx.com/status/${tweet.id})`);
return []; // 動画や投票、引用のある場合はEmbedを作成しない
}

const embed: APIEmbed = {
description: tweet.text + `\n\n<t:${tweet.created_timestamp}:R>`,
description: createDescriptin(tweet),
color: 0x000,
footer: {
text: `𝕏 - 返信 ${tweet.replies} · リポスト ${tweet.retweets} · いいね ${tweet.likes}`,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface APITweetResponse {
}

// The container of all the information for a Tweet
interface APITweet {
export interface APITweet {
id: string;
url: string;
text: string;
Expand Down

0 comments on commit ce7212b

Please sign in to comment.