This repository has been archived by the owner on Jul 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
96 lines (81 loc) · 3.04 KB
/
bot.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
const vk = require('node-vk-bot-api');
const fs = require('fs');
const os = require('os');
const strftime = require('strftime')
const math = require('mathjs');
const http = require('http');
const host = '0.0.0.0';
const port = 8080;
const requestListener = function (req, res) {
res.setHeader("Content-Type", "text/html");
res.writeHead(200);
res.end(`<html><body>Pong!</body></html>`);
};
const server = http.createServer(requestListener);
server.listen(port, host, () => {
console.log(`Server is running on http://${host}:${port}`);
});
const lang = require("./languages/ru.js");
const config = require("./config.js");
const Stage = require('node-vk-bot-api/lib/stage');
const Scene = require('node-vk-bot-api/lib/scene');
const Session = require('node-vk-bot-api/lib/session');
const Markup = require('node-vk-bot-api/lib/markup');
const bot = new vk(config['token']);
let prefix = ""
let commands = new Map()
const commandFiles = fs.readdirSync('./vk/commands').filter(file => file.endsWith('.js'));
const session = new Session();
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.set(command.name, command);
}
const crystball = new Scene('8ball',
(ctx) => {
commands.get('crystball').first_scene(vk, bot, prefix, lang, config, ctx, Markup, Scene, Stage)
},
(ctx) => {
commands.get('crystball').second_scene(vk, bot, prefix, lang, config, ctx, Markup, Scene, Stage)
}
);
const calc = new Scene('calc',
(ctx) => {
commands.get('calc').first_scene(vk, bot, prefix, lang, config, ctx, Markup, Scene, Stage, math)
},
(ctx) => {
commands.get('calc').second_scene(vk, bot, prefix, lang, config, ctx, Markup, Scene, Stage, math)
}
);
const stage = new Stage(crystball, calc);
bot.use(session.middleware());
bot.use(stage.middleware());
bot.on((ctx) => {
try {
if (ctx.message.peer_id >= 2000000000 && ctx.message.peer_id < 3000000000) {
prefix = config['prefix']
} else {
prefix = ''
}
if (ctx.message.text == prefix + lang.start_command) {
commands.get('start').execute(vk, bot, prefix, lang, config, ctx, Markup)
} else if (ctx.message.text == prefix + lang.user_command) {
commands.get('user').execute(vk, bot, prefix, lang, config, ctx, Markup, strftime)
} else if (ctx.message.text == prefix + lang.conv_command) {
commands.get('conv').execute(vk, bot, prefix, lang, config, ctx, Markup, strftime)
} else if (ctx.message.text == prefix + lang.crystball_command) {
ctx.scene.enter('8ball');
} else if (ctx.message.text == prefix + lang.calc_command) {
ctx.scene.enter('calc');
} else if (ctx.message.text == prefix + lang.menu_command) {
commands.get('menu').execute(vk, bot, prefix, lang, config, ctx, Markup)
}
} catch(ex) {
console.log(ex)
}
});
bot.startPolling((err) => {
console.log(`${config.bot_name} bot (VK) started!\n\n`);
if (err) {
console.log(err);
}
});