forked from hczhcz/telegram-kuso-bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.info.js
57 lines (46 loc) · 1.5 KB
/
plugin.info.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
'use strict';
const util = require('util');
module.exports = (bot, event, playerEvent, env) => {
bot.onText(/^\/info(@\w+)?((?: (?!_)\w+)*)$/, event((msg, match) => {
let info = msg;
if (info.reply_to_message) {
info = info.reply_to_message;
}
const path = match[2].split(' ').slice(1);
for (const i in path) {
if (Object.hasOwnProperty.bind(info)(path[i])) {
info = info[path[i]];
}
}
bot.sendMessage(
msg.chat.id,
util.inspect(info),
{
reply_to_message_id: msg.message_id,
}
);
}, 1));
bot.onText(/^\/gameinfo(@\w+)?((?: (?!_)\w+)*)$/, event((msg, match) => {
let info = env.data.games[msg.chat.id];
const path = match[2].split(' ').slice(1);
for (const i in path) {
if (Object.hasOwnProperty.bind(info)(path[i])) {
info = info[path[i]];
}
}
bot.sendMessage(
msg.chat.id,
util.inspect(info),
{
reply_to_message_id: msg.message_id,
}
);
}, 1));
env.info.addPluginHelp(
'info',
'/info 显示当前消息或回复消息 JSON 数据\n'
+ '/info <path> 按路径访问当前消息或回复消息 JSON 数据\n'
+ '/gameinfo 显示当前啪啪 JSON 数据\n'
+ '/gameinfo <path> 按路径访问当前啪啪 JSON 数据'
);
};