Skip to content

Commit

Permalink
Use wechat4u, append "via ChatGPT" after response text
Browse files Browse the repository at this point in the history
  • Loading branch information
jazzqi committed Feb 8, 2023
1 parent db50970 commit 6e2e1d8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ WechatEveryDay.memory-card.json
test.js
package-lock.json
yarn.lock
Chromium.app
Chromium.app
config.js
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"remark": "^14.0.2",
"strip-markdown": "^5.0.0",
"wechaty": "^1.20.2",
"wechaty-puppet-wechat": "^1.18.4"
"wechaty-puppet-wechat": "^1.18.4",
"wechaty-puppet-wechat4u": "^1.13.13"
}
}
2 changes: 1 addition & 1 deletion src/openai/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function getOpenAiReply(prompt) {

const reply = markdownToText(response.data.choices[0].text)
console.log('🚀🚀🚀 / reply', reply)
return reply
return `${reply}\nvia ChatGPT`
}

function markdownToText(markdown) {
Expand Down
2 changes: 1 addition & 1 deletion src/wechaty/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async function onMessage(msg) {
export const bot = WechatyBuilder.build({
name: 'WechatEveryDay',
// puppet: 'wechaty-puppet-wechat4u', // 如果有token,记得更换对应的puppet
puppet: 'wechaty-puppet-wechat', // 如果 wechaty-puppet-wechat 存在问题,也可以尝试使用上面的 wechaty-puppet-wechat4u ,记得安装 wechaty-puppet-wechat4u
puppet: 'wechaty-puppet-wechat4u', // 如果 wechaty-puppet-wechat 存在问题,也可以尝试使用上面的 wechaty-puppet-wechat4u ,记得安装 wechaty-puppet-wechat4u
puppetOptions: {
uos: true,
},
Expand Down
10 changes: 8 additions & 2 deletions src/wechaty/sendMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ export async function defaultMessage(msg, bot) {
const isBotSelf = botName === remarkName || botName === name // 是否是机器人自己
// TODO 你们可以根据自己的需求修改这里的逻辑
if (isText && !isBotSelf) {
console.log(JSON.stringify(msg))
if ((Date.now() - 1e3 * msg.payload.timestamp) > 3000) return
if (!content.startsWith('? ') && !content.startsWith('? ') && !content.startsWith('> ')) return
try {
const trimed = content.substr(2)
if (trimed.length < 5) return

// 区分群聊和私聊
if (isRoom && room) {
await room.say(await getReply(content.replace(`${botName}`, '')))
await room.say(await getReply(trimed.replace(`${botName}`, '')))
return
}
// 私人聊天,白名单内的直接发送
if (isAlias && !room) {
await contact.say(await getReply(content))
await contact.say(await getReply(trimed))
}
} catch (e) {
console.error(e)
Expand Down

0 comments on commit 6e2e1d8

Please sign in to comment.