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