代码拉取完成,页面将自动刷新
import {
botName,
roomWhiteList,
aliasWhiteList
} from '../../config.js';
import {
getServe
} from './serve.js';
/**
* 默认消息发送
* @param msg
* @param bot
* @param ServiceType 服务类型 'GPT' | 'Kimi'
* @returns {Promise<void>}
*/
export async function defaultMessage(msg, bot, ServiceType = 'GPT') {
const getReply = getServe(ServiceType)
const contact = msg.talker() // 发消息人
const receiver = msg.to() // 消息接收人
const content = msg.text() // 消息内容
const room = msg.room() // 是否是群消息
const roomName = (await room?.topic()) || null // 群名称
const alias = (await contact.alias()) || (await contact.name()) // 发消息人昵称
const remarkName = await contact.alias() // 备注名称
const name = await contact.name() // 微信名称
const isText = msg.type() === bot.Message.Type.Text; // 消息类型是否为文本
const isImage = msg.type() == bot.Message.Type.Image;
const isRoom = roomWhiteList.includes(roomName) && content.includes(`${botName}`) // 是否在群聊白名单内并且艾特了机器人
const isAlias = aliasWhiteList === '*' ? true : (aliasWhiteList.includes(remarkName) || aliasWhiteList.includes(name)) // 发消息的人是否在联系人白名单内
const isBotSelf = botName === remarkName || botName === name // 是否是机器人自己
// TODO 你们可以根据自己的需求修改这里的逻辑
// if (isBotSelf || !isText) return // 如果是机器人自己发送的消息或者消息类型不是文本则不处理
if (isBotSelf) return // 如果是机器人自己发送的消息或者消息类型不是文本则不处理
const options = {
msg,
bot,
type: ({
[bot.Message.Type.Text]: 'text',
// 豆包大模型接图片
...(ServiceType === 'Doubao' ? {
[bot.Message.Type.Image]: 'image',
[bot.Message.Type.Video]: 'video',
[bot.Message.Type.Audio]: 'audio'
} : {})
})[msg.type()],
};
if (!options.type) {
return;
}
try {
// 区分群聊和私聊
if (isRoom && room) {
const question = await msg.mentionText() || content.replace(`${botName}`, ''); // 去掉艾特的消息主体
console.log('🌸🌸🌸 / question: ', question);
const response = await getReply(question, options);
console.log('🚀🚀🚀 / reply', response);
await room.say(response);
}
// 私人聊天,白名单内的直接发送
if (isAlias && !room) {
console.log('🌸🌸🌸 / content: ', content);
const response = await getReply(content, options);
console.log('🚀🚀🚀 / reply', response);
await contact.say(response);
}
} catch (e) {
console.error('defaultMessage in error: ', e);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。