@@ -2,76 +2,77 @@ import { type AppBskyFeedDefs, AppBskyFeedPost, RichText } from "@atproto/api";
22import type { BlueskyDiscordBot } from "../discord/client.ts" ;
33
44export const processPostText = ( post : AppBskyFeedDefs . PostView ) : string => {
5- if ( ! AppBskyFeedPost . isRecord ( post . record ) ) {
6- throw new Error ( "Post is not record" ) ;
7- }
5+ if ( ! AppBskyFeedPost . isRecord ( post . record ) ) {
6+ throw new Error ( "Post is not record" ) ;
7+ }
88
9- if ( ! post . record . facets || post . record . facets . length === 0 )
10- return post . record . text ;
9+ if ( ! post . record . facets || post . record . facets . length === 0 ) {
10+ return post . record . text ;
11+ }
1112
12- const rt = new RichText ( {
13- text : post . record . text ,
14- facets : post . record . facets ,
15- } ) ;
13+ const rt = new RichText ( {
14+ text : post . record . text ,
15+ facets : post . record . facets ,
16+ } ) ;
1617
17- let processedText = "" ;
18- for ( const segment of rt . segments ( ) ) {
19- if ( segment . isLink ( ) ) {
20- if ( segment . text === segment . link ?. uri ) {
21- processedText += segment . text ;
22- } else {
23- processedText += `[${ segment . text } ](${ segment . link ?. uri } )` ;
24- }
25- } else if ( segment . isMention ( ) ) {
26- processedText += `[${ segment . text } ](https://bsky.app/profile/${ segment . mention ?. did } )` ;
27- } else if ( segment . isTag ( ) ) {
28- processedText += `[${ segment . text } ](https://bsky.app/hashtag/${ segment . tag ?. tag } )` ;
29- } else {
30- processedText += segment . text ;
31- }
32- }
33- return processedText ;
18+ let processedText = "" ;
19+ for ( const segment of rt . segments ( ) ) {
20+ if ( segment . isLink ( ) ) {
21+ if ( segment . text === segment . link ?. uri ) {
22+ processedText += segment . text ;
23+ } else {
24+ processedText += `[${ segment . text } ](${ segment . link ?. uri } )` ;
25+ }
26+ } else if ( segment . isMention ( ) ) {
27+ processedText += `[${ segment . text } ](https://bsky.app/profile/${ segment . mention ?. did } )` ;
28+ } else if ( segment . isTag ( ) ) {
29+ processedText += `[${ segment . text } ](https://bsky.app/hashtag/${ segment . tag ?. tag } )` ;
30+ } else {
31+ processedText += segment . text ;
32+ }
33+ }
34+ return processedText ;
3435} ;
3536
3637export const getBlueskyPostLink = ( post : AppBskyFeedDefs . PostView ) : string => {
37- const uriParts = post . uri . split ( "/" ) ;
38- const handle = post . author . handle ;
39- const rkey = uriParts [ uriParts . length - 1 ] ;
38+ const uriParts = post . uri . split ( "/" ) ;
39+ const handle = post . author . handle ;
40+ const rkey = uriParts [ uriParts . length - 1 ] ;
4041
41- return `https://bsky.app/profile/${ handle } /post/${ rkey } ` ;
42+ return `https://bsky.app/profile/${ handle } /post/${ rkey } ` ;
4243} ;
4344
4445export const didOrHandleToBlueskyAccount = async (
45- didorhandle : string ,
46- botClient : BlueskyDiscordBot ,
46+ didorhandle : string ,
47+ botClient : BlueskyDiscordBot ,
4748) => {
48- if ( ! didorhandle ) throw new Error ( "No DID or handle provided." ) ;
49+ if ( ! didorhandle ) throw new Error ( "No DID or handle provided." ) ;
4950
50- let localDidOrHandle = didorhandle ;
51+ let localDidOrHandle = didorhandle ;
5152
52- const didRegex = / ^ d i d : p l c : [ a - z 0 - 9 ] { 24 } $ / ;
53- const handleRegex = / ^ @ ? [ a - z A - Z 0 - 9 . - ] + \. [ a - z A - Z ] { 2 , } $ / ;
53+ const didRegex = / ^ d i d : p l c : [ a - z 0 - 9 ] { 24 } $ / ;
54+ const handleRegex = / ^ @ ? [ a - z A - Z 0 - 9 . - ] + \. [ a - z A - Z ] { 2 , } $ / ;
5455
55- console . log ( `Got didorhandle: ${ didorhandle } ` ) ;
56+ console . log ( `Got didorhandle: ${ didorhandle } ` ) ;
5657
57- if ( didRegex . test ( localDidOrHandle ) ) {
58- console . log ( `didorhandle: "${ localDidOrHandle } " seems like a DID.` ) ;
59- } else if ( handleRegex . test ( didorhandle ) ) {
60- console . log ( `didorhandle: "${ didorhandle } " seems like a handle.` ) ;
61- if ( didorhandle . charAt ( 0 ) === "@" ) {
62- console . log ( "Cut @ off the start" ) ;
63- localDidOrHandle = didorhandle . substring ( 1 ) ;
64- } else {
65- localDidOrHandle = didorhandle ;
66- }
67- } else {
68- throw new Error ( "String isn't DID or handle" ) ;
69- }
58+ if ( didRegex . test ( localDidOrHandle ) ) {
59+ console . log ( `didorhandle: "${ localDidOrHandle } " seems like a DID.` ) ;
60+ } else if ( handleRegex . test ( didorhandle ) ) {
61+ console . log ( `didorhandle: "${ didorhandle } " seems like a handle.` ) ;
62+ if ( didorhandle . charAt ( 0 ) === "@" ) {
63+ console . log ( "Cut @ off the start" ) ;
64+ localDidOrHandle = didorhandle . substring ( 1 ) ;
65+ } else {
66+ localDidOrHandle = didorhandle ;
67+ }
68+ } else {
69+ throw new Error ( "String isn't DID or handle" ) ;
70+ }
7071
71- console . log ( "Finding Bluesky account..." ) ;
72- const { data } = await botClient . bskyAgent . getProfile ( {
73- actor : localDidOrHandle ,
74- } ) ;
72+ console . log ( "Finding Bluesky account..." ) ;
73+ const { data } = await botClient . bskyAgent . getProfile ( {
74+ actor : localDidOrHandle ,
75+ } ) ;
7576
76- return data ;
77+ return data ;
7778} ;
0 commit comments