Skip to content

Let's use AI to Earn!

style: 1

yikaJasonMicf86a7d2b2509
diff --git a/electron/main/reply/controller.ts b/electron/main/reply/controller.ts
index 68531b91..b8b40432 100644
--- a/electron/main/reply/controller.ts
+++ b/electron/main/reply/controller.ts
@@ -1,17 +1,15 @@
/*
* @Author: nevin
* @Date: 2025-01-20 22:02:54
- * @LastEditTime: 2025-03-20 22:38:17
+ * @LastEditTime: 2025-03-20 23:01:23
* @LastEditors: nevin
* @Description: reply Reply
*/
import { AutoRunModel, AutoRunType } from '../../db/models/autoRun';
import { AccountService } from '../account/service';
-import { toolsApi } from '../api/tools';
import { AutoRunService } from '../autoRun/service';
import { Controller, Et, Icp, Inject } from '../core/decorators';
import platController from '../plat';
-import type { CommentData } from '../plat/plat.type';
import { ReplyService } from './service';
@Controller()
@@ -83,7 +81,6 @@ export class ReplyController {
/**
* 作品一键AI评论
- * 规则:评论所有的一级评论,已有自己的评论的不评论
*/
@Icp('ICP_REPLY_COMMENT_LIST_BY_AI')
async createCommentList(
@@ -94,37 +91,7 @@ export class ReplyController {
const account = await this.accountService.getAccountById(accountId);
if (!account) return null;
- // 1. 获取作品的评论列表, 如果返回
- let theHasMore = true;
- let thePcursor = undefined;
-
- const list: CommentData[] = [];
-
- while (theHasMore) {
- const {
- list,
- pageInfo: { pcursor, hasMore },
- } = await platController.getCommentList(account, dataId, thePcursor);
-
- list.forEach((item) => {
- list.push(item);
- });
-
- thePcursor = pcursor;
- theHasMore = !!hasMore;
- }
-
- // 2. 循环AI回复评论
- for (const element of list) {
- const aiRes = await toolsApi.aiRecoverReview({
- content: element.content,
- });
-
- platController.replyComment(account, element.commentId, aiRes, {
- dataId,
- comment: element,
- });
- }
+ const res = await this.replyService.autorReplyComment(account, dataId);
return true;
}
diff --git a/electron/main/reply/service.ts b/electron/main/reply/service.ts
index 119f6dd6..60f96177 100644
--- a/electron/main/reply/service.ts
+++ b/electron/main/reply/service.ts
@@ -6,6 +6,10 @@
*/
import { Injectable } from '../core/decorators';
import PQueue from 'p-queue';
+import { CommentData } from '../plat/plat.type';
+import { AccountModel } from '../../db/models/account';
+import platController from '../plat';
+import { toolsApi } from '../api/tools';
@Injectable()
export class ReplyService {
@@ -13,4 +17,50 @@ export class ReplyService {
constructor() {
this.replyQueue = new PQueue({ concurrency: 2 });
}
+
+ /**
+ * 自动一键评论
+ * 规则:评论所有的一级评论,已有自己的评论的不评论
+ */
+ async autorReplyComment(account: AccountModel, dataId: string) {
+ // 1. 获取作品的评论列表, 如果返回
+ let theHasMore = true;
+ let thePcursor = undefined;
+
+ const list: CommentData[] = [];
+
+ while (theHasMore) {
+ const {
+ list,
+ pageInfo: { pcursor, hasMore },
+ } = await platController.getCommentList(account, dataId, thePcursor);
+
+ list.forEach((item) => {
+ list.push(item);
+ });
+
+ thePcursor = pcursor;
+ theHasMore = !!hasMore;
+ }
+
+ // 2. 循环AI回复评论
+ for (const element of list) {
+ const aiRes = await toolsApi.aiRecoverReview({
+ content: element.content,
+ });
+
+ platController.replyComment(account, element.commentId, aiRes, {
+ dataId,
+ comment: element,
+ });
+ }
+
+ return true;
+ }
+
+ addReplyQueue(msg: string) {
+ this.replyQueue.add(() => {
+ console.log(msg);
+ });
+ }
}