@@ -15,7 +15,7 @@ const { CODA_API_TOKEN } = process.env
1515const IGNORED_CHANNELS = new Set < string > ( [ ] )
1616
1717// Cache for storing API responses to reduce rate limit usage
18- const cache = new Map < string , { data : any ; timestamp : number } > ( )
18+ const cache = new Map < string , { data : unknown ; timestamp : number } > ( )
1919const CACHE_TTL = 5 * 60 * 1000 // 5 minutes
2020
2121// Track processed messages to avoid duplicates if original message is edited
@@ -37,9 +37,9 @@ const sentEmbeds = new Map<string, Map<string, Message>>()
3737
3838// URL pattern matching for different Coda link types
3939const CODA_URL_PATTERNS = {
40- document : / h t t p s : \/ \/ c o d a \. i o \/ d \/ ( [ ^ \/ \ ?# ] + ) (?: \/ ( [ ^ \/ \ ?# _ ] + ) ) ? / g,
41- section : / h t t p s : \/ \/ c o d a \. i o \/ d \/ ( [ ^ \/ \ ?# ] + ) \/ _ s u ( [ ^ \/ \ ?# ] + ) / g,
42- table : / h t t p s : \/ \/ c o d a \. i o \/ d \/ ( [ ^ \/ \ ?# ] + ) \/ _ t ( [ ^ \/ \ ?# ] + ) / g,
40+ document : / h t t p s : \/ \/ c o d a \. i o \/ d \/ ( [ ^ / ? # ] + ) (?: \/ ( [ ^ / ? # _ ] + ) ) ? / g,
41+ section : / h t t p s : \/ \/ c o d a \. i o \/ d \/ ( [ ^ / ? # ] + ) \/ _ s u ( [ ^ / ? # ] + ) / g,
42+ table : / h t t p s : \/ \/ c o d a \. i o \/ d \/ ( [ ^ / ? # ] + ) \/ _ t ( [ ^ / ? # ] + ) / g,
4343}
4444
4545type CodaLinkData = {
@@ -132,7 +132,7 @@ class CodaApiClient {
132132 return null
133133 }
134134
135- private setCache ( key : string , data : any ) : void {
135+ private setCache ( key : string , data : unknown ) : void {
136136 cache . set ( key , { data, timestamp : Date . now ( ) } )
137137 }
138138
@@ -166,13 +166,18 @@ class CodaApiClient {
166166 }
167167 }
168168
169- async getSection ( docId : string , sectionId : string ) : Promise < CodaSection | null > {
169+ async getSection (
170+ docId : string ,
171+ sectionId : string ,
172+ ) : Promise < CodaSection | null > {
170173 const cacheKey = this . getCacheKey ( `docs/${ docId } /sections/${ sectionId } ` )
171174 const cached = this . getFromCache < CodaSection > ( cacheKey )
172175 if ( cached ) return cached
173176
174177 try {
175- const response = await this . client . get ( `/docs/${ docId } /sections/${ sectionId } ` )
178+ const response = await this . client . get (
179+ `/docs/${ docId } /sections/${ sectionId } ` ,
180+ )
176181 const data = response . data as CodaSection
177182 this . setCache ( cacheKey , data )
178183 return data
@@ -191,15 +196,15 @@ class CodaApiClient {
191196 this . client . get ( `/docs/${ docId } /tables/${ tableId } ` ) ,
192197 this . client . get ( `/docs/${ docId } /tables/${ tableId } /columns` ) ,
193198 ] )
194-
199+
195200 const tableData = tableResponse . data
196201 const columnsData = columnsResponse . data
197-
202+
198203 const data : CodaTable = {
199204 ...tableData ,
200205 columns : columnsData . items || [ ] ,
201206 }
202-
207+
203208 this . setCache ( cacheKey , data )
204209 return data
205210 } catch ( _error ) {
@@ -354,7 +359,10 @@ async function createCodaEmbed(
354359 }
355360 } else if ( linkData . type === "section" && linkData . sectionId ) {
356361 // Section-specific embed
357- const section = await codaClient . getSection ( linkData . docId , linkData . sectionId )
362+ const section = await codaClient . getSection (
363+ linkData . docId ,
364+ linkData . sectionId ,
365+ )
358366 if ( ! section ) return null
359367
360368 embed
@@ -528,10 +536,7 @@ async function processCodaEmbeds(
528536 } )
529537}
530538
531- export default async function codaEmbeds (
532- discordClient : Client ,
533- robot : Robot ,
534- ) {
539+ export default async function codaEmbeds ( discordClient : Client , robot : Robot ) {
535540 if ( ! CODA_API_TOKEN ) {
536541 robot . logger . warn (
537542 "CODA_API_TOKEN not found. Coda embed processing will be disabled." ,
@@ -576,24 +581,33 @@ export default async function codaEmbeds(
576581 }
577582
578583 const messageEmbeds = sentEmbeds . get ( newMessage . id ) ?? new Map ( )
579-
584+
580585 // Parse old and new Coda links
581586 const oldLinks = oldMessage . content ? parseCodaUrls ( oldMessage . content ) : [ ]
582587 const newLinks = parseCodaUrls ( newMessage . content )
583-
588+
584589 const oldKeys = new Set (
585- oldLinks . map ( ( link ) => `${ link . docId } -${ link . pageId || "" } -${ link . sectionId || "" } -${ link . tableId || "" } ` )
590+ oldLinks . map (
591+ ( link ) =>
592+ `${ link . docId } -${ link . pageId || "" } -${ link . sectionId || "" } -${ link . tableId || "" } ` ,
593+ ) ,
586594 )
587595 const newKeys = new Set (
588- newLinks . map ( ( link ) => `${ link . docId } -${ link . pageId || "" } -${ link . sectionId || "" } -${ link . tableId || "" } ` )
596+ newLinks . map (
597+ ( link ) =>
598+ `${ link . docId } -${ link . pageId || "" } -${ link . sectionId || "" } -${ link . tableId || "" } ` ,
599+ ) ,
589600 )
590601
591602 // Remove embeds for deleted links
592603 oldKeys . forEach ( ( key ) => {
593604 if ( ! newKeys . has ( key ) && messageEmbeds . has ( key ) ) {
594- messageEmbeds . get ( key ) ?. delete ( ) . catch ( ( error ) =>
595- robot . logger . error ( `Failed to delete Coda embed: ${ error } ` )
596- )
605+ messageEmbeds
606+ . get ( key )
607+ ?. delete ( )
608+ . catch ( ( error ) =>
609+ robot . logger . error ( `Failed to delete Coda embed: ${ error } ` ) ,
610+ )
597611 messageEmbeds . delete ( key )
598612 }
599613 } )
@@ -622,7 +636,9 @@ export default async function codaEmbeds(
622636 Array . from ( embedMessages . values ( ) ) . map ( ( embedMessage ) =>
623637 embedMessage . delete ( ) . catch ( ( error : unknown ) => {
624638 if ( error instanceof Error ) {
625- robot . logger . error ( `Failed to delete Coda embed: ${ error . message } ` )
639+ robot . logger . error (
640+ `Failed to delete Coda embed: ${ error . message } ` ,
641+ )
626642 } else {
627643 robot . logger . error ( `Unknown error deleting Coda embed: ${ error } ` )
628644 }
@@ -635,4 +651,4 @@ export default async function codaEmbeds(
635651 } )
636652
637653 robot . logger . info ( "✅ Coda embed processing enabled" )
638- }
654+ }
0 commit comments