Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 互动逻辑调整
牛文政c4e23540a6e2
diff --git a/electron/main/app.ts b/electron/main/app.tsindex 64f10241..7e2428df 100644--- a/electron/main/app.ts+++ b/electron/main/app.ts@@ -18,6 +18,7 @@ import { AppController } from './controller';import { AppService } from './service';import { ReplyModule } from './reply/module';import { AutoRunModule } from './autoRun/module';+import { InteractionModule } from './interaction/module';@Module({imports: [@@ -30,6 +31,7 @@ import { AutoRunModule } from './autoRun/module';TestModule,ReplyModule,AutoRunModule,+ InteractionModule,],controllers: [AppController],providers: [AppService],diff --git a/electron/main/interaction/controller.ts b/electron/main/interaction/controller.tsindex 26a3d8a2..60cd98ee 100644--- a/electron/main/interaction/controller.ts+++ b/electron/main/interaction/controller.ts@@ -26,6 +26,41 @@ export class InteractionController {@Inject(AutoRunService)private readonly autoRunService!: AutoRunService;+ /**+ * 一键AI互动+ */+ @Icp('ICP_INTERACTION_ONE_DATA')+ async interactionOneData(+ event: Electron.IpcMainInvokeEvent,+ accountId: number,+ works: WorkData,+ option: {+ commentContent: string; // 评论内容+ },+ ): Promise<any> {+ const account = await this.accountService.getAccountById(accountId);+ if (!account) return null;++ console.log('------ works', works);+ console.log('------ option', option);++ const res = await this.interactionService.interactionOneData(+ account,+ works,+ option,+ (e: {+ tag: AutorWorksInteractionScheduleEvent;+ status: -1 | 0 | 1;+ data?: any;+ error?: any;+ }) => {+ windowOperate.sendRenderMsg(SendChannelEnum.CommentRelyProgress, e);+ },+ );++ return res;+ }+/*** 一键AI互动*/@@ -41,6 +76,9 @@ export class InteractionController {const account = await this.accountService.getAccountById(accountId);if (!account) return null;+ console.log('------ worksList', worksList);+ console.log('------ option', option);+const res = await this.interactionService.autorInteraction(account,worksList,diff --git a/electron/main/interaction/service.ts b/electron/main/interaction/service.tsindex 4e43c99a..e7a96f22 100644--- a/electron/main/interaction/service.ts+++ b/electron/main/interaction/service.ts@@ -88,6 +88,163 @@ export class InteractionService {});}+ /**+ * 互动:作品评论,收藏,点赞+ */+ async interactionOneData(+ account: AccountModel,+ works: WorkData,+ option: {+ commentContent: string; // 评论内容+ },+ scheduleEvent: (data: {+ tag: AutorWorksInteractionScheduleEvent;+ status: -1 | 0 | 1; // -1 错误 0 进行中 1 完成+ data?: any; // 数据+ error?: any;+ }) => void,+ ) {+ const userInfo = getUserInfo();+ if (GlobleCache.getCache(getCacheKey(account))) {+ sysNotice('请勿重复执行', `该账户有正在执行的任务`);+ return false;+ }++ try {+ scheduleEvent({+ tag: AutorWorksInteractionScheduleEvent.Start,+ status: 0,+ });++ // 重设缓存时间+ GlobleCache.updateCacheTTL(getCacheKey(account), 60 * 15);++ scheduleEvent({+ tag: AutorWorksInteractionScheduleEvent.GetCommentListStart,+ status: 0,+ });++ // 历史记录+ const oldRecord = await this.getInteractionRecord(+ userInfo.id,+ account,+ works.dataId,+ );+ if (oldRecord) return false;++ if (!option.commentContent) {+ const aiRes = await toolsApi.aiRecoverReview({+ content: (works.desc || '') + (works.title || ''),+ });++ // AI接口错误+ if (!aiRes) {+ scheduleEvent({+ tag: AutorWorksInteractionScheduleEvent.Error,+ status: -1,+ error: '未获得AI产出内容',+ });+ return false;+ }++ option.commentContent = aiRes;+ }++ scheduleEvent({+ tag: AutorWorksInteractionScheduleEvent.ReplyCommentStart,+ data: {+ aiContent: option.commentContent,+ },+ status: 0,+ });++ // ----- 1-评论作品 -----+ const commentWorksRes = await platController.createCommentByOther(+ account,+ works.dataId,+ option.commentContent,+ );++ // 错误处理+ if (!commentWorksRes) {+ scheduleEvent({+ tag: AutorWorksInteractionScheduleEvent.ReplyCommentEnd,+ status: -1,+ error: '回复评论失败',+ });+ }++ scheduleEvent({+ tag: AutorWorksInteractionScheduleEvent.ReplyCommentEnd,+ status: 0,+ });++ // ----- 2-点赞作品 -----+ let isLike: 0 | 1 = 0;+ try {+ const isLikeRes = await platController.dianzanDyOther(+ account,+ works.dataId,+ );+ isLike = isLikeRes ? 1 : 0;+ } catch (error) {+ scheduleEvent({+ tag: AutorWorksInteractionScheduleEvent.Error,+ status: 0,+ error,+ data: {+ isLike,+ },+ });+ }++ // ----- 3-收藏作品 -----+ let isCollect: 0 | 1 = 0;+ try {+ const isCollectRes = await platController.shoucangDyOther(+ account,+ works.dataId,+ );+ isCollect = isCollectRes ? 1 : 0;+ } catch (error) {+ scheduleEvent({+ tag: AutorWorksInteractionScheduleEvent.Error,+ status: 0,+ error,+ data: {+ isLike,+ },+ });+ }++ // 创建评论记录+ this.create(+ userInfo.id,+ account,+ {+ worksId: works.dataId,+ worksTitle: works.title,+ worksCover: works.coverUrl,+ },+ option.commentContent,+ isLike,+ isCollect,+ );++ scheduleEvent({+ tag: AutorWorksInteractionScheduleEvent.ReplyCommentEnd,+ status: 0,+ });+ } catch (error) {+ scheduleEvent({+ tag: AutorWorksInteractionScheduleEvent.Error,+ status: -1,+ error,+ });+ return false;+ }+ }+/*** 自动一键互动:作品评论,收藏,点赞* 规则:评论作品,已经评论不评论@@ -148,88 +305,90 @@ export class InteractionService {return false;}+ option.commentContent = aiRes;+ }++ scheduleEvent({+ tag: AutorWorksInteractionScheduleEvent.ReplyCommentStart,+ data: {+ aiContent: option.commentContent,+ },+ status: 0,+ });++ // ----- 1-评论作品 -----+ const commentWorksRes = await platController.createCommentByOther(+ account,+ works.dataId,+ option.commentContent,+ );++ // 错误处理+ if (!commentWorksRes) {scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.ReplyCommentStart,- data: {- aiContent: aiRes,- },- status: 0,+ tag: AutorWorksInteractionScheduleEvent.ReplyCommentEnd,+ status: -1,+ error: '回复评论失败',});+ continue;+ }- // ----- 1-评论作品 ------ const commentWorksRes = await platController.createCommentByOther(+ scheduleEvent({+ tag: AutorWorksInteractionScheduleEvent.ReplyCommentEnd,+ status: 0,+ });++ // ----- 2-点赞作品 -----+ let isLike: 0 | 1 = 0;+ try {+ const isLikeRes = await platController.dianzanDyOther(account,works.dataId,- aiRes,);-- // 错误处理- if (!commentWorksRes) {- scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.ReplyCommentEnd,- status: -1,- error: '回复评论失败',- });- continue;- }-+ isLike = isLikeRes ? 1 : 0;+ } catch (error) {scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.ReplyCommentEnd,+ tag: AutorWorksInteractionScheduleEvent.Error,status: 0,+ error,+ data: {+ isLike,+ },});+ }- // ----- 2-点赞作品 ------ let isLike: 0 | 1 = 0;- try {- const isLikeRes = await platController.dianzanDyOther(- account,- works.dataId,- );- isLike = isLikeRes ? 1 : 0;- } catch (error) {- scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.Error,- status: 0,- error,- data: {- isLike,- },- });- }-- // ----- 3-收藏作品 ------ let isCollect: 0 | 1 = 0;- try {- const isCollectRes = await platController.shoucangDyOther(- account,- works.dataId,- );- isCollect = isCollectRes ? 1 : 0;- } catch (error) {- scheduleEvent({- tag: AutorWorksInteractionScheduleEvent.Error,- status: 0,- error,- data: {- isLike,- },- });- }-- // 创建评论记录- this.create(- userInfo.id,+ // ----- 3-收藏作品 -----+ let isCollect: 0 | 1 = 0;+ try {+ const isCollectRes = await platController.shoucangDyOther(account,- {- worksId: works.dataId,- worksTitle: works.title,- worksCover: works.coverUrl,- },- option.commentContent,- isLike,- isCollect,+ works.dataId,);+ isCollect = isCollectRes ? 1 : 0;+ } catch (error) {+ scheduleEvent({+ tag: AutorWorksInteractionScheduleEvent.Error,+ status: 0,+ error,+ data: {+ isLike,+ },+ });}++ // 创建评论记录+ this.create(+ userInfo.id,+ account,+ {+ worksId: works.dataId,+ worksTitle: works.title,+ worksCover: works.coverUrl,+ },+ option.commentContent,+ isLike,+ isCollect,+ );}scheduleEvent({diff --git a/src/icp/replyother.ts b/src/icp/replyother.tsindex ec62933d..e2f4a817 100644--- a/src/icp/replyother.ts+++ b/src/icp/replyother.ts@@ -179,6 +179,25 @@ export async function icpReplyCommentByOther(return res;}+/**+ * 作品互动+ */+export async function icpInteractionOneData(+ accountId: number,+ works: WorkData,+ option: {+ commentContent: string; // 评论内容+ },+) {+ const res: boolean = await window.ipcRenderer.invoke(+ 'ICP_INTERACTION_ONE_DATA',+ accountId,+ works,+ option,+ );+ return res;+}+/*** 一键AI互动*/diff --git a/src/views/interaction/components/oneKeyInteraction.tsx b/src/views/interaction/components/oneKeyInteraction.tsxindex b8d761bf..abf0e2d9 100644--- a/src/views/interaction/components/oneKeyInteraction.tsx+++ b/src/views/interaction/components/oneKeyInteraction.tsx@@ -40,7 +40,7 @@ const Com = forwardRef<InteractionOneKeyRef>((props: any, ref) => {inWorkDataList: WorkData[] = [],) {if (!inWorkDataList.length) return;- const res = await icpCreateInteractionOneKey(inAccountId, workDataList, {+ const res = await icpCreateInteractionOneKey(inAccountId, inWorkDataList, {commentContent: '不错啊!收藏了!',});console.log('------ res', res);diff --git a/src/views/interaction/index.tsx b/src/views/interaction/index.tsxindex a27ed8e0..15e7348b 100644--- a/src/views/interaction/index.tsx+++ b/src/views/interaction/index.tsx@@ -3,7 +3,7 @@* @Date: 2025-02-10 22:20:15* @LastEditTime: 2025-03-25 16:01:56* @LastEditors: nevin- * @Description: 评论页面 reply+ * @Description: 互动页面 interaction*/import { WorkData } from '@/icp/reply';import { Button, Col, Popconfirm, Row, Tabs, Tooltip } from 'antd';@@ -17,7 +17,7 @@ import {import InteractionOneKey, {InteractionOneKeyRef,} from './components/oneKeyInteraction';-import { getCommentSearchNotes } from '@/icp/replyother';+import { getCommentSearchNotes, icpInteractionOneData } from '@/icp/replyother';export default function Page() {const [wordList, setWordList] = useState<WorkData[]>([]);@@ -44,7 +44,17 @@ export default function Page() {}/**- * 打开创建自动任务+ * 单个作品互动+ */+ async function interactionOneData(works: WorkData) {+ const res = await icpInteractionOneData(activeAccountId, works, {+ commentContent: '不错啊!点赞点赞!',+ });+ console.log('----- res ---', res);+ }++ /**+ * TODO:打开创建自动任务* @param data*/function openAddAutoRun(data: WorkData) {}@@ -114,7 +124,7 @@ export default function Page() {<Col span={8}><Tooltip title="自动评论"><FieldTimeOutlined- onClick={() => openAddAutoRun(item)}+ onClick={() => interactionOneData(item)}/></Tooltip></Col>