Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions jekyll/_contributors/abeiheng.md
@@ -0,0 +1,15 @@
---
name: abeiheng
site: https://github.com/Abeiheng
avatar: /assets/contributors/abeiheng/avatar.webp
bio: 前端工程师 热爱技术 后端也会一点
email: 16638336810@163.com
---

前端工程师 热爱技术 后端也会一点

## Contact me

- Github: <https://github.com/Abeiheng>
Copy link

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.

- - Github: <https://github.com/Abeiheng>
+ - GitHub: <https://github.com/Abeiheng>

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- Github: <https://github.com/Abeiheng>
- GitHub: <https://github.com/Abeiheng>

- Email:<>
Copy link

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
- Email:<>

- Website: <>
102 changes: 102 additions & 0 deletions jekyll/_posts/2023-12-26-blog-auto-friend-auto-room.md
@@ -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,你可以创还能一个微信机器人,使其在微信平台上运行。
Copy link

Choose a reason for hiding this comment

The 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
WeChaty 是一个基于 Node.js 的开源微信机器人框架,而作为社群管理,需要对好友进行分类让其进入相应的群,通过本篇文章以及Wechaty,你可以创还能一个微信机器人,使其在微信平台上运行
WeChaty 是一个基于 Node.js 的开源微信机器人框架。本篇文章将介绍如何利用 WeChaty 进行社群管理,包括如何对好友进行分类并让他们加入相应的群聊。通过本文的指导,你将能够创建一个微信机器人,实现在微信平台上的自动化管理


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();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a variable mismatch in the code snippet. The variable message is used in the event handler but then referred to as msg within the function. This will cause a runtime error.

-    const content = msg.text();
-    const talker = msg.talker();
+    const content = message.text();
+    const talker = message.talker();

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const content = msg.text();
const content = message.text();
const talker = message.talker();

const talker = msg.talker();
if (/^加群$/.test(content)) {
const roomList = await bot.Room.findAll();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable bot is used but not defined in the provided code snippet. It seems like wechaty should be used instead, as that is the instance of the bot being configured and used in this context.

-        const roomList = await bot.Room.findAll();
+        const roomList = await wechaty.Room.findAll();

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const roomList = await bot.Room.findAll();
const roomList = await wechaty.Room.findAll();

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 });
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the previous comment, the variable bot is used but not defined. Replace bot with wechaty to reference the correct instance.

-        const room = await bot.Room.find({ topic: content });
+        const room = await wechaty.Room.find({ topic: content });

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const room = await bot.Room.find({ topic: content });
const room = await wechaty.Room.find({ topic: content });

if (room) {
await room?.add(talker);
} else {
talker.say(`${content}群聊,查找失败`);
}
}
})
```

![1.webp](/assets/2023/12-blog-auto-friend-auto-room/1.webp)
![2.webp](/assets/2023/12-blog-auto-friend-auto-room/2.webp)

以下代码为当私聊接收信息后返回提示 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) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code snippet references bot.Friendship.Type.Receive, but bot is not defined in this context. It appears that wechaty.Friendship.Type.Receive should be used instead, assuming wechaty is the instance being worked with.

-    if (friendship.type() === bot.Friendship.Type.Receive) {
+    if (friendship.type() === wechaty.Friendship.Type.Receive) {

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
if (friendship.type() === bot.Friendship.Type.Receive) {
if (friendship.type() === wechaty.Friendship.Type.Receive) {

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秒,暂不处理此请求");
}
}
})
```
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added jekyll/assets/contributors/abeiheng/avatar.webp
Binary file not shown.