Skip to content

Commit 905f0da

Browse files
atorberchoogoo
andauthored
1.13.2 (#199)
* 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. 修复获取群成员昵称乱码 --------- Co-authored-by: choogoo <[email protected]>
1 parent 724138a commit 905f0da

17 files changed

+4100
-1047
lines changed

.eslintrc.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const rules = {
2+
"no-shadow": "off"
23
}
34

45
module.exports = {
56
extends: '@chatie',
7+
"ignorePatterns": ["src/init-agent-script.ts", "src/init-agent-script.js"],
68
rules,
79
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,4 @@ typings/
6565
t/
6666
t.*
6767
cache/*
68+
src/init-agent-script.js

examples/ding-dong-bot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ function onScan (payload: PUPPET.payloads.EventScan) {
7474
'https://wechaty.js.org/qrcode/',
7575
encodeURIComponent(payload.qrcode),
7676
].join('')
77-
console.info('StarterBot', 'onScan: %s(%s) - %s', payload.status, qrcodeImageUrl)
77+
console.info('onScan: %s(%s) - %s', payload.status, qrcodeImageUrl)
7878

7979
qrcodeTerminal.generate(payload.qrcode, { small: true }) // show qrcode on console
8080
console.info(`[${payload.status}] ${payload.qrcode}\nScan QR Code above to log in: `)
Loading
Loading
Loading

examples/quick-start.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function onScan(qrcode: string, status: ScanStatus) {
2121
'https://wechaty.js.org/qrcode/',
2222
encodeURIComponent(qrcode),
2323
].join('')
24-
console.info('StarterBot', 'onScan: %s(%s) - %s', status, qrcodeImageUrl)
24+
console.info('onScan: %s(%s) - %s', status, qrcodeImageUrl)
2525

2626
qrcodeTerminal.generate(qrcode, { small: true }) // show qrcode on console
2727
console.info(`[${status}] ${qrcode}\nScan QR Code above to log in: `)
@@ -31,7 +31,7 @@ function onScan(qrcode: string, status: ScanStatus) {
3131
}
3232

3333
async function onLogin(user: Contact) {
34-
log.info('StarterBot', '%s login', user)
34+
log.info('onLogin', '%s login', user)
3535
const roomList = await bot.Room.findAll()
3636
console.info('room count:', roomList.length)
3737

examples/raw-sidecar.ts

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable no-console */
2+
13
/**
24
* Wechaty - https://github.com/wechaty/wechaty
35
*
@@ -21,10 +23,14 @@ import {
2123
detach,
2224
} from 'sidecar'
2325

24-
import { WeChatSidecar } from '../src/wechat-sidecar.js'
26+
import {
27+
WeChatSidecar,
28+
// XpSidecar
29+
} from '../src/wechat-sidecar.js'
2530

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

2935
const sidecar = new WeChatSidecar()
3036
await attach(sidecar)
@@ -36,39 +42,84 @@ async function main() {
3642
const isSupported = await sidecar.checkSupported()
3743
console.info(`\nWeChat Version: ${ver} -> ${verStr} , Supported: ${isSupported}\n`)
3844

39-
const isLoggedIn = await sidecar.isLoggedIn()
40-
console.info(`has Logged In: ${isLoggedIn}`)
45+
const isLoggedIn = false
4146
const myselfInfo = await sidecar.getMyselfInfo()
42-
console.info(`myInfo: ${myselfInfo}`)
43-
44-
sidecar.on('hook', ({ method, args }) => {
45-
47+
console.info(`当前登陆账号信息: ${myselfInfo}`)
48+
49+
const loginUrl = await sidecar.getLoginUrl()
50+
console.info(`登陆二维码地址loginUrl: ${loginUrl}`)
51+
52+
// const contact = await sidecar.getChatroomMemberInfo()
53+
// //console.log(contact)
54+
// for (const item of JSON.parse(contact)) {
55+
// for(const wxid of item.roomMember){
56+
// //console.log(wxid)
57+
// if(wxid === 'tyutluyc'){
58+
// const nick = await sidecar.getChatroomMemberNickInfo(wxid,item.roomid)
59+
// console.log('wxid:====',wxid,"==nick:===",nick)
60+
// }
61+
// }
62+
63+
// }
64+
65+
sidecar.on('hook', async ({ method, args }) => {
66+
// console.log(`onhook事件消息:${new Date().toLocaleString()}\n`, method, JSON.stringify(args))
67+
console.log(`onhook事件消息:${new Date().toLocaleString()}`, method)
4668
switch (method) {
4769
case 'recvMsg':
4870
void onRecvMsg(args)
4971
break
5072
case 'checkQRLogin':
5173
onScan(args)
5274
break
53-
case 'loginEvent':
54-
onLogin()
75+
case 'loginEvent':{
76+
if(!isLoggedIn){
77+
const loginRes = await sidecar.isLoggedIn()
78+
if(loginRes){
79+
onLogin()
80+
}
81+
}
82+
break
83+
}
84+
case 'agentReady':
85+
console.log('agentReady...')
5586
break
5687
case 'logoutEvent':
5788
onLogout(args[0] as number)
5889
break
59-
6090
default:
61-
console.info('onHook', method, JSON.stringify(args))
91+
console.info('onHook没有匹配到处理方法:', method, JSON.stringify(args))
6292
break
6393
}
6494

6595
})
6696

67-
const onLogin = () => {
68-
console.info('You are logged in.')
97+
const onLogin = async () => {
98+
console.info('登陆事件触发')
99+
console.info(`登陆状态: ${isLoggedIn}`)
100+
// await sidecar.sendMsg('filehelper', 'Sidecar is ready!')
101+
const contacts = await sidecar.getContact()
102+
// console.log(`contacts: ${contacts}`)
103+
const contactsJSON = JSON.parse(contacts)
104+
console.log('contacts列表:', contactsJSON.length)
105+
106+
for (const contact of contactsJSON) {
107+
if(!contact.name) {
108+
console.info('好友:', JSON.stringify(contact))
109+
}
110+
}
111+
112+
const roomList = await sidecar.getChatroomMemberInfo()
113+
// console.log(`roomList: ${roomList}`)
114+
const roomListJSON = JSON.parse(roomList)
115+
console.log('roomList列表:', roomListJSON.length)
116+
// for (const room of roomListJSON) {
117+
// console.info('room:', room)
118+
// }
69119
}
70120

71121
const onLogout = (bySrv: number) => {
122+
console.info('登出事件触发:', bySrv)
72123
console.info(`You are logged out${bySrv ? ' because you were kicked by server.' : ''}.`)
73124
}
74125

@@ -97,22 +148,24 @@ async function main() {
97148
}
98149

99150
const onRecvMsg = async (args: any) => {
100-
console.info('recvMsg:', args)
151+
console.info('onRecvMsg事件触发:', JSON.stringify(args))
101152

102153
if (args instanceof Error) {
103-
console.error(args)
154+
console.error('onRecvMsg: 参数错误 Error', args)
104155
return
105156
}
106157

107158
const toId = String(args[1])
108159
const text = String(args[2])
109160
const talkerId = String(args[3])
110161

111-
console.info('recvMsg: talkerId =', talkerId)
112-
console.info('recvMsg: text =', text)
162+
// const nickname = await sidecar.GetContactOrChatRoomNickname(talkerId)
163+
// console.log('发言人昵称:', nickname)
113164

165+
const talker = await sidecar.getChatroomMemberNickInfo(talkerId,toId)
166+
console.log('发言人:', talker)
114167
if (talkerId && text === 'ding') {
115-
console.info('recvMsg: ding found, reply dong')
168+
console.info('叮咚测试: ding found, reply dong')
116169
await sidecar.sendMsg(toId, 'dong')
117170
// await sidecar.sendAtMsg(toId, 'dong',talkerId)
118171
}
@@ -128,4 +181,6 @@ async function main() {
128181
}
129182

130183
main()
131-
.catch(console.error)
184+
.catch(e=>{
185+
console.error('主函数运行失败:', e)
186+
})

examples/ripe-wechaty.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,48 @@ import { FileBox } from 'file-box'
1414

1515
import { PuppetXp } from '../src/puppet-xp.js'
1616
import qrcodeTerminal from 'qrcode-terminal'
17-
import fs from 'fs'
17+
import * as fs from 'fs'
1818

1919
function onScan (qrcode: string, status: ScanStatus) {
2020
if (qrcode) {
2121
const qrcodeImageUrl = [
2222
'https://wechaty.js.org/qrcode/',
2323
encodeURIComponent(qrcode),
2424
].join('')
25-
console.info('StarterBot', 'onScan: %s(%s) - %s', status, qrcodeImageUrl)
25+
log.info('onScan', '%s(%s) - %s', status, qrcodeImageUrl)
2626

2727
qrcodeTerminal.generate(qrcode, { small: true }) // show qrcode on console
28-
console.info(`[${status}] ${qrcode}\nScan QR Code above to log in: `)
28+
log.info(`[${status}] ${qrcode}\nScan QR Code above to log in: `)
2929
} else {
30-
console.info(`[${status}]`)
30+
log.info(`[${status}]`)
3131
}
3232
}
3333

3434
async function onLogin (user: Contact) {
35-
log.info('StarterBot', '%s login', user)
35+
log.info('onLogin', '%s login', user)
3636
const roomList = await bot.Room.findAll()
37-
console.info(roomList.length)
37+
log.info('群数量:', roomList.length)
3838
const contactList = await bot.Contact.findAll()
39-
console.info(contactList.length)
39+
log.info('联系人数量:', contactList.length)
40+
const friends = contactList.filter(c => c.friend())
41+
log.info('好友数量:', friends.length)
4042
}
4143

4244
function onLogout (user: Contact) {
43-
log.info('StarterBot', '%s logout', user)
45+
log.info('onLogout', '%s logout', user)
4446
}
4547

4648
async function onMessage (msg: Message) {
47-
log.info('StarterBot', msg.toString())
49+
// log.info('onMessage', msg.toString())
50+
log.info('接收到消息:', JSON.stringify(msg))
51+
const contact = msg.talker()
52+
log.info('当前联系人信息:', JSON.stringify(contact))
53+
const room = msg.room()
54+
if(room){
55+
log.info('当前群信息:', await room.topic())
56+
log.info('当前群群主:', JSON.stringify(room.owner()))
57+
}
58+
4859
if (msg.text() === 'ding') {
4960
await msg.say('dong')
5061
}
@@ -96,21 +107,25 @@ async function onMessage (msg: Message) {
96107
// Log other non-text messages
97108
const logData = {
98109
date: new Date(),
99-
from: msg.talker().name(),
110+
talker: msg.talker(),
111+
listener: msg.listener(),
112+
room:await msg.room(),
100113
text: msg.text(),
101114
type: msg.type(),
102115
}
103-
const logPath = 'examples/log/message.log'
116+
117+
const logPath = 'examples/file/message.log'
104118
fs.appendFileSync(logPath, JSON.stringify(logData, null, 2) + '\n')
105-
log.info(`Logged message data to ${logPath}`)
119+
120+
log.info(`日志查看路径: ${logPath}`)
106121
}
107122
} catch (e) {
108-
console.error(`Error handling message: ${e}`)
123+
log.error(`Error handling message: ${e}`)
109124
}
110125

111126
}
112127

113-
const puppet = new PuppetXp()
128+
const puppet = new PuppetXp({wechatVersion:'0.0.0.0'})
114129
const bot = WechatyBuilder.build({
115130
name: 'ding-dong-bot',
116131
puppet,
@@ -137,12 +152,12 @@ bot.on('room-invite', async roomInvitation => {
137152
log.info('received room-invite event.')
138153
await roomInvitation.accept()
139154
} catch (e) {
140-
console.error(e)
155+
log.error('处理进群申请信息错误:', e)
141156
}
142157
})
143158

144159
bot.start()
145160
.then(() => {
146161
return log.info('StarterBot', 'Starter Bot Started.')
147162
})
148-
.catch(console.error)
163+
.catch(log.error)

package.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wechaty-puppet-xp",
3-
"version": "1.13.1",
3+
"version": "1.13.2",
44
"description": "Puppet XP for Wechaty",
55
"type": "module",
66
"exports": {
@@ -17,28 +17,31 @@
1717
"scripts": {
1818
"clean": "shx rm -fr dist/*",
1919
"dist": "npm-run-all clean build dist:copy dist:commonjs",
20+
"build:agent": "tsc src/init-agent-script.ts --outFile src/init-agent-script.js",
2021
"build": "tsc && tsc -p tsconfig.cjs.json",
22+
"build:agent": "tsc src/init-agent-script.ts --outFile src/init-agent-script.js",
2123
"dist:commonjs": "jq -n \"{ type: \\\"commonjs\\\" }\" > dist/cjs/package.json",
2224
"dist:copy": "npm-run-all copy:esm copy:cjs",
2325
"copy:esm": "shx cp -R commonjs/ dist/esm/ && shx cp src/init-agent-script.js dist/esm/src",
2426
"copy:cjs": "shx cp -R commonjs/ dist/cjs/ && shx cp src/init-agent-script.js dist/cjs/src",
2527
"start": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/ding-dong-bot.ts",
2628
"quick-start": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/quick-start.ts",
2729
"start:raw": "cross-env BROLOG_LEVEL=silly NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/raw-sidecar.ts",
30+
"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",
2831
"start:ripe": "cross-env WECHATY_LOG=verbose NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/ripe-wechaty.ts",
29-
"start:ripe:info": "cross-env WECHATY_LOG=info NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" node examples/ripe-wechaty.ts",
32+
"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",
3033
"lint": "npm run lint:es && npm run lint:ts && npm run lint:md",
3134
"lint:md": "markdownlint README.md",
3235
"lint:ts": "tsc --isolatedModules --noEmit",
3336
"lint:es": "eslint \"src/**/*.ts\" \"tests/**/*.spec.ts\" --ignore-pattern tests/fixtures/",
34-
"lint-fix": "eslint --fix \"src/**/*.ts\" \"tests/**/*.spec.ts\"",
37+
"lint:fix": "eslint --fix \"src/**/*.ts\" \"tests/**/*.spec.ts\"",
3538
"test": "npm run lint && npm run test:unit",
3639
"test:pack": "bash -x scripts/npm-pack-testing.sh",
3740
"test:unit": "cross-env NODE_OPTIONS=\"--no-warnings --loader=ts-node/esm\" tap \"src/**/*.spec.ts\" \"tests/**/*.spec.ts\""
3841
},
3942
"repository": {
4043
"type": "git",
41-
"url": "git+https://github.com/wechaty/wechaty-puppet-mock.git"
44+
"url": "git+https://github.com/wechaty/puppet-xp.git"
4245
},
4346
"keywords": [
4447
"chatie",
@@ -53,23 +56,26 @@
5356
"author": "Huan LI <[email protected]>",
5457
"license": "Apache-2.0",
5558
"bugs": {
56-
"url": "https://github.com/wechaty/wechaty-puppet-mock/issues"
59+
"url": "https://github.com/wechaty/puppet-xp/issues"
5760
},
58-
"homepage": "https://github.com/wechaty/wechaty-puppet-mock#readme",
61+
"homepage": "https://github.com/wechaty/puppet-xp#readme",
5962
"devDependencies": {
6063
"@chatie/eslint-config": "^1.0.4",
6164
"@chatie/git-scripts": "^0.7.7",
6265
"@chatie/semver": "^0.4.7",
6366
"@chatie/tsconfig": "^4.5.3",
6467
"@types/cuid": "^2.0.1",
6568
"@types/faker": "^5.5.9",
66-
"@types/qrcode-terminal": "^0.12.0",
69+
"@types/frida-gum": "^18.5.1",
70+
"@types/node": "^20.10.5",
71+
"@types/qrcode-terminal": "^0.12.2",
6772
"@types/xml2js": "^0.4.9",
73+
"frida-compile": "^16.4.1",
6874
"husky": "^7.0.4",
6975
"qrcode-terminal": "^0.12.0",
7076
"tstest": "^1.0.1",
7177
"typed-emitter": "^1.4.0",
72-
"wechaty": "^1.7.21"
78+
"wechaty": "^1.20.2"
7379
},
7480
"peerDependencies": {
7581
"wechaty-puppet": "^1.10.2"

src/agents/agent-script-3.3.0.115.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const getTestInfoFunction = (() => {
7070

7171
})
7272

73-
// 002 get global data
73+
// 002 get global dataf
7474
const isLoggedInFunction = (() => {
7575
loggedIn = moduleBaseAddress.add(offset.is_logged_in_offset).readU32()
7676
return !!loggedIn

0 commit comments

Comments
 (0)