-
Notifications
You must be signed in to change notification settings - Fork 54
/
HandleMessageText.js
171 lines (134 loc) · 4.17 KB
/
HandleMessageText.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
function debugMessageText(){
debug();
}
function handleMessageText(body) {
var payload = {
"method": "sendMessage",
"chat_id": body.message.chat.id,
"text": "",
"parse_mode": "markdown",
"disable_web_page_preview": true,
};
var regex = new RegExp("(^/[^ ]+)@" + Const.myName + "", "i");
var origMessageText = body.message.text.replace(regex, '$1');
// Covert a not command to command
origMessageText = handleNoCommandAndAlias(body, origMessageText);
if (origMessageText.indexOf("/") !== 0) {
//Check context and convert it to a command
if (isPrivate(body)) {
if (body.message && body.message.from) {
var context = getContext(body.message.from.id);
if (context && context.command) {
var command = context.command;
origMessageText = '/' + command.split(':').join(' ') + ' ' + origMessageText;
} else {
return null;
}
} else {
return null;
}
} else {
// Not a command
return null;
}
}
body.message.text = origMessageText;
var messageText = origMessageText.toLowerCase();
var commands = [
"/draw",
"/admin",
"/allowme",
"/help",
"/start",
"/initdb",
"/delmsg",
"/ban",
];
var paras = messageText.trim().split(" ");
// remove empty strings
paras = paras.filter(function(para){
if (para){
return true;
}
});
var command = paras[0];
if (!command) {
return;
}
// remove ! from command, a commamnd start with /! is from feng
command = command.replace("!", "");
if (!commands.includes(command)) {
// not a command
return null;
}
// mongo.insert(Const.fromTelegram, body);
var origParas = origMessageText.trim().split(" ");
// remove empty strings
origParas = origParas.filter(function(para){
if (para){
return true;
}
});
if (!allowed(body, paras, origParas)) {
payload.text = "对不起,您无权执行此操作,";
payload.text += "喜欢";
payload.text += "[本bot](https://telegram.me/" + Const.myName + ")";
payload.text += "的话";
payload.text += "[加我到您群中](https://telegram.me/" + Const.myName + "?startgroup=true)!";
addDeleteMeButton(payload);
return payload;
}
if (command.indexOf("/jump") == 0) {
var foundMessageId = paras[1];
if (isNaN(foundMessageId)) {
payload.text = "消息ID必需是数";
return payload;
}
payload.reply_to_message_id = foundMessageId;
payload.text = "点击以上引用可跳转到原消";
return payload;
}
if (command.indexOf("/admin") == 0) {
return handleAdminCommand(body, paras, origParas);
}
if (command.indexOf("/initdb") == 0) {
return handleInitDBCommand(body, paras, origParas);
}
if (command.indexOf("/notrobot") == 0) {
return handleNotRobotCommand(body, paras, origParas);
}
if (command.indexOf("/ban") == 0) {
return handleBanCommand(body, paras, origParas);
}
if (command.indexOf("/pinmessage") == 0) {
return handlePinMessageCommand(body, paras, origParas);
}
if (command.indexOf("/gpset") == 0) {
if (body.message.from.id !== 539065210) {
payload += "此命令极其危险,暂时只有峰哥可以使用";
return payload;
}
if (paras[2]) {
var field = origParas[1];
var value = origParas.splice(2).join(" ");
if (gpSetFieldValue(body.message.chat, field, value)) {
payload.text = "设置成功";
} else {
payload.text = "设置失败";
payload.text += "\n";
}
return payload;
}
return null;
}
if (command.indexOf("/delmsg") == 0) {
return handleDelMsgCommand(body, paras, origParas);
}
if (command.indexOf("/help") == 0) {
return handleHelpCommand(body, paras, origParas);
}
if (command.indexOf("/start") == 0) {
return handleStartCommand(body, paras, origParas);
}
return null;
}