Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
leo committed Dec 22, 2024
1 parent 22623fe commit fabb4af
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wechaty-web-panel",
"version": "1.6.71",
"version": "1.6.72",
"description": "智能微秘书插件",
"exports": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion src/common/hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { delay } from "../lib/index.js";
* @returns {Promise<boolean>}
*/
export async function privateForward({ that, msg, name, config }) {
const { role } = config?.userInfo
const { role } = config?.userInfo || {}
const privateForwards = config.privateForwards
if(role !== 'vip' || !privateForwards || !privateForwards.length || msg.text().includes('请在手机上查看]')) return false
let result = false
Expand Down
8 changes: 4 additions & 4 deletions src/db/configDb.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import nedb from './nedb.js'

const cdb = nedb()
/**
* 添加配置文件
Expand All @@ -20,11 +21,10 @@ async function updateConfig(config) {
try {
let res = await allConfig()
if (res) {
let up = await cdb.update({ id: config.id }, config)
return up
await cdb.remove({ id: config.id }, { multi: true })
return await addConfig(config)
} else {
let add = await addConfig(config)
return add
return await addConfig(config)
}
} catch (error) {
console.log('配置文件更新失败', error)
Expand Down
3 changes: 0 additions & 3 deletions src/db/global.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { getGptConfigById, updateAllGptConfig, updateOneGptConfig } from "./gptConfig.js";
import onVerifyCode from "../handlers/on-verifycode.js";

class Config {
constructor(){
this.apiKey = '';
Expand Down
71 changes: 57 additions & 14 deletions src/service/event-dispatch-service.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
import { getRubbishType, getMingYan, getSweetWord, getStar, getNews, getXing, getSkl, getLunar, getGoldReply, getXhy, getRkl, getEmo, getCname, getResByTX } from '../proxy/api.js'
import { getConfig, getMeiNv, getWordCloudConfig, getCustomEvents } from '../proxy/aibotk.js'
import { getConstellation, msgArr, getNewsType } from '../lib/index.js'
import { initTaskLocalSchedule, initTimeSchedule, initMultiTask } from "../task/index.js";
import { updateContactAndRoom, updateContactOnly, updateRoomOnly } from '../common/index.js'
import { getTencentOpenReply } from '../proxy/tencent-open.js'
import { removeRecord } from "../db/roomDb.js";
import { getGptOfficialReply, reset as officialReset, getSimpleGptReply } from "../proxy/openAi.js";
import { getDifyReply, reset as difyReset, getDifySimpleReply } from "../proxy/difyAi.js";
import { getCozeV3Reply, reset as cozeV3Reset, getCozeV3SimpleReply } from "../proxy/cozeV3Ai.js";
import { getCozeReply, reset as cozeReset, getCozeSimpleReply } from '../proxy/cozeAi.js'
import { getQAnyReply, reset as qanyReset, getQAnySimpleReply } from '../proxy/qAnyAi.js'
import { outApi } from '../proxy/outapi.js'
import {
getCname,
getEmo,
getGoldReply,
getLunar,
getMingYan,
getNews,
getResByTX,
getRkl,
getRubbishType,
getSkl,
getStar,
getSweetWord,
getXhy,
getXing
} from '../proxy/api.js'
import {getConfig, getCustomEvents, getMeiNv, getWordCloudConfig} from '../proxy/aibotk.js'
import {getConstellation, getNewsType, msgArr} from '../lib/index.js'
import {initMultiTask, initTaskLocalSchedule, initTimeSchedule} from "../task/index.js";
import {roomSay, updateContactAndRoom, updateContactOnly, updateRoomOnly} from '../common/index.js'
import {getTencentOpenReply} from '../proxy/tencent-open.js'
import {removeRecord} from "../db/roomDb.js";
import {getGptOfficialReply, getSimpleGptReply, reset as officialReset} from "../proxy/openAi.js";
import {getDifyReply, getDifySimpleReply, reset as difyReset} from "../proxy/difyAi.js";
import {getCozeV3Reply, getCozeV3SimpleReply, reset as cozeV3Reset} from "../proxy/cozeV3Ai.js";
import {getCozeReply, getCozeSimpleReply, reset as cozeReset} from '../proxy/cozeAi.js'
import {getQAnyReply, reset as qanyReset} from '../proxy/qAnyAi.js'
import {outApi} from '../proxy/outapi.js'
import {getUser} from "../db/userDb.js";

/**
Expand All @@ -22,7 +37,7 @@ import {getUser} from "../db/userDb.js";
* @param avatar
* @returns {string} 内容
*/
async function dispatchEventContent(that, eName, msg, name, id, avatar, room, roomName, sourceMsg) {
async function dispatchEventContent(that, eName, msg, name, id, avatar, room, roomName, sourceMsg, contact, eventInfo) {
try {
let content = '',
type = 1,
Expand Down Expand Up @@ -130,6 +145,34 @@ async function dispatchEventContent(that, eName, msg, name, id, avatar, room, ro
cozeV3Reset();
content = '更新配置成功,请稍等一分钟后生效'
break
case 'autoRoomCreate':
console.log('触发创建群聊指令,拉取用户并创建群聊')
const roomMembers = [contact]
const creatInfo = eventInfo?.otherInfo || { members: [], name: '', welcomes: [], tips: '' }
for (let member of creatInfo.members) {
console.log('member', member)
const target = member.id && (await that.Contact.find({id: member.id})) || member.name && (await that.Contact.find({name: member.name})); // 获取你要发送的联系人
if (target) {
roomMembers.push(target)
} else {
console.log(`没有查找到你预设进群的用户:${member.name},请确保是机器人的好友`)
}
}
that.Room.create(roomMembers, creatInfo.name || '').then((room)=> {
if (room) {
console.log('创建群聊成功')
if(creatInfo.welcomes && creatInfo.welcomes.length) {
for (let welcome of creatInfo.welcomes) {
void roomSay.call(that, room, contact, welcome)
}
}
}
}).catch(e => {
console.log('创建群聊失败', e)
})

content = creatInfo.tips || '正在拉您进群,请稍后...'
break;
default:
break
}
Expand Down
8 changes: 4 additions & 4 deletions src/service/msg-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ async function scheduleJobMsg({ that, msg, name }) {
* @param avatar 用户头像
* @returns {String}
*/
async function getEventReply(that, event, msg, name, id, avatar, room, roomName, sourceMsg) {
async function getEventReply(that, event, msg, name, id, avatar, room, roomName, sourceMsg, contact, eventInfo) {
try {
let reply = await dispatch.dispatchEventContent(that, event, msg, name, id, avatar, room, roomName, sourceMsg)
let reply = await dispatch.dispatchEventContent(that, event, msg, name, id, avatar, room, roomName, sourceMsg, contact, eventInfo)
return reply
} catch (e) {
console.log('getEventReply error', e)
Expand Down Expand Up @@ -192,7 +192,7 @@ async function callbackEvent({ that, msg, name, id, config, room, isMention }) {
}
}

async function eventMsg({ that, msg, name, id, avatar, config, room, isMention, roomName }) {
async function eventMsg({ that, msg, name, id, avatar, config, room, isMention, roomName, contact }) {
try {
for (let item of config.eventKeywords) {
for (let key of item.keywords) {
Expand All @@ -202,7 +202,7 @@ async function eventMsg({ that, msg, name, id, avatar, config, room, isMention,
return []
}
const replaceMsg = msg.replace(key, '')
let res = await getEventReply(that, item.event, replaceMsg, name, id, avatar, room, roomName, msg)
let res = await getEventReply(that, item.event, replaceMsg, name, id, avatar, room, roomName, msg, contact, item)
return res
}
}
Expand Down

0 comments on commit fabb4af

Please sign in to comment.