Skip to content

Commit

Permalink
[ Add ] Auto reply
Browse files Browse the repository at this point in the history
  • Loading branch information
TechQuery committed Jun 19, 2019
1 parent cee9f7c commit a162ca0
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 9 deletions.
22 changes: 22 additions & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# FCC Panky

FCC 成都社区的微信群管理机器人,源自[【微信机器人工作坊】][1]

## 核心功能

1. 入群提醒
2. 自动回复
- 官网链接

## 本地运行

```shell
git clone https://github.com/FreeCodeCamp-Chengdu/wechat-robot.git ~/Desktop/FCC-Panky
cd ~/Desktop/FCC-Panky

npm set puppeteer_download_host https://storage.googleapis.com.cnpmjs.org
npm install
npm start
```

[1]: https://fcc-cd.tk/activity/workshop/wechat-robot/
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fcc-cdc/wechat-robot",
"version": "0.1.0",
"version": "0.2.0",
"description": "WeChat group administrator of FCC ChengDu community",
"license": "AGPL-3.0",
"author": "[email protected]",
Expand All @@ -12,16 +12,19 @@
"bugs": {
"url": "https://github.com/FreeCodeCamp-Chengdu/wechat-robot/issues"
},
"main": "index.js",
"main": "source/index.js",
"scripts": {
"format": "prettier --write \"{,!(node_modules|.git)/**/}*.{html,md,css,less,js,json,yml,yaml}\"",
"start": "node index"
"start": "node source/"
},
"husky": {
"hooks": {
"pre-commit": "npm run format && git add ."
}
},
"engines": {
"node": "^7.6.0"
},
"dependencies": {
"puppeteer": "^1.17.0",
"qrcode-terminal": "^0.12.0",
Expand Down
35 changes: 31 additions & 4 deletions source/core.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,36 @@
exports.roomJoin = function(room, list, guy) {
room.say(`欢迎喜爱编程的小伙伴入群:
${list.map((guy, index) => ` ${++index}. ${guy.name()}`)}
const roomList = require('./room.json'),
replyMap = require('./reply.json');

exports.roomJoin = async (room, list, guy) => {
const topic = await room.topic(),
name = guy.name();

list = list.map(guy => guy.name());

console.log(`【加群】${topic}${name} 邀请了 ${list}`);

return room.say(`欢迎喜爱编程的小伙伴入群:
${list.map((name, index) => ` ${++index}. ${name}`)}
请新人按照“昵称 - 技术栈”的格式修改自己的群名,并仔细阅读群公告中的【FCC 社区行为准则】:
https://fcc-cd.tk/profile/code-of-conduct/
若以上新人有因违反【行为准则】而被踢,邀请人 ${guy.name()} 也将负连带责任,被一起踢出本群。`);
若以上新人有因违反【行为准则】而被踢,邀请人 ${name} 也将负连带责任,被一起踢出本群。`);
};

exports.message = async message => {
const room = message.room(),
text = message.text();

if (!room || !roomList.includes(await room.topic())) return;

for (let pattern in replyMap)
if (text.match(new RegExp(pattern, 'i'))) {
console.log(`【回复】
${text}
=>
${replyMap[pattern]}`);

return message.say(replyMap[pattern]);
}
};
6 changes: 4 additions & 2 deletions source/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#! /usr/bin/env node

const { Wechaty } = require('wechaty'),
QRCoder = require('qrcode-terminal');

const { roomJoin } = require('./core');
const { roomJoin, message } = require('./core');

const robot = new Wechaty();

Expand All @@ -12,5 +14,5 @@ robot
.on('login', user => console.log('登录成功:' + user))
.on('logout', user => console.log('登出成功:' + user))
.on('room-join', roomJoin)
.on('message', message => console.log('收到消息:' + message))
.on('message', message)
.start();
5 changes: 5 additions & 0 deletions source/reply.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"(FCC|freeCodeCamp)\\s*成都.*官?方?网站?": "https://fcc-cd.tk/",
"(FCC|freeCodeCamp)\\s*中(文|国).*官?方?网站?": "https://freecodecamp.one/",
"(FCC|freeCodeCamp)\\s*(国际|全球).*官?方?网站?": "https://freecodecamp.org/"
}
7 changes: 7 additions & 0 deletions source/room.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
"FCC成都社区 - 1群",
"FCC成都社区 - 2群",
"FCC成都社区 - 3群",
"FCC成都社区 - 4群",
"微信机器人测试"
]

0 comments on commit a162ca0

Please sign in to comment.