Skip to content

Commit 30a1b25

Browse files
author
lrhh123
committed
add: 添加多平台的支持
1 parent 2984cd8 commit 30a1b25

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+7092
-1301
lines changed

.env

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
PY_HOSTNAME=localhost
22
PY_PORT=9999
33
VAR=1234
4-
BKEXE_PATH=./backend/__main__.exe
4+
BKEXE_PATH=./backend/__main__.exe
5+
PKG_VERSION=0.0.1

.eslintrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ module.exports = {
3030
'max-classes-per-file': 'off',
3131
'no-continue': 'off',
3232
'no-plusplus': 'off',
33+
'no-underscore-dangle': 'off',
34+
camelcase: 'off',
35+
'no-use-before-define': 'off',
36+
'no-dupe-class-members': 'off',
3337
},
3438
parserOptions: {
3539
ecmaVersion: 2022,

src/main/backend/backend.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { BroadcastService } from './services/broadcastService';
1717
import { SystemService } from './services/systemService';
1818
import { ConfigService } from './services/configService';
1919
import { PlatformConfigController } from './controllers/platformConfigController';
20-
import { AutoReplyController } from './controllers/autoReplyController';
20+
import { AutoReplyController } from './controllers/keywordReplyController';
2121

2222
const sessionController = new SessionController();
2323
const configController = new ConfigController();
@@ -93,7 +93,6 @@ class BKServer {
9393
console.log('Client connected registerHandlers');
9494
this.messageService.registerHandlers(socket);
9595
this.sessionService.registerHandlers(socket);
96-
this.configService.registerHandlers(socket);
9796
this.broadcastService.registerHandlers(socket);
9897

9998
socket.on('disconnect', () => {

src/main/backend/constants/index.ts

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
export const ALL_PLATFORMS = [
2+
{
3+
id: 'bilibili',
4+
name: 'bilibili',
5+
},
6+
{
7+
id: 'douyin',
8+
name: '抖音',
9+
},
10+
{
11+
id: 'douyin_mp',
12+
name: '抖音企业号',
13+
},
14+
{
15+
id: 'win_jinmai',
16+
name: '京卖',
17+
},
18+
{
19+
id: 'jinritemai',
20+
name: '抖店',
21+
},
22+
{
23+
id: 'win_qianniu',
24+
name: '千牛',
25+
},
26+
{
27+
id: 'win_wechat',
28+
name: '微信',
29+
},
30+
{
31+
id: 'win_wecom',
32+
name: '企微(Bate版)',
33+
},
34+
{
35+
id: 'weibo',
36+
name: '微博私信',
37+
},
38+
{
39+
id: 'xiaohongshu',
40+
name: '小红书评论',
41+
},
42+
{
43+
id: 'xiaohongshu_pro',
44+
name: '小红书私信',
45+
},
46+
{
47+
id: 'zhihu',
48+
name: '知乎',
49+
},
50+
];
51+
52+
// # 固定会传递的上下文参数
53+
// CTX_APP_NAME = "app_name"
54+
// CTX_APP_ID = "app_id"
55+
// CTX_INSTANCE_ID = "instance_id"
56+
57+
// CTX_USERNAME = "username"
58+
// CTX_PLATFORM = "platform"
59+
// CTX_HAS_NEW_MESSAGE = "has_new_message"
60+
// CTX_HAS_GROUP_MESSAGE = "has_group_message"
61+
62+
// # 千牛平台特有的上下文参数
63+
// CTX_CURRENT_GOODS = "CTX_CURRENT_GOODS" # 当前商品
64+
// CTX_CURRENT_GOODS_ID = "CTX_CURRENT_GOODS_ID" # 当前商品 ID
65+
// CTX_MEMBER_TAG = "CTX_MEMBER_TAG" # 会员标签
66+
// CTX_FAN_TAG = "CTX_FAN_TAG" # 粉丝标签
67+
// CTX_NEW_CUSTOMER_TAG = "CTX_NEW_CUSTOMER_TAG" # 新客标签
68+
69+
export const CTX_APP_NAME = 'app_name';
70+
export const CTX_APP_ID = 'app_id';
71+
export const CTX_INSTANCE_ID = 'instance_id';
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,37 @@
11
import { Config } from '../entities/config';
2+
import { Plugin } from '../entities/plugin';
23

34
export class ConfigController {
4-
async getConfig(): Promise<Config> {
5-
try {
6-
const config = await Config.findByPk(1);
7-
if (!config) {
8-
throw new Error('Config not found');
9-
}
5+
async getByAppId(appId: string): Promise<Config | null> {
6+
const config = await Config.findOne({
7+
where: { platform_id: appId },
8+
});
9+
return config;
10+
}
1011

11-
return config;
12-
} catch (error) {
13-
const newConfig = await Config.create({
14-
extract_phone: true,
15-
extract_product: true,
16-
save_path: '',
17-
reply_speed: 0,
18-
reply_random_speed: 0,
19-
default_reply: '',
20-
wait_humans_time: 60,
21-
context_count: 1,
22-
gpt_base_url: 'https://api.openai.com/v1',
23-
gpt_key: 'your-key',
24-
gpt_model: 'gpt-3.5-turbo',
25-
gpt_temperature: 0.7,
26-
gpt_top_p: 0.9,
27-
stream: true,
28-
use_lazy: false,
29-
lazy_key: 'your-key',
30-
});
31-
return newConfig;
32-
}
12+
async getByInstanceId(instanceId: string): Promise<Config | null> {
13+
const config = await Config.findOne({
14+
where: { instance_id: instanceId },
15+
});
16+
return config;
3317
}
3418

35-
async updateConfig(id: number, configData: Partial<Config>): Promise<Config> {
36-
const config = await Config.findByPk(id);
19+
async getGlobalConfig(): Promise<Config> {
20+
let config = await Config.findOne({
21+
where: { global: true },
22+
});
23+
3724
if (!config) {
38-
throw new Error('Config not found');
25+
config = await Config.create({
26+
global: true,
27+
});
3928
}
4029

41-
const data = await config.update(configData);
42-
return data;
30+
return config;
31+
}
32+
33+
async getPluginConfig(pluginId: number): Promise<Plugin | null> {
34+
const plugin = await Plugin.findByPk(pluginId);
35+
return plugin;
4336
}
4437
}

src/main/backend/controllers/globalParamController.ts

-27
This file was deleted.

src/main/backend/controllers/autoReplyController.ts renamed to src/main/backend/controllers/keywordReplyController.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import ExcelJS from 'exceljs';
22
import fs from 'fs';
33
import { Op } from 'sequelize';
4-
import { AutoReply } from '../entities/autoReply';
4+
import { Keyword } from '../entities/keyword';
55
import { ALL_PLATFORMS } from '../constants';
66
import { getTempPath } from '../../utils';
77

88
export class AutoReplyController {
99
async create(autoReplyData: any) {
10-
return AutoReply.create(autoReplyData);
10+
return Keyword.create(autoReplyData);
1111
}
1212

1313
async update(id: number, autoReplyData: any) {
14-
const autoReply = await AutoReply.findByPk(id);
14+
const autoReply = await Keyword.findByPk(id);
1515
if (!autoReply) {
1616
throw new Error('AutoReply not found');
1717
}
1818
await autoReply.update(autoReplyData);
1919
}
2020

2121
async delete(id: number) {
22-
const autoReply = await AutoReply.findByPk(id);
22+
const autoReply = await Keyword.findByPk(id);
2323
if (!autoReply) {
2424
throw new Error('AutoReply not found');
2525
}
@@ -68,22 +68,22 @@ export class AutoReplyController {
6868
}
6969
});
7070

71-
const originalAutoReplies = await AutoReply.findAll();
71+
const originalAutoReplies = await Keyword.findAll();
7272

7373
try {
7474
// 先删除所有数据
75-
await AutoReply.destroy({ where: {} });
76-
await AutoReply.bulkCreate(autoReplies);
75+
await Keyword.destroy({ where: {} });
76+
await Keyword.bulkCreate(autoReplies);
7777
} catch (error) {
7878
// 如果插入失败,回滚数据
7979
// @ts-ignore
80-
await AutoReply.bulkCreate(originalAutoReplies);
80+
await Keyword.bulkCreate(originalAutoReplies);
8181
throw error;
8282
}
8383
}
8484

8585
async exportExcel() {
86-
const autoReplies = await AutoReply.findAll();
86+
const autoReplies = await Keyword.findAll();
8787

8888
const workbook = new ExcelJS.Workbook();
8989
const worksheet = workbook.addWorksheet('自动回复');
@@ -144,13 +144,13 @@ export class AutoReplyController {
144144
}
145145

146146
async getKeywords(platformId: string) {
147-
const autoReplies = await AutoReply.findAll({
147+
const autoReplies = await Keyword.findAll({
148148
where: {
149149
platform_id: platformId,
150150
},
151151
});
152152

153-
const globalKeywords = await AutoReply.findAll({
153+
const globalKeywords = await Keyword.findAll({
154154
where: {
155155
platform_id: {
156156
[Op.or]: [null, ''],
@@ -172,7 +172,7 @@ export class AutoReplyController {
172172
}) {
173173
try {
174174
const { rows: autoReplies, count: total } =
175-
await AutoReply.findAndCountAll({
175+
await Keyword.findAndCountAll({
176176
where: platformId
177177
? {
178178
platform_id: platformId,

src/main/backend/controllers/platformConfigController.ts

-68
This file was deleted.

src/main/backend/controllers/sessionController.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,22 @@ export class SessionCreate {
1717
}
1818

1919
export class SessionController {
20-
async create(sessionData: SessionCreate) {
21-
// @ts-ignore
22-
return Session.create(sessionData);
20+
async createSession(
21+
platformId: string,
22+
platformName: string,
23+
username?: string,
24+
goodsName?: string,
25+
goodsAvatar?: string,
26+
): Promise<Session> {
27+
return Session.create({
28+
platform_id: platformId,
29+
platform: platformName,
30+
username: username || '',
31+
last_active: new Date(),
32+
goods_name: goodsName || '',
33+
goods_avatar: goodsAvatar || '',
34+
created_at: new Date(),
35+
});
2336
}
2437

2538
async update(id: number, sessionData: Session) {

0 commit comments

Comments
 (0)