|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
});
|
|
|
};
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
-exports.sendAllStories = exports.ScreenNameNormalizer = exports.SessionManager = exports.parseLink = exports.linkBuilder = void 0;
|
|
|
+exports.sendAllStories = exports.sendStory = exports.ScreenNameNormalizer = exports.SessionManager = exports.parseLink = exports.linkBuilder = void 0;
|
|
|
const crypto = require("crypto");
|
|
|
const fs = require("fs");
|
|
|
const http = require("http");
|
|
@@ -140,7 +140,11 @@ class ScreenNameNormalizer {
|
|
|
}
|
|
|
exports.ScreenNameNormalizer = ScreenNameNormalizer;
|
|
|
ScreenNameNormalizer.normalize = (username) => `${username.toLowerCase().replace(/^@/, '')}:`;
|
|
|
-let sendAllStories = (segmentId, receiver, startIndex, count) => {
|
|
|
+let sendStory = (username, storyId, receiver) => {
|
|
|
+ throw Error();
|
|
|
+};
|
|
|
+exports.sendStory = sendStory;
|
|
|
+let sendAllStories = (username, receiver, startIndex, count) => {
|
|
|
throw Error();
|
|
|
};
|
|
|
exports.sendAllStories = sendAllStories;
|
|
@@ -381,14 +385,9 @@ class default_1 {
|
|
|
this.webshotDelay = opt.webshotDelay;
|
|
|
this.mode = opt.mode;
|
|
|
this.wsUrl = opt.wsUrl;
|
|
|
- ScreenNameNormalizer._queryUser = this.queryUser;
|
|
|
- exports.sendAllStories = (rawUserName, receiver, startIndex = 0, count = 10) => {
|
|
|
- if (startIndex < 0)
|
|
|
- return this.bot.sendTo(receiver, '跳过数量参数值应为非负整数。');
|
|
|
- if (count < 1)
|
|
|
- return this.bot.sendTo(receiver, '最大查看数量参数值应为正整数。');
|
|
|
- const sender = this.sendStories(`instagram stories for ${rawUserName}`, receiver);
|
|
|
- this.queryUser(rawUserName)
|
|
|
+ const workNow = (config) => {
|
|
|
+ const { action, retryAction, reply, rawUserName } = config;
|
|
|
+ return this.queryUser(rawUserName)
|
|
|
.then(userNameId => {
|
|
|
var _a, _b;
|
|
|
const [userName, userId] = userNameId.split(':');
|
|
@@ -401,41 +400,70 @@ class default_1 {
|
|
|
.filter(item => !(item.pk in this.cache[userName].stories))
|
|
|
.map(item => this.webshot([Object.assign(Object.assign({}, item), { user: this.cache[userName].user })], (msgs, text, author) => this.cache[userName].stories[item.pk] = { pk: item.pk, msgs, text, author, original: item }, this.webshotDelay))).then(() => userName).finally(() => this.cache[userName].updated = new Date()));
|
|
|
})
|
|
|
- .then(userName => {
|
|
|
- const storyItems = Object.values(this.cache[userName].stories)
|
|
|
- .sort((i1, i2) => -utils_1.BigNumOps.compare(i2.pk, i1.pk));
|
|
|
- if (storyItems.length === 0)
|
|
|
- return this.bot.sendTo(receiver, `当前用户 (@${userName}) 没有可用的 Instagram 限时动态。`);
|
|
|
- if (startIndex + 1 > storyItems.length)
|
|
|
- return this.bot.sendTo(receiver, '跳过数量到达或超过当前用户可用的限时动态数量。');
|
|
|
- const endIndex = Math.min(storyItems.length, startIndex + count);
|
|
|
- const sendRangeText = `${startIndex + 1}${endIndex - startIndex > 1 ? `-${endIndex}` : ''}`;
|
|
|
- return this.workOnMedia(storyItems.slice(startIndex, endIndex), sender)
|
|
|
- .then(() => this.bot.sendTo(receiver, `已显示当前用户 ${storyItems.length} 条可用限时动态中的第 ${sendRangeText} 条。`));
|
|
|
- })
|
|
|
+ .then(action)
|
|
|
.catch((error) => {
|
|
|
if (error instanceof instagram_private_api_1.IgExactUserNotFoundError) {
|
|
|
- this.bot.sendTo(receiver, `找不到用户 ${rawUserName.replace(/^@?(.*)$/, '@$1')}。`);
|
|
|
+ reply(`找不到用户 ${rawUserName.replace(/^@?(.*)$/, '@$1')}。`);
|
|
|
}
|
|
|
if (error instanceof instagram_private_api_1.IgNetworkError) {
|
|
|
if (error.cause.message === "Unexpected '<'") {
|
|
|
logger.warn('login required, logging in again...');
|
|
|
- return this.session.login().then(() => exports.sendAllStories(rawUserName, receiver, startIndex, count));
|
|
|
+ return this.session.login().then(retryAction);
|
|
|
}
|
|
|
logger.warn(`error while fetching stories for ${rawUserName}: ${JSON.stringify(error.cause)}`);
|
|
|
- this.bot.sendTo(receiver, `获取 Stories 时出现错误:原因: ${error.cause}`);
|
|
|
+ reply(`获取 Stories 时出现错误:原因: ${error.cause}`);
|
|
|
}
|
|
|
else if (error instanceof instagram_private_api_1.IgLoginRequiredError || error instanceof instagram_private_api_1.IgCookieNotFoundError) {
|
|
|
logger.warn('login required, logging in again...');
|
|
|
- this.bot.sendTo(receiver, '等待登陆中,稍后会处理请求,请稍候……');
|
|
|
- this.session.login().then(() => exports.sendAllStories(rawUserName, receiver, startIndex, count));
|
|
|
+ reply('等待登陆中,稍后会处理请求,请稍候……');
|
|
|
+ this.session.login().then(retryAction);
|
|
|
}
|
|
|
else {
|
|
|
logger.error(`unhandled error while fetching stories for ${rawUserName}: ${error}`);
|
|
|
- this.bot.sendTo(receiver, `获取 Stories 时发生未知错误: ${error}`);
|
|
|
+ reply(`获取 Stories 时发生未知错误: ${error}`);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
+ ScreenNameNormalizer._queryUser = this.queryUser;
|
|
|
+ exports.sendStory = (rawUserName, storyId, receiver) => {
|
|
|
+ const reply = msg => this.bot.sendTo(receiver, msg);
|
|
|
+ const sender = this.sendStories(`instagram stories for ${rawUserName}`, receiver);
|
|
|
+ workNow({
|
|
|
+ rawUserName,
|
|
|
+ action: userName => {
|
|
|
+ if (!(storyId in this.cache[userName].stories))
|
|
|
+ return reply('此动态不存在或已过期。');
|
|
|
+ return this.workOnMedia([this.cache[userName].stories[storyId]], sender);
|
|
|
+ },
|
|
|
+ reply,
|
|
|
+ retryAction: () => exports.sendStory(rawUserName, storyId, receiver),
|
|
|
+ });
|
|
|
+ };
|
|
|
+ exports.sendAllStories = (rawUserName, receiver, startIndex = 0, count = 10) => {
|
|
|
+ const reply = msg => this.bot.sendTo(receiver, msg);
|
|
|
+ if (startIndex < 0)
|
|
|
+ return reply('跳过数量参数值应为非负整数。');
|
|
|
+ if (count < 1)
|
|
|
+ return reply('最大查看数量参数值应为正整数。');
|
|
|
+ const sender = this.sendStories(`instagram stories for ${rawUserName}`, receiver);
|
|
|
+ workNow({
|
|
|
+ rawUserName,
|
|
|
+ action: userName => {
|
|
|
+ const storyItems = Object.values(this.cache[userName].stories)
|
|
|
+ .sort((i1, i2) => -utils_1.BigNumOps.compare(i2.pk, i1.pk));
|
|
|
+ if (storyItems.length === 0)
|
|
|
+ return reply(`当前用户 (@${userName}) 没有可用的 Instagram 限时动态。`);
|
|
|
+ if (startIndex + 1 > storyItems.length)
|
|
|
+ return reply('跳过数量到达或超过当前用户可用的限时动态数量。');
|
|
|
+ const endIndex = Math.min(storyItems.length, startIndex + count);
|
|
|
+ const sendRangeText = `${startIndex + 1}${endIndex - startIndex > 1 ? `-${endIndex}` : ''}`;
|
|
|
+ return this.workOnMedia(storyItems.slice(startIndex, endIndex), sender)
|
|
|
+ .then(() => reply(`已显示当前用户 ${storyItems.length} 条可用限时动态中的第 ${sendRangeText} 条。`));
|
|
|
+ },
|
|
|
+ reply,
|
|
|
+ retryAction: () => exports.sendAllStories(rawUserName, receiver, startIndex, count)
|
|
|
+ });
|
|
|
+ };
|
|
|
}
|
|
|
get pullOrders() {
|
|
|
const arr = [];
|