generated from wechaty/puppet-mock
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
Showing
8 changed files
with
1,078 additions
and
2,568 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.