This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
command-utils.js
151 lines (147 loc) · 4.89 KB
/
command-utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const Dialog = require('./dialog');
const Parser = require('./msg-parser');
const DBUtils = require('./db-utils');
const RoomID = require('./roomid.json');
const WorkergroupLeader = require('./workgroup_leader.json');
const Leaders = require('./leaders.json');
const COSConRooms = require('./coscon_rooms.json');
const KYSRooms = require('./kys_rooms.json');
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
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){
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, '正式成员');
}
}
}
}
});
}
exports.do_user_command = async function (bot, msg){
var msg_text = await Parser.getMsgText(bot, msg);
msg_text = msg_text.trim();
if (msg_text.slice(0, 6) == '#join ') {
msg_text = msg_text.slice(6);
var room_id = RoomID['开源社迎新群'];
var room = await bot.Room.load(room_id);
if (room) {
await room.add(msg.from());
await room.say("欢迎新朋友:" + msg.from().name());
await room.say(msg.from().name() + "的自我介绍:" + msg_text);
} else {
console.log("没有找到房间");
}
} else if(msg_text.slice(0,12) == '#joincoscon '){
msg_text = msg_text.slice(12);
room_index = 0;
room_id = COSConRooms[room_index];
var room = await bot.Room.load(room_id);
if (room) {
await room.add(msg.from());
await room.say("欢迎新朋友:" + msg.from().name());
await room.say(msg.from().name() + "的自我介绍:" + msg_text);
} else {
console.log("没有找到房间");
}
} else if(msg_text.slice(0,9)=='#joinkys2'){
var room = await bot.Room.load('17853987174@chatroom');
if(room){
await room.add(msg.from());
}
} else if(msg_text == '#merge'){
var from_name = await msg.from().name();
if (from_name == "庄表伟"){
var room0 = await bot.Room.load(COSConRooms[0]);
var room0list= await room0.memberAll();
var room0userlist = [];
var time_count = 0;
for(let room0user of room0list){
room0userlist.push(room0user.id);
}
for(let room_id of COSConRooms){
var room = await bot.Room.load(room_id);
console.log(room_id);
var list = await room.memberAll();
for(let user of list){
if (room0userlist.indexOf(user.id) == -1){
sleep(3000*time_count).then(()=>{
user.say("合并现场观众到一个大群,已经加入的同学请忽略");
room0.add(user);
});
time_count = time_count + 1;
}
}
}
}
} else {
var from_name = await msg.from().name();
if (from_name != "开源社-bot" && from_name != "微信团队"){
var reply = Dialog.getReply(msg_text);
msg.say(reply);
}
}
}
exports.do_room_command = async function (bot, msg) {
var msg_text = await Parser.getMsgText(bot, msg);
var room_topic = await msg.room().topic();
var from_name = await msg.from().name();
if(WorkergroupLeader[room_topic]){
if(WorkergroupLeader[room_topic]==from_name || from_name=='庄表伟'){
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), "预备");
}
if (msg_text.slice(0,2)=="正式"){
this.accept_user(bot, msg_text.slice(2), "正式");
}
}
}
}
if(room_topic=="开源社.2019 理事会+执行委员会" || room_topic=="COSCon'19组委会"){
if(Leaders.indexOf(from_name)>=0){
if (msg_text.slice(0,8)=="@开源社-bot"){
msg_text = msg_text.slice(9);
if (msg_text.slice(0,2)=="群发"){
const list = await bot.Contact.findAll();
list.forEach(async function (item, index) {
sleep(2000*index).then(()=>{
item.say(msg_text.slice(2));
});
});
}
if (msg_text.slice(0,6)=="COSCon"){
for(let room_id of COSConRooms){
var room = await bot.Room.load(room_id);
room.say(msg_text.slice(7));
}
}
if (msg_text.slice(0,3)=="kys"){
for(let room_id of KYSRooms){
var room = await bot.Room.load(room_id);
room.say(msg_text.slice(3));
}
}
}
}
}
}