Skip to content

Commit

Permalink
3.9.10.19 init
Browse files Browse the repository at this point in the history
  • Loading branch information
atorber committed Jun 6, 2024
1 parent cee7c00 commit 2e8b70f
Show file tree
Hide file tree
Showing 5 changed files with 973 additions and 2,489 deletions.
98 changes: 98 additions & 0 deletions examples/raw-sidecar-hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/* eslint-disable no-console */

/**
* Wechaty - https://github.com/wechaty/wechaty
*
* @copyright 2021 Wechaty Contributors <https://github.com/wechaty>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import {
attach,
detach,
} from 'sidecar'

import {
WeChatSidecar,
// XpSidecar
} from '../src/wechat-sidecar.js'

async function main () {
console.info('WeChat Sidecar starting...')
// new XpSidecar({ wechatVersion: '3.9.2.23' })

const sidecar = new WeChatSidecar()
await attach(sidecar)

console.info('WeChat Sidecar started.')

sidecar.on('hook', ({ method, args }) => {
// console.log(`onhook事件消息:${new Date().toLocaleString()}\n`, method, JSON.stringify(args))
console.log(`onhook事件消息:${new Date().toLocaleString()}`, method)
switch (method) {
case 'recvMsg':{
void onRecvMsg(args)
break
}
case 'checkQRLogin':
break
case 'loginEvent':{
break
}
case 'agentReady':
console.log('agentReady...')
break
default:
console.info('onHook没有匹配到处理方法:', method, JSON.stringify(args))
break
}
})

const onRecvMsg = async (args: any) => {
console.info('onRecvMsg事件触发:', JSON.stringify(args))

if (args instanceof Error) {
console.error('onRecvMsg: 参数错误 Error', args)
return
}

const toId = String(args[3])
const text = String(args[2])
const talkerId = String(args[1])

// const nickname = await sidecar.GetContactOrChatRoomNickname(talkerId)
// console.log('发言人昵称:', nickname)
console.info('talkerId:', talkerId)
console.info('toId:', toId)
console.info('text:', text)
if (talkerId && text === 'ding') {
console.info('叮咚测试: ding found, reply dong')
await sidecar.sendMsg(talkerId || toId, 'dong')
// await sidecar.sendAtMsg(toId, 'dong',talkerId)
}
}

const clean = () => {
console.info('Sidecar detaching...')
void detach(sidecar)
}

process.on('SIGINT', clean)
process.on('SIGTERM', clean)
}

main()
.catch(e => {
console.error('主函数运行失败:', e)
})
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
"start:raw": "cross-env BROLOG_LEVEL=silly NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/raw-sidecar.ts",
"start:raw:nobuild": "cross-env BROLOG_LEVEL=info NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/raw-sidecar.ts",
"start:raw:info": "npm run build:agent && cross-env BROLOG_LEVEL=info NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/raw-sidecar.ts",
"start:raw:hook": "npm run build:agent && cross-env BROLOG_LEVEL=info NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/raw-sidecar-hook.ts",
"start:xp:3.9.10.19": "frida -l src/init-agent-script.js WeChat.exe",
"start:ripe": "cross-env WECHATY_LOG=verbose NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/ripe-wechaty.ts",
"start:ripe:info": "npm run build:agent && cross-env WECHATY_LOG=info NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/ripe-wechaty.ts",
"start:ripe:demo": "npm run build:agent && cross-env WECHATY_LOG=info NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/demo.ts",
Expand Down Expand Up @@ -83,8 +85,9 @@
"wechaty-puppet": "^1.10.2"
},
"dependencies": {
"@swc/core": "^1.5.25",
"cuid": "^2.1.8",
"sidecar": "^0.17.8",
"sidecar": "^1.0.19",
"xml2js": "^0.4.23",
"xmlreader": "^0.2.3"
},
Expand Down
Loading

0 comments on commit 2e8b70f

Please sign in to comment.