@@ -108,6 +108,22 @@ export default class PinArchive extends BotComponent {
108108 }
109109 }
110110
111+ async fetch_all_pins ( channel : Discord . GuildTextBasedChannel ) {
112+ const current_pins = new Map < string , Discord . Message < true > > ( ) ;
113+ let before : Date | undefined = undefined ;
114+ while ( true ) {
115+ const { items, hasMore } = await channel . messages . fetchPins ( before ? { before } : undefined ) ;
116+ for ( const pin of items ) {
117+ current_pins . set ( pin . message . id , pin . message ) ;
118+ }
119+ if ( ! hasMore || items . length === 0 ) {
120+ break ;
121+ }
122+ before = items [ items . length - 1 ] . pinnedAt ;
123+ }
124+ return current_pins ;
125+ }
126+
111127 async update_for_channel ( channel : Discord . TextBasedChannel ) {
112128 if (
113129 channel . isDMBased ( ) ||
@@ -116,13 +132,13 @@ export default class PinArchive extends BotComponent {
116132 ) {
117133 return ;
118134 }
119- const current_pins = await channel . messages . fetchPinned ( ) ;
135+ const current_pins = await this . fetch_all_pins ( channel ) ;
120136 const database_current_pins = await this . database . pins
121137 . find ( { channel : channel . id , current_pin : true } )
122138 . toArray ( ) ;
123139 // two things to handle: new pins and pins that are now no longer pins
124140 // ensure current pins are marked as such
125- for ( const [ _ , message ] of current_pins ) {
141+ for ( const [ , message ] of current_pins ) {
126142 const res = await this . database . pins . updateOne (
127143 { channel : channel . id , message : message . id } ,
128144 { $set : { current_pin : true } } ,
0 commit comments