· 7 years ago · Jul 23, 2018, 09:52 AM
1const http = require("http");
2const VK = require ("VK-Promise");
3const vk = new VK();
4const callback = vk.init_callback_api("Строка, которую должен вернуть Ñервер", "secretkey", {group: 123});
5const bot = {
6 cmds: [],
7 on ( r, f, d ) {
8 return this.cmds.push ({ r, f, d });
9 }
10}
11
12http.createServer((req, res) => {
13 if(req.url == "/vk_callback_api")
14 return callback(req, res);
15 res.end("Error 404");
16}).listen(80);
17
18vk.init_execute_cart(50);
19
20vk.on("message",function (event, msg) {
21 if (msg.out) return;
22
23 let command = bot.cmds.find(c => c.r.test(msg.body));
24
25 if (!command) return msg.send("ÐеизвеÑÑ‚Ð½Ð°Ñ ÐºÐ¾Ð¼Ð°Ð½Ð´Ð°");
26
27 let args = msg.body.match(command.r) || [];
28 args[0] = msg;
29 command.f.apply(this, args);
30
31 event.ok();
32});
33
34bot.on (/!test/i, msg => msg.send("ok!"));