Update
This commit is contained in:
@@ -42,6 +42,7 @@
|
||||
];
|
||||
|
||||
const ANGLE_DEFAULT = [
|
||||
{ value: 'NATURAL', text: 'Phản ứng tự nhiên' },
|
||||
{ value: 'AGREE', text: 'Đồng ý' },
|
||||
{ value: 'CHALLENGE', text: 'Không đồng ý' },
|
||||
{ value: 'ADD_INFO', text: 'Thêm thông tin liên quan hữu ích' },
|
||||
|
||||
+4
-1
@@ -5,6 +5,9 @@ export function rand(min, max) {
|
||||
export function getTweetIdFromUrl(xUrl: string) {
|
||||
xUrl = xUrl.replace('twitter.com', 'x.com').split('?')[0];
|
||||
const match = xUrl.match(/status\/(\d+)/);
|
||||
if (!match) throw new Error('URL X không hợp lệ');
|
||||
if (!match) throw new Error('getTweetIdFromUrl: URL X không hợp lệ');
|
||||
return match[1];
|
||||
}
|
||||
export const _toNumber = (value) => {
|
||||
return 1 * value;
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
import {Injectable, Logger} from "@nestjs/common";
|
||||
import {SqsPostService} from "./sqs.post.service";
|
||||
import {SUPPORT_SOCIAL_PROVIDERS, XPosterRouterService, XStrategy} from "../x-poster/x-poster.router.service";
|
||||
import {rand} from "../helper";
|
||||
import {getTweetIdFromUrl, rand} from "../helper";
|
||||
import {FacebookApi} from "../x-poster/facebook.api";
|
||||
import {NotifyService} from "../notify.service";
|
||||
import {XCacheService} from "../x-cache/x-cache.service";
|
||||
@@ -68,8 +68,8 @@ export class SqsPosterWorker {
|
||||
|
||||
private async process(data: any) {
|
||||
this.logger.log('📩 Got job:', data);
|
||||
const {type, content, xSubmitProvider, tweetUrl, publishTo, tweetId, telegramChatId} = data;
|
||||
switch (type) {
|
||||
const {type, job_type, content, xSubmitProvider, tweetUrl, publishTo, tweetId, telegramChatId} = data;
|
||||
switch (type || job_type) {
|
||||
case 'X_POSTER_TWEET': {
|
||||
await this.doPostTweet(
|
||||
content,
|
||||
@@ -87,6 +87,15 @@ export class SqsPosterWorker {
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'X_POSTER_REPLY_VIA_AUTO': {
|
||||
await this.doReplyTweet(
|
||||
content,
|
||||
tweetUrl,
|
||||
tweetId,
|
||||
xSubmitProvider
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 'X_POSTER_QUOTE': {
|
||||
await this.doQuoteTweet(
|
||||
content,
|
||||
@@ -159,11 +168,14 @@ export class SqsPosterWorker {
|
||||
private async doReplyTweet(
|
||||
text: string,
|
||||
tweetUrl: string,
|
||||
tweetId: string,
|
||||
tweetId?: string,
|
||||
strategy: string = XStrategy.BROWSER_COOKIE
|
||||
) {
|
||||
try {
|
||||
this.logger.log('doReplyTweet');
|
||||
if (!tweetId) {
|
||||
tweetId = getTweetIdFromUrl(tweetUrl)
|
||||
}
|
||||
// @ts-ignore
|
||||
const r = await this.xRouterService.postReply({text, tweetUrl, tweetId, strategy});
|
||||
if (r.success) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import {Inject, Injectable} from "@nestjs/common";
|
||||
import {Cache, CACHE_MANAGER} from "@nestjs/cache-manager";
|
||||
import {_toNumber} from "../helper";
|
||||
|
||||
@Injectable()
|
||||
export class XCacheService {
|
||||
@@ -68,6 +69,7 @@ export class XCacheService {
|
||||
const cacheKey = 'state_xcookie_status';
|
||||
return this.setCachedKey(cacheKey, 0, 3 * 24 * 3600);
|
||||
}
|
||||
|
||||
async setStateXCookiesIsSillALive() {
|
||||
const cacheKey = 'state_xcookie_status';
|
||||
return this.setCachedKey(cacheKey, 1, 3 * 24 * 3600);
|
||||
@@ -77,4 +79,14 @@ export class XCacheService {
|
||||
const cacheKey = 'state_xcookie_status';
|
||||
return 1 === Number(await this.cacheManager.get(cacheKey));
|
||||
}
|
||||
|
||||
async setDoneTweetComment(tweetId) {
|
||||
await this.setCachedKey(`cmt_tweetId:${tweetId}`, 1, 30 * 24 * 3600);
|
||||
return {tweetId};
|
||||
}
|
||||
|
||||
async isDoneTweetComment(tweetId) {
|
||||
const v = await this.getCachedData(`cmt_tweetId:${tweetId}`);
|
||||
return 1 === _toNumber(v);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user