|
@@ -15,7 +15,7 @@ import { SocksProxyAgent } from 'socks-proxy-agent';
|
|
|
|
|
|
import { getLogger } from './loggers';
|
|
|
import QQBot from './koishi';
|
|
|
-import { BigNumOps } from './utils';
|
|
|
+import { Arr, BigNumOps, chainPromises } from './utils';
|
|
|
import Webshot from './webshot';
|
|
|
|
|
|
const parseLink = (link: string): {userName?: string, storyId?: string} => {
|
|
@@ -350,15 +350,18 @@ export default class {
|
|
|
return idToUserMap[id] = user as UserFeedResponseUser;
|
|
|
});
|
|
|
}))
|
|
|
- .then(() => {
|
|
|
- logger.debug(`pulling stories for users: ${Object.values(idToUserMap).map(user => user.username)}`);
|
|
|
- return this.client.feed.reelsMedia({userIds: Object.keys(idToUserMap)}).items()
|
|
|
- .then(storyItems => storyItems.forEach(item => {
|
|
|
- if (!(item.pk in this.cache[idToUserMap[item.user.pk].username].stories)) {
|
|
|
- this.cache[idToUserMap[item.user.pk].username].stories[item.pk] = item;
|
|
|
- }
|
|
|
- }));
|
|
|
- })
|
|
|
+ .then(() => chainPromises(
|
|
|
+ Arr.chunk(Arr.shuffle(Object.keys(idToUserMap)), 20).map(userIds => () => {
|
|
|
+ logger.info(`pulling stories for users: ${userIds.map(id => idToUserMap[id as unknown as number].username)}`);
|
|
|
+ return this.client.feed.reelsMedia({userIds}).items()
|
|
|
+ .then(storyItems => storyItems.forEach(item => {
|
|
|
+ if (!(item.pk in this.cache[idToUserMap[item.user.pk].username].stories)) {
|
|
|
+ this.cache[idToUserMap[item.user.pk].username].stories[item.pk] = item;
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ }),
|
|
|
+ (lp1, lp2) => () => lp1().then(() => promisify(setTimeout)(this.workInterval * 1000).then(lp2))
|
|
|
+ ))
|
|
|
.catch((error: IgClientError & Partial<RequestError>) => {
|
|
|
if (error instanceof IgNetworkError) {
|
|
|
logger.warn(`error on fetching stories for all: ${JSON.stringify(error.cause)}`);
|