url-customizerでtweetを展開する際に絵文字が入っているとバグる
色んなものを展開しようとこのサイトのポストで試していたら再現
> 🚨 New Desktop Feature: Channel Status
> Let the rest of the server know what you're up to in voice so people can join in. <3 Enjoy!
> 
最後の行に Y
が入っている
これ例としてよくないな...

<
が展開できていないのも含んでいる
後で調べる
期待する展開
> 🚨 New Desktop Feature: Channel Status
> Let the rest of the server know what you're up to in voice so people can join in. <3 Enjoy!
> 
原因
tweet.text
はツイートの文章(短縮リンクやハッシュタグを含む)
text.slice()
で要素ごとに分割しているが絵文字が含まれると正しく取り出せない
jsconst unicodeSubstring `` = (str, start, end) => {
const reg = new RegExp(`^[\\s\\S]{${start}}([\\s\\S]{0,${end - start}})`, 'u')
return str.match(reg)?.[1]
}
unicodeSubstring(tweet.text,indices[0] - offset,tweet.text.length)
誤
before
: "🚨 New Desktop Feature: Channel Status\n\nLet the rest of the server know what you're up to in voice so people can join in. <3 Enjoy! "
text
: 'Y'
正
before
: "🚨 New Desktop Feature: Channel Status\n\nLet the rest of the server know what you're up to in voice so people can join in. <3 Enjoy!"
text
: ''
あっ………………………………………………………………………………………………………………………………………………………

こっちのほうがスマートでGOOD

こんな文字は「しらんがな」です
> 🚨 New Desktop Feature: Channel Status
> Let the rest of the server know what you're up to in voice so people can join in. <3 Enjoy!
> 
オマケ: <
について
便利そうなので取り込みます

旧
> &quot;"""クォーテーション&amp;"&"アンパサンド&lt;"<"小なり&gt;">"大なり&nbsp;" "空白&copy;"©"コピーライト
新
> """"クォーテーション&"&"アンパサンド<"<"小なり>">"大なり " "空白©"©"コピーライト
テスト
>

動画が表示できなくなってる...
js...tweet.entities.media?.map?.((media) => ({
type: "media",
indices: media.indices,
media: tweet.mediaDetails?.flatMap?.((detail) => detail.url === media.url ? [{
type: detail.type,
//url: new URL(detail.video_info?.variants?.sort?.((a, b) => b.bitrate - a.bitrate)?.[0].url ?? detail.media_url_https)
url: new URL(detail.video_info?.variants.filter(variant => variant.bitrate)?.sort?.((a, b) => b.bitrate - a.bitrate)?.[0].url ?? detail.media_url_https)
}] : []) ?? []
})) ?? []
これも入れました

bitrateが0のやつ見つけたけど眠いので今日はやらない

variants.filter(variant => variant.content_type.startsWith("video"))
でいけそう

オマケ2
メディアがあったときに入る謎の空行
これはメディアの後にテキストがあるのかどうか判定するときにミスっているぽい
なんかミスってる気がするので訂正
なんかうまいこと単体テスト入れてPR書いてくれるとうれし~

自分はもうおやすみする時間なので
おやすも

snapshot testは
$ deno test --allow-read --allow-write -- -u
で更新できる
生成されたsnapshot通りになるかどうかは
$ deno test --allow-read
で確認できる
修正助かります!
