-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
修改 #176
修改 #176
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,15 @@ | ||||
--- | ||||
name: abeiheng | ||||
site: https://github.com/Abeiheng | ||||
avatar: /assets/contributors/abeiheng/avatar.webp | ||||
bio: 前端工程师 热爱技术 后端也会一点 | ||||
email: [email protected] | ||||
--- | ||||
|
||||
前端工程师 热爱技术 后端也会一点 | ||||
|
||||
## Contact me | ||||
|
||||
- Github: <https://github.com/Abeiheng> | ||||
- Email:<> | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The email and website placeholders are left empty. It's important to either provide the relevant information or remove these lines if the information is not available to avoid confusion. - - Email:<>
- - Website: <> Committable suggestion
Suggested change
|
||||
- Website: <> |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,102 @@ | ||||||||
--- | ||||||||
title: "AutoRoom 帮您更好的进行用户自动进群" | ||||||||
author: abeiheng | ||||||||
categories: article | ||||||||
tags: | ||||||||
- blog | ||||||||
- auto-friend | ||||||||
- auto-room | ||||||||
image: /assets/2023/12-blog-auto-friend-auto-room/logo.webp | ||||||||
--- | ||||||||
|
||||||||
WeChaty 是一个基于 Node.js 的开源微信机器人框架,而作为社群管理,需要对好友进行分类让其进入相应的群,通过本篇文章以及Wechaty,你可以创还能一个微信机器人,使其在微信平台上运行。 | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The introduction paragraph could be enhanced for clarity and grammar. Consider revising it to improve readability and provide a more compelling introduction to the topic. - WeChaty 是一个基于 Node.js 的开源微信机器人框架,而作为社群管理,需要对好友进行分类让其进入相应的群,通过本篇文章以及Wechaty,你可以创还能一个微信机器人,使其在微信平台上运行。
+ WeChaty 是一个基于 Node.js 的开源微信机器人框架。本篇文章将介绍如何利用 WeChaty 进行社群管理,包括如何对好友进行分类并让他们加入相应的群聊。通过本文的指导,你将能够创建一个微信机器人,实现在微信平台上的自动化管理。 Committable suggestion
Suggested change
|
||||||||
|
||||||||
Setup: | ||||||||
|
||||||||
我们使用 `wechaty-puppet-padlocal` | ||||||||
|
||||||||
```Text | ||||||||
package.json: | ||||||||
"qrcode-terminal": "^0.12.0", | ||||||||
"wechaty": "^1.19.10", | ||||||||
"wechaty-puppet": "^1.19.6", | ||||||||
"wechaty-puppet-padlocal": "^1.11.18" | ||||||||
``` | ||||||||
|
||||||||
```javascript | ||||||||
import { PuppetPadlocal } from "wechaty-puppet-padlocal"; | ||||||||
import { WechatyBuilder } from "wechaty"; | ||||||||
|
||||||||
const puppet = new PuppetPadlocal({ | ||||||||
token: "放入您的Pad_local申请的TOKEN", | ||||||||
}); | ||||||||
const wechaty = WechatyBuilder.build({ | ||||||||
name: 'auto-room', | ||||||||
puppet | ||||||||
}); | ||||||||
|
||||||||
``` | ||||||||
|
||||||||
以下代码为当私聊接收信息后返回提示 autoRoom 相关代码 | ||||||||
|
||||||||
```javascript | ||||||||
wechaty.on('message', async message => { | ||||||||
const content = msg.text(); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a variable mismatch in the code snippet. The variable - const content = msg.text();
- const talker = msg.talker();
+ const content = message.text();
+ const talker = message.talker(); Committable suggestion
Suggested change
|
||||||||
const talker = msg.talker(); | ||||||||
if (/^加群$/.test(content)) { | ||||||||
const roomList = await bot.Room.findAll(); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable - const roomList = await bot.Room.findAll();
+ const roomList = await wechaty.Room.findAll(); Committable suggestion
Suggested change
|
||||||||
const targetRooms = roomList.filter(async (room: RoomInterface) => { | ||||||||
const topic = await room.topic(); | ||||||||
return topic.startsWith("狼人杀"); | ||||||||
}); | ||||||||
if (targetRooms.length > 0) { | ||||||||
const roomList = targetRooms.map(async (room: RoomInterface) => { | ||||||||
const roomTopic = await room.topic(); | ||||||||
return roomTopic; | ||||||||
}); | ||||||||
const joinedRoomTopics = (await Promise.all(roomList)).join("\n"); | ||||||||
await talker.say(`狼人杀群聊列表:\n${joinedRoomTopics}\n\n请输入要加入的群聊名称`); | ||||||||
} else { | ||||||||
await talker.say("暂时没有狼人杀群聊可加入!"); | ||||||||
} | ||||||||
} | ||||||||
if (/^狼人杀/.test(content)) { | ||||||||
const room = await bot.Room.find({ topic: content }); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous comment, the variable - const room = await bot.Room.find({ topic: content });
+ const room = await wechaty.Room.find({ topic: content }); Committable suggestion
Suggested change
|
||||||||
if (room) { | ||||||||
await room?.add(talker); | ||||||||
} else { | ||||||||
talker.say(`${content}群聊,查找失败`); | ||||||||
} | ||||||||
} | ||||||||
}) | ||||||||
``` | ||||||||
|
||||||||
 | ||||||||
 | ||||||||
|
||||||||
以下代码为当私聊接收信息后返回提示 autoFriend 相关代码 | ||||||||
|
||||||||
```javascript | ||||||||
import { Message } from "wechaty"; | ||||||||
import { FriendshipInterface, WechatyInterface } from "wechaty/impls"; | ||||||||
|
||||||||
let lastAcceptTime: number = 0; | ||||||||
|
||||||||
wechaty.on('friendship', async friendship => { | ||||||||
if (friendship.type() === bot.Friendship.Type.Receive) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code snippet references - if (friendship.type() === bot.Friendship.Type.Receive) {
+ if (friendship.type() === wechaty.Friendship.Type.Receive) { Committable suggestion
Suggested change
|
||||||||
const currentTime = Date.now(); | ||||||||
// 判断距离上次接受好友请求的时间是否超过10秒 | ||||||||
if (currentTime - lastAcceptTime > 10000) { | ||||||||
// 发送好友请求通知 | ||||||||
const contact = await friendship.contact(); | ||||||||
// 自定义验证信息 | ||||||||
if (friendship.hello() === "我要学习Wechaty") { | ||||||||
await friendship.accept(); | ||||||||
} | ||||||||
lastAcceptTime = currentTime; | ||||||||
} else { | ||||||||
console.log("距离上次接受好友请求的时间未超过10秒,暂不处理此请求"); | ||||||||
} | ||||||||
} | ||||||||
}) | ||||||||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The official name of the platform is spelled with a capital "H" in "GitHub". Please correct the spelling to maintain professionalism and accuracy.
Committable suggestion