Skip to content

Commit

Permalink
3.9.10.19 init (#233)
Browse files Browse the repository at this point in the history
* 3.9.2.23 init (#180)

* 3.9.2.23 initt

* Update init-agent-script.js

* 3.9.2.23 adapter

* 3.9.2.23 init (#182)

* 3.9.2.23 initt

* Update init-agent-script.js

* 3.9.2.23 adapter

* 适配3.9.2.23

* Delete agent-script-3.9.2.23-new.js

* 适配3.9.2.23 (#185)

* 3.9.2.23 initt

* Update init-agent-script.js

* 3.9.2.23 adapter

* 适配3.9.2.23

* Delete agent-script-3.9.2.23-new.js

* 适配3.9.2.23

---------

Co-authored-by: LuChao <[email protected]>

* add 1.3.0 illustrate

* Update README.md

* Update README.md

* add demo

* 1.13.1

* 1.13.1

* 1.13.2 dev

* 增加扫码登录、检测登录状态

* 增加登入登出事件

* 增加ts改造init

* 1.13.2

* 1.13.2

* 1.13.2

* 1.13.2

* 1.13.2

1. 修复获取群成员昵称乱码

* Update .npmignore

* Update .gitignore

* 1.13.2删除agent的ts文件

* 1.13.4

* 1.13.5

* Update init-agent-script.ts

* 1.13.5

* 1.13.6

* del png file

* Update init-agent-script.js

* 1.13.7 修复@好友出现两个昵称的bug

* 1.13.7 修复@好友昵称重复bug (#209)

* 3.9.2.23 init (#180)

* 3.9.2.23 initt

* Update init-agent-script.js

* 3.9.2.23 adapter

* 3.9.2.23 init (#182)

* 3.9.2.23 initt

* Update init-agent-script.js

* 3.9.2.23 adapter

* 适配3.9.2.23

* Delete agent-script-3.9.2.23-new.js

* 适配3.9.2.23 (#185)

* 3.9.2.23 initt

* Update init-agent-script.js

* 3.9.2.23 adapter

* 适配3.9.2.23

* Delete agent-script-3.9.2.23-new.js

* 适配3.9.2.23

---------

Co-authored-by: LuChao <[email protected]>

* add 1.3.0 illustrate

* Update README.md

* Update README.md

* add demo

* 1.13.1

* 1.13.1

* 1.13.2 dev

* 增加扫码登录、检测登录状态

* 增加登入登出事件

* 增加ts改造init

* 1.13.2

* 1.13.2

* 1.13.2

* 1.13.2

* 1.13.2

1. 修复获取群成员昵称乱码

* Update .npmignore

* Update .gitignore

* 1.13.2删除agent的ts文件

* 1.13.4

* 1.13.5

* Update init-agent-script.ts

* 1.13.5

* 1.13.6

* del png file

* Update init-agent-script.js

* 1.13.7 修复@好友出现两个昵称的bug

---------

Co-authored-by: choogoo <[email protected]>

* 1.13.7

* Update README.md

* 1.13.8

* 3.9.10.19 init

* 3.9.10.19 init

1. Support WeChat version 3.9.10.19
2. Support list
    - getMyselfInfo
    - sendMsg
    - recvMsg

* Update package.json

---------

Co-authored-by: choogoo <[email protected]>
  • Loading branch information
atorber and choogoo authored Jun 7, 2024
1 parent 2cd0438 commit 8ee6ac5
Show file tree
Hide file tree
Showing 8 changed files with 1,078 additions and 2,568 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ puppet-xp|wechat|npm install|

## HISTORY

### v2.0.0

1. Support WeChat version 3.9.10.19
2. Support list
- getMyselfInfo
- sendMsg
- recvMsg

### v1.13.12

1. Fixed the bug where the system crashes upon receiving a message before successful startup
Expand Down
102 changes: 102 additions & 0 deletions examples/raw-sidecar-hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/* 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')
try {
await sidecar.sendMsg(talkerId || toId, 'dong')
// await sidecar.sendAtMsg(toId, 'dong',talkerId)
} catch (e) {
console.error('发送消息失败:', e)
}
}
}

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

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

main()
.catch(e => {
console.error('主函数运行失败:', e)
})
88 changes: 44 additions & 44 deletions examples/raw-sidecar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ async function main () {

console.info('WeChat Sidecar started.')

const ver = await sidecar.getWeChatVersion()
const verStr = await sidecar.getWechatVersionString()
const isSupported = await sidecar.checkSupported()
console.info(`\nWeChat Version: ${ver} -> ${verStr} , Supported: ${isSupported}\n`)
// const ver = await sidecar.getWeChatVersion()
// const verStr = await sidecar.getWechatVersionString()
// const isSupported = await sidecar.checkSupported()
// console.info(`\nWeChat Version: ${ver} -> ${verStr} , Supported: ${isSupported}\n`)

const isLoggedIn = await sidecar.isLoggedIn()
// const isLoggedIn = await sidecar.isLoggedIn()
const myselfInfo = await sidecar.getMyselfInfo()
console.info(`当前登陆账号信息: ${myselfInfo}`)

const loginUrl = await sidecar.getLoginUrl()
console.info(`登陆二维码地址loginUrl: ${loginUrl}`)
// const loginUrl = await sidecar.getLoginUrl()
// console.info(`登陆二维码地址loginUrl: ${loginUrl}`)

// const contact = await sidecar.getChatroomMemberInfo()
// //console.log(contact)
Expand All @@ -74,18 +74,18 @@ async function main () {
void onScan(args)
break
case 'loginEvent':{
if (!isLoggedIn) {
let loginRes = false
sidecar.isLoggedIn().then(res => {
loginRes = res
if (loginRes) {
void onLogin()
}
return res
}).catch(e => {
console.error('登录状态检查失败:', e)
})
}
// if (!isLoggedIn) {
// let loginRes = false
// sidecar.isLoggedIn().then(res => {
// loginRes = res
// if (loginRes) {
// void onLogin()
// }
// return res
// }).catch(e => {
// console.error('登录状态检查失败:', e)
// })
// }
break
}
case 'agentReady':
Expand All @@ -100,31 +100,31 @@ async function main () {
}
})

const onLogin = async () => {
console.info('登陆事件触发')
console.info(`登陆状态: ${isLoggedIn}`)
// await sidecar.sendMsg('filehelper', 'Sidecar is ready!')
const contacts = await sidecar.getContact()
// console.log(`contacts: ${contacts}`)
const contactsJSON = JSON.parse(contacts)
console.log('contacts列表:', contactsJSON.length)

for (const contact of contactsJSON) {
if (!contact.name) {
console.info('好友:', JSON.stringify(contact))
}
}
// const onLogin = async () => {
// console.info('登陆事件触发')
// console.info(`登陆状态: ${isLoggedIn}`)
// await sidecar.sendMsg('filehelper', 'Sidecar is ready!')
// const contacts = await sidecar.getContact()
// console.log(`contacts: ${contacts}`)
// const contactsJSON = JSON.parse(contacts)
// console.log('contacts列表:', contactsJSON.length)

// for (const contact of contactsJSON) {
// if (!contact.name) {
// console.info('好友:', JSON.stringify(contact))
// }
// }

const roomList = await sidecar.getChatroomMemberInfo()
// console.log(`roomList: ${roomList}`)
const roomListJSON = JSON.parse(roomList)
console.log('roomList列表:', roomListJSON.length)
// for (const room of roomListJSON) {
// console.info('room:', room)
// }
// await sidecar.sendAtMsg('21341182572@chatroom', new Date().toLocaleString(), 'atorber', '超哥');
// const roomList = await sidecar.getChatroomMemberInfo()
// console.log(`roomList: ${roomList}`)
// const roomListJSON = JSON.parse(roomList)
// console.log('roomList列表:', roomListJSON.length)
// for (const room of roomListJSON) {
// console.info('room:', room)
// }
// await sidecar.sendAtMsg('21341182572@chatroom', new Date().toLocaleString(), 'atorber', '超哥');

}
// }

const onLogout = (bySrv: number) => {
console.info('登出事件触发:', bySrv)
Expand Down Expand Up @@ -170,8 +170,8 @@ async function main () {
// const nickname = await sidecar.GetContactOrChatRoomNickname(talkerId)
// console.log('发言人昵称:', nickname)

const talker = await sidecar.getChatroomMemberNickInfo(talkerId, toId)
console.log('发言人:', talker)
// const talker = await sidecar.getChatroomMemberNickInfo(talkerId, toId)
// console.log('发言人:', talker)
if (talkerId && text === 'ding') {
console.info('叮咚测试: ding found, reply dong')
await sidecar.sendMsg(toId, 'dong')
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wechaty-puppet-xp",
"version": "1.13.12",
"version": "2.0.0",
"description": "Puppet XP for Wechaty",
"type": "module",
"exports": {
Expand Down Expand Up @@ -29,6 +29,7 @@
"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: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 +84,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 8ee6ac5

Please sign in to comment.