twitter.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. "use strict";
  2. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  4. return new (P || (P = Promise))(function (resolve, reject) {
  5. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  6. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  7. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  8. step((generator = generator.apply(thisArg, _arguments || [])).next());
  9. });
  10. };
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. exports.sendTimeline = exports.sendTweet = exports.ScreenNameNormalizer = exports.linkBuilder = exports.parseLink = void 0;
  13. const fs = require("fs");
  14. const path = require("path");
  15. const Twitter = require("twitter-api-v2");
  16. const loggers_1 = require("./loggers");
  17. const koishi_1 = require("./koishi");
  18. const redis_1 = require("./redis");
  19. const utils_1 = require("./utils");
  20. const webshot_1 = require("./webshot");
  21. const parseLink = (link) => {
  22. let match = /twitter.com\/([^\/?#]+)\/lists\/([^\/?#]+)/.exec(link) ||
  23. /^([^\/?#]+)\/([^\/?#]+)$/.exec(link);
  24. if (match)
  25. return [match[1], `/lists/${match[2]}`];
  26. match =
  27. /twitter.com\/([^\/?#]+)\/status\/(\d+)/.exec(link);
  28. if (match)
  29. return [match[1], `/status/${match[2]}`];
  30. match =
  31. /twitter.com\/([^\/?#]+)/.exec(link) ||
  32. /^([^\/?#]+)$/.exec(link);
  33. if (match)
  34. return [match[1]];
  35. return;
  36. };
  37. exports.parseLink = parseLink;
  38. const linkBuilder = (userName, more = '') => {
  39. if (!userName)
  40. return;
  41. return `https://twitter.com/${userName}${more}`;
  42. };
  43. exports.linkBuilder = linkBuilder;
  44. class ScreenNameNormalizer {
  45. static normalizeLive(username) {
  46. return __awaiter(this, void 0, void 0, function* () {
  47. username = this.normalize(username);
  48. if (this._queryUser) {
  49. return yield this._queryUser(username)
  50. .then(userNameId => userNameId.split(':')[0])
  51. .catch((err) => {
  52. if (err.title === 'Not Found Error') {
  53. logger.warn(`error looking up user: ${showApiError(err)}`);
  54. return username;
  55. }
  56. return null;
  57. });
  58. }
  59. return username;
  60. });
  61. }
  62. }
  63. exports.ScreenNameNormalizer = ScreenNameNormalizer;
  64. ScreenNameNormalizer.normalize = (username) => username.toLowerCase().replace(/^@/, '');
  65. let sendTweet = (id, receiver, forceRefresh) => {
  66. throw Error();
  67. };
  68. exports.sendTweet = sendTweet;
  69. let sendTimeline = (conf, receiver) => {
  70. throw Error();
  71. };
  72. exports.sendTimeline = sendTimeline;
  73. const TWITTER_EPOCH = 1288834974657;
  74. const snowflake = (epoch) => Number.isNaN(epoch) ? undefined :
  75. utils_1.BigNumOps.lShift(String(epoch - 1 - TWITTER_EPOCH), 22);
  76. const logger = (0, loggers_1.getLogger)('twitter');
  77. const maxTrials = 3;
  78. const retryInterval = 1500;
  79. const ordinal = (n) => {
  80. switch ((Math.trunc(n / 10) % 10 === 1) ? 0 : n % 10) {
  81. case 1:
  82. return `${n}st`;
  83. case 2:
  84. return `${n}nd`;
  85. case 3:
  86. return `${n}rd`;
  87. default:
  88. return `${n}th`;
  89. }
  90. };
  91. const retryOnError = (doWork, onRetry) => new Promise(resolve => {
  92. const retry = (reason, count) => {
  93. setTimeout(() => {
  94. let terminate = false;
  95. onRetry(reason, count, defaultValue => { terminate = true; resolve(defaultValue); });
  96. if (!terminate)
  97. doWork().then(resolve).catch(error => retry(error, count + 1));
  98. }, retryInterval);
  99. };
  100. doWork().then(resolve).catch(error => retry(error, 1));
  101. });
  102. const showApiError = (err) => err.errors && err.errors[0].message || err.detail || err.stack || JSON.stringify(err);
  103. const toMutableConst = (o) => {
  104. return o;
  105. };
  106. const v2SingleParams = toMutableConst({
  107. expansions: ['attachments.media_keys', 'author_id', 'referenced_tweets.id'],
  108. 'tweet.fields': ['created_at', 'entities'],
  109. 'media.fields': ['url', 'variants', 'alt_text'],
  110. 'user.fields': ['id', 'name', 'username']
  111. });
  112. ;
  113. class default_1 {
  114. constructor(opt) {
  115. this.launch = () => {
  116. this.client.appLogin().then(client => {
  117. this.client = client.readOnly;
  118. this.webshot = new webshot_1.default(this.wsUrl, this.mode, () => setTimeout(this.work, this.workInterval * 1000));
  119. });
  120. };
  121. this.queryUser = (username) => {
  122. const thread = this.lock.threads[(0, exports.linkBuilder)(username)];
  123. if (thread && thread.id)
  124. return Promise.resolve(`${username}:${thread.id}`);
  125. return this.client.v2.userByUsername(username).then(({ data: { username, id }, errors }) => {
  126. if (errors && errors.length > 0)
  127. throw errors[0];
  128. if (thread)
  129. thread.id = id;
  130. return `${username}:${id}`;
  131. });
  132. };
  133. this.queryTimelineReverse = (conf) => {
  134. if (!conf.since)
  135. return this.queryTimeline(conf);
  136. const count = conf.count;
  137. const maxID = conf.until;
  138. conf.count = undefined;
  139. const until = () => utils_1.BigNumOps.min(maxID, utils_1.BigNumOps.plus(conf.since, String(7 * 24 * 3600 * 1000 * Math.pow(2, 22))));
  140. conf.until = until();
  141. const promise = (tweets) => this.queryTimeline(conf).then(newTweets => {
  142. tweets = newTweets.concat(tweets);
  143. conf.since = conf.until;
  144. conf.until = until();
  145. if (tweets.length >= count ||
  146. utils_1.BigNumOps.compare(conf.since, conf.until) >= 0) {
  147. return tweets.slice(-count);
  148. }
  149. return promise(tweets);
  150. });
  151. return promise([]);
  152. };
  153. this.queryTimeline = ({ username, count, since, until, noreps, norts }) => {
  154. username = username.replace(/^@?(.*)$/, '@$1');
  155. return this.queryUser(username.slice(1)).then(userNameId => {
  156. const getMore = (lastTweets = []) => {
  157. logger.info(`querying timeline of ${username} with config: ${JSON.stringify(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (count && { count })), (since && { since })), (until && { until })), (noreps && { noreps })), (norts && { norts })))}`);
  158. return this.get('userTimeline', userNameId.split(':')[1], Object.assign(Object.assign({ expansions: ['attachments.media_keys', 'author_id'], 'tweet.fields': ['created_at'], exclude: [
  159. ...(noreps !== null && noreps !== void 0 ? noreps : true) ? ['replies'] : [],
  160. ...(norts !== null && norts !== void 0 ? norts : false) ? ['retweets'] : [],
  161. ], max_results: Math.min(Math.max(count || 0, 20), 100) }, (since && { since_id: since })), (until && { until_id: until }))).then(newTweets => {
  162. logger.info(`timeline query of ${username} yielded ${newTweets.length} new tweets`);
  163. const tweets = lastTweets.concat(newTweets.filter(({ data }) => (data.attachments || {}).media_keys));
  164. if (tweets.length < count) {
  165. until = utils_1.BigNumOps.plus('-1', newTweets.slice(-1)[0].data.id);
  166. logger.info(`starting next query at offset ${until}...`);
  167. return getMore(tweets);
  168. }
  169. logger.info(`timeline query of ${username} finished successfully, ${tweets.length} media tweets have been fetched`);
  170. return tweets.slice(0, count);
  171. });
  172. };
  173. return getMore();
  174. });
  175. };
  176. this.workOnTweets = (tweets, sendTweets, refresh = false) => Promise.all(tweets.map(({ data, includes }) => ((this.redis && !refresh) ?
  177. this.redis.waitForProcess(`webshot/${data.id}`, this.webshotDelay * 4)
  178. .then(() => this.redis.getContent(`webshot/${data.id}`)) :
  179. Promise.reject())
  180. .then(content => {
  181. if (content === null)
  182. throw Error();
  183. logger.info(`retrieved cached webshot of tweet ${data.id} from redis database, message chain:`);
  184. const { msg, text, author } = JSON.parse(content);
  185. let cacheId = data.id;
  186. const retweetRef = (data.referenced_tweets || []).find(ref => ref.type === 'retweeted');
  187. if (retweetRef)
  188. cacheId += `,rt:${retweetRef.id}`;
  189. logger.info(JSON.stringify(koishi_1.Message.parseCQCode(msg)));
  190. sendTweets(cacheId, koishi_1.Message.parseCQCode(msg), text, author);
  191. return null;
  192. })
  193. .catch(() => {
  194. this.redis.startProcess(`webshot/${data.id}`);
  195. return { data, includes };
  196. }))).then(tweets => this.webshot(tweets.filter(t => t), (cacheId, msg, text, author) => {
  197. Promise.resolve()
  198. .then(() => {
  199. if (!this.redis)
  200. return;
  201. const [twid, rtid] = cacheId.split(',rt:');
  202. logger.info(`caching webshot of tweet ${twid} to redis database`);
  203. this.redis.cacheContent(`webshot/${twid}`, JSON.stringify({ msg: koishi_1.Message.toCQCode(msg), text, author, rtid })).then(() => this.redis.finishProcess(`webshot/${twid}`));
  204. })
  205. .then(() => sendTweets(cacheId, msg, text, author));
  206. }, this.webshotDelay));
  207. this.getTweet = (id, sender, refresh = false) => ((this.redis && !refresh) ?
  208. this.redis.waitForProcess(`webshot/${id}`, this.webshotDelay * 4)
  209. .then(() => this.redis.getContent(`webshot/${id}`))
  210. .then(content => {
  211. if (content === null)
  212. throw Error();
  213. const { rtid } = JSON.parse(content);
  214. return { data: Object.assign({ id }, rtid && { referenced_tweets: [{ type: 'retweeted', id: rtid }] }) };
  215. }) :
  216. Promise.reject())
  217. .catch(() => this.client.v2.singleTweet(id, v2SingleParams))
  218. .then((tweet) => {
  219. if (tweet.data.text) {
  220. logger.debug(`api returned tweet ${JSON.stringify(tweet)} for query id=${id}`);
  221. const retweetRef = (tweet.data.referenced_tweets || []).find(ref => ref.type === 'retweeted');
  222. if (retweetRef)
  223. return this.client.v2.singleTweet(retweetRef.id, v2SingleParams)
  224. .then(({ includes: { media } }) => (Object.assign(Object.assign({}, tweet), { includes: Object.assign(Object.assign({}, tweet.includes), { media }) })));
  225. }
  226. else {
  227. logger.debug(`skipped querying api as this tweet has been cached`);
  228. }
  229. return tweet;
  230. })
  231. .then((tweet) => this.workOnTweets([tweet], sender, refresh));
  232. this.sendTweets = (config = { reportOnSkip: false, force: false }, ...to) => (id, msg, text, author) => {
  233. to.forEach(subscriber => {
  234. const [twid, rtid] = id.split(',rt:');
  235. const { sourceInfo: source, reportOnSkip, force } = config;
  236. const targetStr = JSON.stringify(subscriber);
  237. const send = () => retryOnError(() => this.bot.sendTo(subscriber, msg), (_, count, terminate) => {
  238. if (count <= maxTrials) {
  239. logger.warn(`retry sending to ${subscriber.chatID} for the ${ordinal(count)} time...`);
  240. }
  241. else {
  242. logger.warn(`${count - 1} consecutive failures while sending message chain, trying plain text instead...`);
  243. terminate(this.bot.sendTo(subscriber, author + text, true));
  244. }
  245. }).then(() => {
  246. if (this.redis) {
  247. logger.info(`caching push status of tweet ${rtid ? `${rtid} (RTed as ${twid})` : twid} for ${targetStr}...`);
  248. return this.redis.cacheForChat(rtid || twid, subscriber);
  249. }
  250. });
  251. ((this.redis && !force) ? this.redis.isCachedForChat(rtid || twid, subscriber) : Promise.resolve(false))
  252. .then(isCached => {
  253. if (isCached) {
  254. logger.info(`skipped subscriber ${targetStr} as tweet ${rtid ? `${rtid} (or its RT)` : twid} has been sent already`);
  255. if (!reportOnSkip)
  256. return;
  257. text = `[最近发送过的推文:${rtid || twid}]`;
  258. msg = author + text;
  259. }
  260. logger.info(`pushing data${source ? ` of ${source}` : ''} to ${targetStr}`);
  261. return send();
  262. });
  263. });
  264. };
  265. this.get = (type, targetId, params) => {
  266. const { since_id, max_results } = params;
  267. const getMore = (res) => {
  268. if (res.errors && res.errors.length > 0) {
  269. const [err] = res.errors;
  270. if (!res.data)
  271. throw err;
  272. if (err.title === 'Authorization Error') {
  273. logger.warn(`non-fatal error while querying ${type} with id ${targetId}, error: ${err.detail}`);
  274. }
  275. }
  276. if (!res.meta.next_token ||
  277. utils_1.BigNumOps.compare(res.tweets.slice(-1)[0].id, since_id || '0') !== 1 ||
  278. !since_id && res.meta.result_count >= max_results)
  279. return res;
  280. return res.fetchNext().then(getMore);
  281. };
  282. if (type === 'listTweets')
  283. delete params.since_id;
  284. return this.client.v2[type](targetId, params).then(getMore)
  285. .then(({ includes, tweets }) => tweets.map((tweet) => ({
  286. data: tweet,
  287. includes: {
  288. media: includes.medias(tweet),
  289. users: [includes.author(tweet)]
  290. }
  291. })))
  292. .then(tweets => Promise.all(tweets.map(tweet => {
  293. const retweetRef = (tweet.data.referenced_tweets || []).find(ref => ref.type === 'retweeted');
  294. if (retweetRef)
  295. return this.client.v2.singleTweet(retweetRef.id, v2SingleParams)
  296. .then(({ includes: { media } }) => (Object.assign(Object.assign({}, tweet), { includes: Object.assign(Object.assign({}, tweet.includes), { media }) })));
  297. return tweet;
  298. })));
  299. };
  300. this.work = () => {
  301. const lock = this.lock;
  302. if (this.workInterval < 1)
  303. this.workInterval = 1;
  304. if (lock.feed.length === 0) {
  305. setTimeout(() => {
  306. this.work();
  307. }, this.workInterval * 1000);
  308. return;
  309. }
  310. if (lock.workon >= lock.feed.length)
  311. lock.workon = 0;
  312. if (!lock.threads[lock.feed[lock.workon]] ||
  313. !lock.threads[lock.feed[lock.workon]].subscribers ||
  314. lock.threads[lock.feed[lock.workon]].subscribers.length === 0) {
  315. logger.warn(`nobody subscribes thread ${lock.feed[lock.workon]}, removing from feed`);
  316. delete lock.threads[lock.feed[lock.workon]];
  317. lock.feed.splice(lock.workon, 1);
  318. fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
  319. this.work();
  320. return;
  321. }
  322. const currentFeed = lock.feed[lock.workon];
  323. logger.debug(`pulling feed ${currentFeed}`);
  324. const promise = new Promise(resolve => {
  325. let job = Promise.resolve();
  326. let id = lock.threads[currentFeed].id;
  327. let endpoint;
  328. let match = /https:\/\/twitter.com\/([^\/]+)\/lists\/([^\/]+)/.exec(currentFeed);
  329. if (match) {
  330. endpoint = 'listTweets';
  331. if (match[1] === 'i') {
  332. id = match[2];
  333. }
  334. else if (id === undefined) {
  335. job = job.then(() => this.client.v1.list({
  336. owner_screen_name: match[1],
  337. slug: match[2],
  338. })).then(({ id_str }) => {
  339. lock.threads[currentFeed].id = id = id_str;
  340. });
  341. }
  342. }
  343. else {
  344. match = /https:\/\/twitter.com\/([^\/]+)/.exec(currentFeed);
  345. if (match) {
  346. endpoint = 'userTimeline';
  347. if (id === undefined) {
  348. job = job.then(() => this.queryUser(match[1].replace(/^@?(.*)$/, '$1'))).then(userNameId => {
  349. lock.threads[currentFeed].id = id = userNameId.split(':')[1];
  350. });
  351. }
  352. }
  353. }
  354. const offset = lock.threads[currentFeed].offset;
  355. job.then(() => this.get(endpoint, id, Object.assign(Object.assign(Object.assign(Object.assign({}, v2SingleParams), { max_results: 20, exclude: ['retweets'] }), (offset > 0) && { since_id: offset }), (offset < -1) && { until_id: offset.slice(1) }))).catch((err) => {
  356. if (err.title === 'Not Found Error') {
  357. logger.warn(`error on fetching tweets for ${currentFeed}: ${showApiError(err)}`);
  358. lock.threads[currentFeed].subscribers.forEach(subscriber => {
  359. logger.info(`sending notfound message of ${currentFeed} to ${JSON.stringify(subscriber)}`);
  360. this.bot.sendTo(subscriber, `链接 ${currentFeed} 指向的用户或列表不存在,请退订。`).catch();
  361. });
  362. }
  363. else {
  364. logger.error(`unhandled error on fetching tweets for ${currentFeed}: ${showApiError(err)}`);
  365. }
  366. return [];
  367. }).then(resolve);
  368. });
  369. promise.then((tweets) => {
  370. logger.debug(`api returned ${JSON.stringify(tweets)} for feed ${currentFeed}`);
  371. const currentThread = lock.threads[currentFeed];
  372. const setOffset = (offset) => currentThread.offset = offset;
  373. const updateDate = () => currentThread.updatedAt = new Date().toString();
  374. if (tweets.length === 0) {
  375. if (currentThread.offset < -1) {
  376. setOffset(utils_1.BigNumOps.plus('1', currentThread.offset));
  377. }
  378. updateDate();
  379. return;
  380. }
  381. const currentUser = tweets[0].includes.users.find(user => user.id === currentThread.id);
  382. if (currentUser.username !== (0, exports.parseLink)(currentFeed)[1]) {
  383. lock.feed[lock.workon] = (0, exports.linkBuilder)(currentUser.username);
  384. }
  385. const topOfFeed = tweets[0].data.id;
  386. logger.info(`current offset: ${currentThread.offset}, current top of feed: ${topOfFeed}`);
  387. const bottomOfFeed = tweets.slice(-1)[0].data.id;
  388. const updateOffset = () => setOffset(topOfFeed);
  389. tweets = tweets.filter(({ data }) => (data.attachments || {}).media_keys);
  390. logger.info(`found ${tweets.length} tweets with extended entities`);
  391. if (currentThread.offset === '-1') {
  392. updateOffset();
  393. return;
  394. }
  395. if (currentThread.offset <= 0) {
  396. if (tweets.length === 0) {
  397. setOffset(utils_1.BigNumOps.plus('1', '-' + bottomOfFeed));
  398. lock.workon--;
  399. return;
  400. }
  401. tweets.splice(1);
  402. }
  403. if (tweets.length === 0) {
  404. updateDate();
  405. updateOffset();
  406. return;
  407. }
  408. return this.workOnTweets(tweets, this.sendTweets({ sourceInfo: `thread ${currentFeed}` }, ...currentThread.subscribers))
  409. .then(updateDate).then(updateOffset);
  410. })
  411. .then(() => {
  412. lock.workon++;
  413. let timeout = this.workInterval * 1000 / lock.feed.length;
  414. if (timeout < 1000)
  415. timeout = 1000;
  416. fs.writeFileSync(path.resolve(this.lockfile), JSON.stringify(lock));
  417. setTimeout(() => {
  418. this.work();
  419. }, timeout);
  420. });
  421. };
  422. this.client = new Twitter.TwitterApi({
  423. appKey: opt.consumerKey,
  424. appSecret: opt.consumerSecret,
  425. }).readOnly;
  426. this.lockfile = opt.lockfile;
  427. this.lock = opt.lock;
  428. this.workInterval = opt.workInterval;
  429. this.bot = opt.bot;
  430. this.webshotDelay = opt.webshotDelay;
  431. this.mode = opt.mode;
  432. this.wsUrl = opt.wsUrl;
  433. if (opt.redis)
  434. this.redis = new redis_1.default(opt.redis);
  435. ScreenNameNormalizer._queryUser = this.queryUser;
  436. exports.sendTweet = (idOrQuery, receiver, forceRefresh) => {
  437. const match = /^last(|-\d+)@([^\/?#,]+)((?:,no.*?=[^,]*)*)$/.exec(idOrQuery);
  438. const query = () => this.queryTimeline({
  439. username: match[2],
  440. count: 1 - Number(match[1]),
  441. noreps: { on: true, off: false }[match[3].replace(/.*,noreps=([^,]*).*/, '$1')],
  442. norts: { on: true, off: false }[match[3].replace(/.*,norts=([^,]*).*/, '$1')],
  443. }).then(tweets => tweets.slice(-1)[0].data.id);
  444. (match ? query() : Promise.resolve(idOrQuery))
  445. .then((id) => this.getTweet(id, this.sendTweets({ sourceInfo: `tweet ${id}`, reportOnSkip: true, force: forceRefresh }, receiver), forceRefresh))
  446. .catch((err) => {
  447. if (err.title !== 'Not Found Error') {
  448. logger.warn(`error retrieving tweet: ${showApiError(err)}`);
  449. this.bot.sendTo(receiver, `获取推文时出现错误:${showApiError(err)}`);
  450. }
  451. if (err.resource_type === 'user') {
  452. return this.bot.sendTo(receiver, `找不到用户 ${match[2].replace(/^@?(.*)$/, '@$1')}。`);
  453. }
  454. this.bot.sendTo(receiver, '找不到请求的推文,它可能已被删除。');
  455. });
  456. };
  457. exports.sendTimeline = ({ username, count, since, until, noreps, norts }, receiver) => {
  458. const countNum = Number(count) || 10;
  459. (countNum > 0 ? this.queryTimeline : this.queryTimelineReverse)({
  460. username,
  461. count: Math.abs(countNum),
  462. since: utils_1.BigNumOps.parse(since) || snowflake(new Date(since).getTime()),
  463. until: utils_1.BigNumOps.parse(until) || snowflake(new Date(until).getTime()),
  464. noreps: { on: true, off: false }[noreps],
  465. norts: { on: true, off: false }[norts],
  466. })
  467. .then(tweets => (0, utils_1.chainPromises)(tweets.map(({ data }) => () => this.bot.sendTo(receiver, `\
  468. 编号:${data.id}
  469. 时间:${data.created_at}
  470. 媒体:${(data.attachments || {}).media_keys ? '有' : '无'}
  471. 正文:\n${data.text.replace(/^([\s\S\n]{50})[\s\S\n]+?( https:\/\/t.co\/.*)?$/, '$1…$2')}`))
  472. .concat(() => this.bot.sendTo(receiver, tweets.length ?
  473. '时间线查询完毕,使用 /twipic_view <编号> 查看媒体推文详细内容。' :
  474. '时间线查询完毕,没有找到符合条件的媒体推文。'))))
  475. .catch((err) => {
  476. if (err.title !== 'Not Found Error') {
  477. logger.warn(`error retrieving timeline: ${showApiError(err)}`);
  478. return this.bot.sendTo(receiver, `获取时间线时出现错误:${showApiError(err)}`);
  479. }
  480. this.bot.sendTo(receiver, `找不到用户 ${username.replace(/^@?(.*)$/, '@$1')}。`);
  481. });
  482. };
  483. }
  484. }
  485. exports.default = default_1;