Skip to content

Commit

Permalink
引用投稿に対応
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogyuchi committed Nov 10, 2023
1 parent 1686f49 commit 76d7019
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 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.replaceAll(">", "\\>")];
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, "> "),
);
}

Check warning on line 13 in src/createEmbeds.ts

View check run for this annotation

Codecov / codecov/patch

src/createEmbeds.ts#L7-L13

Added lines #L7 - L13 were not covered by tests
strings.push(`[<t:${tweet.created_timestamp}:R> ](${tweet.url})`); // モバイル版でタップする領域を確保するためにスペースが必要
return strings.join("\n\n");
};

export const createEmbeds = async (
content: string,
Expand Down Expand Up @@ -35,14 +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.replaceAll(">", "\\>")
+ `\n\n[<t:${tweet.created_timestamp}:R> ](${tweet.url})`, // モバイル版でタップする領域を確保するためにスペースが必要
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 76d7019

Please sign in to comment.