Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
完善报名流程
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuangbiaowei committed Dec 22, 2018
1 parent 3107bb8 commit 1c3b194
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
10 changes: 6 additions & 4 deletions bot.js
Expand Up @@ -7,7 +7,7 @@ const CommandUtils = require('./command-utils');
const Dialog = require('./dialog');
const DBUtils = require('./db-utils');
const RoomID = require('./roomid.json');

const Util = require('util');
const puppet = new PuppetPadchat();

const bot = new Wechaty({
Expand Down Expand Up @@ -50,14 +50,14 @@ async function onMessage(msg) {
}

async function onFriendship(friendship) {
console.log(friendship.toString());
console.log(Util.inspect(friendship));
if (friendship.type() == bot.Friendship.Type.Receive) {
await friendship.accept();
} else if (friendship.type() == bot.Friendship.Type.Confirm) {
var contact = await friendship.contact();
await contact.sync();
contact.say(Dialog.greeting);
DBUtils.save_wechat_friend(contact);
CommandUtils.accept_user(bot, await friendship.contact().name());
}
}

Expand All @@ -79,7 +79,9 @@ queue.process("UserApply", 1, async function(job, done){
var room = await bot.Room.load(room_id);
if(room){
room.sync();
var text = "有新人申请加入:"+job.data.nick_name +"\n"+"申请加入的小组:"+job.data.work_group+"\n"+"申请理由与自我介绍:"+job.data.introduce;
var text = "有新人申请加入:"+job.data.nick_name +"\n"+"申请加入的小组:"+job.data.work_group+"\n"+"申请理由与自我介绍:"+job.data.introduce+"\n";
text = text + "组长可以@机器人,并发布命令:“接纳@"+job.data.nick_name+"” 或 “同意@"+job.data.nick_name+"” ,机器人将会把他拉入本群。\n";
text = text + "如果组长@机器人,并发布命令:“正式@"+job.data.nick_name+"”,机器人将会同时把他拉入本群与开源社正式成员群。";
await room.say(text);
}
if (job.data.referee1 && job.data.referee2) {
Expand Down
22 changes: 17 additions & 5 deletions command-utils.js
Expand Up @@ -4,19 +4,28 @@ const DBUtils = require('./db-utils');
const RoomID = require('./roomid.json');
const WorkergroupLeader = require('./workgroup_leader.json');

exports.accept_user = async function (bot, user_name){
exports.accept_user = async function (bot, user_name, type){
console.log(type);
DBUtils.get_user(user_name, async function (user) {
if (user){
var contact = await bot.Contact.load(user.wechat_id);
if (contact.friend()){
var room_id = RoomID[user.work_group];
console.log(room_id);
var room = await bot.Room.load(room_id);
var wechat_user = await bot.Contact.load(user.wechat_id);
if(room){
await room.add(wechat_user);
await room.say("欢迎新朋友:" + user.nick_name);
await room.say(user.nick_name + "的自我介绍:" + user.introduce);
var text = "欢迎新朋友:" + user.nick_name + "\n" + user.nick_name + "的自我介绍:" + user.introduce;
room.add(wechat_user);
room.say(text);
DBUtils.update_user_status(user.wechat_id, '已加入');
if(type=="正式"){
var formal_room_id = RoomID["正式个人成员群"];
var formal_room = await bot.Room.load(formal_room_id);
formal_room.add(wechat_user);
formal_room.say(text);
DBUtils.update_user_position(user.wechat_id, '正式成员');
}
}
}
}
Expand Down Expand Up @@ -51,8 +60,11 @@ exports.do_room_command = async function (bot, msg) {
if (msg_text.slice(0,8)=="@开源社-bot"){
msg_text = msg_text.slice(9);
if (msg_text.slice(0,2)=="接纳" || msg_text.slice(0,2)=="同意"){
this.accept_user(bot, msg_text.slice(2));
this.accept_user(bot, msg_text.slice(2), "预备");
}
if (msg_text.slice(0,2)=="正式"){
this.accept_user(bot, msg_text.slice(2), "正式");
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions db-utils.js
Expand Up @@ -20,6 +20,7 @@ exports.get_user = function (nick_name, func) {
nick_name = nick_name.slice(1);
}
let query = "select * from users where `nick_name`='" + nick_name + "'";
console.log(query);
db.query(query, (err, result) => {
if(!err){
func(result[0]);
Expand All @@ -36,6 +37,13 @@ exports.update_user_status = function (wechat_id, user_status, func) {
});
}

exports.update_user_position = function (wechat_id, position, func){
let query = "update `users` set `position`='"+position+"' where `wechat_id`='"+wechat_id+"'";
db.query(query, (err, result) => {
if(func) { func(); }
});
}


exports.save_wechat_friend = async function (user){
var wechat_id = user.id;
Expand Down
3 changes: 2 additions & 1 deletion roomid.json
Expand Up @@ -8,5 +8,6 @@
"高校合作组":"7173936903@chatroom",
"财务组":"9693152650@chatroom",
"开源社迎新群":"12076146626@chatroom",
"基础设施工作组":"11928934793@chatroom"
"基础设施工作组":"11928934793@chatroom",
"正式个人成员群":"5279807869@chatroom"
}

0 comments on commit 1c3b194

Please sign in to comment.