-
Notifications
You must be signed in to change notification settings - Fork 270
/
shortReply.js
74 lines (59 loc) · 1.92 KB
/
shortReply.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
/*
Short replays for lazy people :)
*/
const SHORTCUTS = {
text: 'sendMessage',
photo: 'sendPhoto',
video: 'sendVideo',
videoNote: 'sendVideoNote',
file: 'sendDocument',
sticker: 'sendSticker',
audio: 'sendAudio',
voice: 'sendVoice',
game: 'sendGame',
action: 'sendChatAction',
location: 'sendLocation',
place(position, title, address, props = {}) {
const msg = this.data.message;
return this.bot.sendVenue(this.userId, position, title, address, this.propertyProcessor(msg, props));
}
};
module.exports = {
id: 'shortReply',
defaultConfig: {
methodName: 'reply',
privateMode: false,
replyMode: false
},
plugin(bot, pluginConfig) {
const methodName = pluginConfig.methodName || 'reply';
const isPrivate = pluginConfig.privateMode === true;
const replyMode = pluginConfig.replyMode === true;
function propertyProcessor(msg, props) {
if (replyMode || props.asReply === true) {
props.replyToMessage = msg.message_id;
}
return props;
}
function replyObject(data) {
const msg = data.message;
const userId = isPrivate ? msg.from.id : msg.chat.id;
const replyMethods = {};
for (let name in SHORTCUTS) {
const fn = SHORTCUTS[name];
if (typeof fn === 'string') {
replyMethods[name] = (data, props = {}) => {
return bot[fn](userId, data, propertyProcessor(msg, props));
};
} else {
replyMethods[name] = fn.bind({bot, data, userId, propertyProcessor});
}
}
return replyMethods;
}
bot.mod('message', (data) => {
data.message[methodName] = replyObject(data);
return data;
});
}
};