File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import type { Guild } from 'discord.js' ;
2+ import { getPublicChannels } from './channel.js' ;
3+
4+ const PER_CHANNEL_CACHE_LIMIT = 100 ;
5+ export const cachedChannelsMap = new Set < string > ( ) ;
6+
7+ export const fetchAndCachePublicChannelsMessages = async ( guild : Guild , force = false ) => {
8+ let cachedChannels = 0 ;
9+ const channels = getPublicChannels ( guild ) ;
10+
11+ await Promise . all (
12+ channels . map ( async ( channel ) => {
13+ if ( force || ! cachedChannelsMap . has ( channel . id ) ) {
14+ const messages = await channel . messages . fetch ( { limit : PER_CHANNEL_CACHE_LIMIT } ) ;
15+ console . log (
16+ `Fetched and cached ${ messages . size } messages from channel ${ channel . name } (${ channel . id } )`
17+ ) ;
18+ cachedChannelsMap . add ( channel . id ) ;
19+ cachedChannels ++ ;
20+ }
21+ } )
22+ ) ;
23+ return { cachedChannels, totalChannels : channels . size } ;
24+ } ;
You can’t perform that action at this time.
0 commit comments