From 79022be20b54211f3b1302679bd7722012af269c Mon Sep 17 00:00:00 2001 From: NAME Date: Fri, 22 May 2026 03:14:03 +0000 Subject: [PATCH] Update --- chrom-ext/content.js | 1 + src/helper.ts | 5 ++++- src/sqs-module/sqs.poster.worker.ts | 20 ++++++++++++++++---- src/x-cache/x-cache.service.ts | 12 ++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/chrom-ext/content.js b/chrom-ext/content.js index 7d26429..795591c 100644 --- a/chrom-ext/content.js +++ b/chrom-ext/content.js @@ -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' }, diff --git a/src/helper.ts b/src/helper.ts index f569a9b..b6dfd9a 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -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; } \ No newline at end of file diff --git a/src/sqs-module/sqs.poster.worker.ts b/src/sqs-module/sqs.poster.worker.ts index b55b440..77d162d 100644 --- a/src/sqs-module/sqs.poster.worker.ts +++ b/src/sqs-module/sqs.poster.worker.ts @@ -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) { diff --git a/src/x-cache/x-cache.service.ts b/src/x-cache/x-cache.service.ts index 038f25c..ef230fb 100644 --- a/src/x-cache/x-cache.service.ts +++ b/src/x-cache/x-cache.service.ts @@ -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); + } }