Skip to content

Let's use AI to Earn!

feat: 优化一键评论的反馈

牛文政e5ed7b6c1f2f
diff --git a/commont/types/reply.ts b/commont/types/reply.ts
new file mode 100644
index 00000000..ce92df63
--- /dev/null
+++ b/commont/types/reply.ts
@@ -0,0 +1,18 @@
+// 自动任务的进度标识
+export enum AutorReplyCommentScheduleEvent {
+ Start = 'start', // 开始
+ GetCommentListStart = 'getCommentListStart', // 获取评论列表开始
+ GetCommentListEnd = 'getCommentListEnd', // 获取评论列表结束
+ ReplyCommentStart = 'replyCommentStart', // 评论开始
+ ReplyCommentEnd = 'replyCommentEnd', // 评论结束
+ End = 'end', // 结束
+ Error = 'error', // 错误
+}
+
+export const AutorReplyCommentScheduleEventTagStrMap = new Map([
+ [AutorReplyCommentScheduleEvent.Start, '开始'],
+ [AutorReplyCommentScheduleEvent.GetCommentListStart, '获取评论列表开始'],
+ [AutorReplyCommentScheduleEvent.GetCommentListEnd, '获取评论列表结束'],
+ [AutorReplyCommentScheduleEvent.ReplyCommentStart, '评论开始'],
+ [AutorReplyCommentScheduleEvent.ReplyCommentEnd, '评论结束'],
+]);
diff --git a/electron/main/plat/platforms/douyin/index.ts b/electron/main/plat/platforms/douyin/index.ts
index 5b19d103..125b4587 100644
--- a/electron/main/plat/platforms/douyin/index.ts
+++ b/electron/main/plat/platforms/douyin/index.ts
@@ -396,15 +396,18 @@ export class Douyin extends PlatformBase {
},
) {
const cookie: CookiesType = JSON.parse(account.loginCookie);
- const res = await douyinService.creatorCommentReply(cookie, {
- comment_Id: commentId,
- item_id: option.dataId!,
- text: content,
- });
-
- console.log('------ res', res);
+ try {
+ const res = await douyinService.creatorCommentReply(cookie, {
+ comment_Id: commentId,
+ item_id: option.dataId!,
+ text: content,
+ });
- return false;
+ return res.status === 200 && res.data.status_code === 0;
+ } catch (error) {
+ console.log('------ replyComment ----', error);
+ return false;
+ }
}
pubParamsParse(params: IPublishParams): DouyinPlatformSettingType {
diff --git a/electron/main/reply/comment.ts b/electron/main/reply/comment.ts
deleted file mode 100644
index 3afc9066..00000000
--- a/electron/main/reply/comment.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * @Author: nevin
- * @Date: 2025-01-21 21:12:52
- * @LastEditTime: 2025-03-23 19:40:58
- * @LastEditors: nevin
- * @Description:
- */
-// 自动任务的进度标识 开始 获取评论列表开始 获取评论列表结束 评论开始 评论结束 结束 错误
-export enum AutorReplyCommentScheduleEvent {
- Start = 'start',
- GetCommentListStart = 'getCommentListStart',
- GetCommentListEnd = 'getCommentListEnd',
- ReplyCommentStart = 'replyCommentStart',
- ReplyCommentEnd = 'replyCommentEnd',
- End = 'end',
- Error = 'error',
-}
diff --git a/electron/main/reply/controller.ts b/electron/main/reply/controller.ts
index 233d436b..80245195 100644
--- a/electron/main/reply/controller.ts
+++ b/electron/main/reply/controller.ts
@@ -11,9 +11,9 @@ import { AccountService } from '../account/service';
import { AutoRunService } from '../autoRun/service';
import { Controller, Et, Icp, Inject } from '../core/decorators';
import platController from '../plat';
-import { AutorReplyCommentScheduleEvent } from './comment';
import { ReplyService } from './service';
import { SendChannelEnum } from '../../../commont/UtilsEnum';
+import { AutorReplyCommentScheduleEvent } from '../../../commont/types/reply';
@Controller()
export class ReplyController {
@@ -186,6 +186,7 @@ export class ReplyController {
(e: {
tag: AutorReplyCommentScheduleEvent;
status: -1 | 0 | 1;
+ data?: any;
error?: any;
}) => {
windowOperate.sendRenderMsg(SendChannelEnum.CommentRelyProgress, e);
@@ -195,6 +196,22 @@ export class ReplyController {
return res;
}
+ /**
+ * 测试
+ */
+ @Icp('ICP_REPLY_TEST_NOTICE')
+ async testNotice(event: Electron.IpcMainInvokeEvent): Promise<any> {
+ console.log('----1111');
+
+ windowOperate.sendRenderMsg(SendChannelEnum.CommentRelyProgress, {
+ tag: AutorReplyCommentScheduleEvent,
+ status: 1,
+ error: '测试',
+ });
+
+ return 1;
+ }
+
/**
* 回复评论
*/
diff --git a/electron/main/reply/service.ts b/electron/main/reply/service.ts
index 0f9d8d89..f53b8c4a 100644
--- a/electron/main/reply/service.ts
+++ b/electron/main/reply/service.ts
@@ -9,10 +9,10 @@ import PQueue from 'p-queue';
import { AccountModel } from '../../db/models/account';
import platController from '../plat';
import { toolsApi } from '../api/tools';
-import { AutorReplyCommentScheduleEvent } from './comment';
import { AutoRunService } from '../autoRun/service';
import { AutoRunModel } from '../../db/models/autoRun';
import { sysNotice } from '../../global/notice';
+import { AutorReplyCommentScheduleEvent } from '../../../commont/types/reply';
@Injectable()
export class ReplyService {
@@ -33,7 +33,8 @@ export class ReplyService {
dataId: string,
scheduleEvent: (data: {
tag: AutorReplyCommentScheduleEvent;
- status: -1 | 0 | 1;
+ status: -1 | 0 | 1; // -1 错误 0 进行中 1 完成
+ data?: any; // 数据
error?: any;
}) => void,
) {
@@ -57,11 +58,6 @@ export class ReplyService {
pageInfo: { pcursor, hasMore },
} = await platController.getCommentList(account, dataId, thePcursor);
- scheduleEvent({
- tag: AutorReplyCommentScheduleEvent.GetCommentListEnd,
- status: 0,
- });
-
if (list.length === 0) {
scheduleEvent({
tag: AutorReplyCommentScheduleEvent.End,
@@ -71,16 +67,12 @@ export class ReplyService {
}
scheduleEvent({
- tag: AutorReplyCommentScheduleEvent.ReplyCommentStart,
+ tag: AutorReplyCommentScheduleEvent.GetCommentListEnd,
status: 0,
});
// 2. 循环AI回复评论
for (const element of list) {
- const aiRes = await toolsApi.aiRecoverReview({
- content: element.content,
- });
-
if (account.uid !== element.userId) {
let hadReply = false;
for (const reply of element.subCommentList) {
@@ -91,10 +83,49 @@ export class ReplyService {
}
if (!hadReply) {
- platController.replyComment(account, element.commentId, aiRes, {
- dataId,
- comment: element,
+ const aiRes = await toolsApi.aiRecoverReview({
+ content: element.content,
+ });
+
+ scheduleEvent({
+ tag: AutorReplyCommentScheduleEvent.ReplyCommentStart,
+ data: element,
+ status: 0,
});
+
+ // AI接口错误
+ if (!aiRes) {
+ scheduleEvent({
+ tag: AutorReplyCommentScheduleEvent.Error,
+ status: -1,
+ error: '未获得AI产出内容',
+ });
+ return false;
+ }
+
+ const replyRes = await platController.replyComment(
+ account,
+ element.commentId,
+ aiRes,
+ {
+ dataId,
+ comment: element,
+ },
+ );
+
+ // 错误处理
+ if (!replyRes) {
+ scheduleEvent({
+ tag: AutorReplyCommentScheduleEvent.ReplyCommentEnd,
+ status: -1,
+ error: '回复评论失败',
+ });
+ } else {
+ scheduleEvent({
+ tag: AutorReplyCommentScheduleEvent.ReplyCommentEnd,
+ status: 0,
+ });
+ }
}
}
}
diff --git a/src/icp/reply.ts b/src/icp/reply.ts
index 1fb5a94a..a2c2f5d1 100644
--- a/src/icp/reply.ts
+++ b/src/icp/reply.ts
@@ -112,7 +112,7 @@ export async function icpReplyComment(
/**
* 一键作品回复评论
*/
-export async function icpCreateCommentList(accountId: number, dataId: string) {
+export async function icpReplyCommentList(accountId: number, dataId: string) {
const res: boolean = await window.ipcRenderer.invoke(
'ICP_REPLY_COMMENT_LIST_BY_AI',
accountId,
diff --git a/src/views/reply/components/oneKeyReply.tsx b/src/views/reply/components/oneKeyReply.tsx
new file mode 100644
index 00000000..9ce3fcdb
--- /dev/null
+++ b/src/views/reply/components/oneKeyReply.tsx
@@ -0,0 +1,84 @@
+/*
+ * @Author: nevin
+ * @Date: 2025-03-18 21:02:38
+ * @LastEditTime: 2025-03-25 13:41:14
+ * @LastEditors: nevin
+ * @Description: 一键评论
+ */
+import { icpReplyCommentList, WorkData } from '@/icp/reply';
+import { Modal } from 'antd';
+import { forwardRef, useImperativeHandle, useState } from 'react';
+import { SendChannelEnum } from '@@/UtilsEnum';
+import {
+ AutorReplyCommentScheduleEvent,
+ AutorReplyCommentScheduleEventTagStrMap,
+} from '@@/types/reply';
+
+export interface OneKeyReplyRef {
+ init: (accountId: number, data: WorkData) => Promise<void>;
+}
+
+const Com = forwardRef<OneKeyReplyRef>((props: any, ref) => {
+ const [isModalOpen, setIsModalOpen] = useState(false);
+ const [infoText, setInfoText] = useState('');
+ const [errorText, setErrorText] = useState('');
+ const [workData, setWorkData] = useState<WorkData | null>(null);
+ async function init(accountId: number, data: WorkData) {
+ window.ipcRenderer.on(SendChannelEnum.CommentRelyProgress, onGetNotice);
+ setWorkData(data);
+ setIsModalOpen(true);
+ replyCommentList(accountId, data);
+ }
+
+ /**
+ * 一键AI评论
+ */
+ async function replyCommentList(inAccountId: number, inWorkData: WorkData) {
+ if (!workData?.dataId) return;
+ const res = await icpReplyCommentList(inAccountId, inWorkData?.dataId);
+ console.log('------ res', res);
+ }
+
+ /**
+ * 返回值处理
+ * @param e
+ * @param args
+ */
+ function onGetNotice(
+ e: any,
+ args: {
+ tag: AutorReplyCommentScheduleEvent;
+ status: -1 | 0 | 1;
+ data?: any;
+ error?: any;
+ },
+ ) {
+ const tagStr = AutorReplyCommentScheduleEventTagStrMap.get(args.tag) || '';
+ setInfoText(`${tagStr}`);
+ }
+
+ useImperativeHandle(ref, () => ({
+ init: init,
+ }));
+
+ function handleCancel() {
+ window.ipcRenderer.off(SendChannelEnum.CommentRelyProgress, onGetNotice);
+ setIsModalOpen(false);
+ }
+
+ return (
+ <>
+ <Modal
+ title="一键评论"
+ open={isModalOpen}
+ onCancel={handleCancel}
+ footer={null}
+ width={400}
+ >
+ <p>{infoText}</p>
+ <p>{errorText}</p>
+ </Modal>
+ </>
+ );
+});
+export default Com;
diff --git a/src/views/reply/index.tsx b/src/views/reply/index.tsx
index 53eca043..590f0519 100644
--- a/src/views/reply/index.tsx
+++ b/src/views/reply/index.tsx
@@ -5,14 +5,13 @@
* @LastEditors: nevin
* @Description: 评论页面 reply
*/
-import { icpCreatorList, WorkData, icpCreateCommentList } from '@/icp/reply';
-import { Button, Col, message, Row, Tabs, Tooltip } from 'antd';
+import { icpCreatorList, WorkData } from '@/icp/reply';
+import { Button, Col, Row, Tabs, Tooltip } from 'antd';
import { useCallback, useRef, useState } from 'react';
import AccountSidebar from '../account/components/AccountSidebar/AccountSidebar';
import ReplyWorks, { ReplyWorksRef } from './components/replyWorks';
import AddAutoRun, { AddAutoRunRef } from './components/addAutoRun';
import CommentList, { CommentListRef } from './components/commentList';
-import { SendChannelEnum } from '@@/UtilsEnum';
import {
AliwangwangOutlined,
CommentOutlined,
@@ -22,6 +21,7 @@ import {
} from '@ant-design/icons';
import styles from './reply.module.scss';
import AutoRun from './autoRun';
+import OneKeyReply, { OneKeyReplyRef } from './components/oneKeyReply';
export default function Page() {
const [wordList, setWordList] = useState<WorkData[]>([]);
@@ -37,23 +37,7 @@ export default function Page() {
const Ref_ReplyWorks = useRef<ReplyWorksRef>(null);
const Ref_AddAutoRun = useRef<AddAutoRunRef>(null);
const Ref_CommentList = useRef<CommentListRef>(null);
-
- // 注册监听
- (() => {
- window.ipcRenderer.on(
- SendChannelEnum.CommentRelyProgress,
- (
- e,
- args: {
- tag: string;
- status: -1 | 0 | 1;
- error?: any;
- },
- ) => {
- message.info(`收到评论通知--${args.status}---${args.tag}`);
- },
- );
- })();
+ const Ref_OneKeyReply = useRef<OneKeyReplyRef>(null);
async function getCreatorList(accountId: number) {
if (accountId === -1) return;
@@ -62,14 +46,6 @@ export default function Page() {
setWordList([...wordList, ...res.list]);
}
- /**
- * 一键AI评论
- */
- async function createCommentList(data: WorkData) {
- const res = await icpCreateCommentList(activeAccountId, data.dataId);
- console.log('------ res', res);
- }
-
/**
* 打开作品评论
* @param data
@@ -108,6 +84,16 @@ export default function Page() {
<div className="m-4">
<Tabs defaultActiveKey="1">
<Tabs.TabPane tab="作品列表" key="1">
+ {/* 测试---- */}
+ <Button
+ onClick={() => {
+ window.ipcRenderer.invoke('ICP_REPLY_TEST_NOTICE');
+ }}
+ >
+ 测试
+ </Button>
+ {/* 测试---- */}
+
{activeAccountId === -1 ? (
<div className="flex items-center justify-center h-[300px] text-gray-500">
<Tooltip title="请先在左侧侧边栏选择账户">
@@ -157,7 +143,12 @@ export default function Page() {
<Col span={8}>
<Tooltip title="一键评论">
<AliwangwangOutlined
- onClick={() => createCommentList(item)}
+ onClick={() =>
+ Ref_OneKeyReply.current?.init(
+ activeAccountId,
+ item,
+ )
+ }
/>
</Tooltip>
</Col>
@@ -199,6 +190,7 @@ export default function Page() {
<ReplyWorks ref={Ref_ReplyWorks} />
<AddAutoRun ref={Ref_AddAutoRun} />
<CommentList ref={Ref_CommentList} />
+ <OneKeyReply ref={Ref_OneKeyReply} />
</div>
);
}