Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

Commit

Permalink
Successed rewriting code to JavaScript (node.js)
Browse files Browse the repository at this point in the history
  • Loading branch information
tretdm committed Apr 22, 2021
1 parent c467515 commit ec8b4ff
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 0 deletions.
41 changes: 41 additions & 0 deletions bot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
const vk = require('node-vk-bot-api');
const fs = require('fs');
const os = require('os');
const lang = require("./languages/ru.js");
const config = require("./config.js");

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('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.set(command.name, command);
}

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('underconstr').execute(vk, bot, prefix, lang, config, ctx, Markup)
} else if (ctx.message.text == prefix + lang.conv_command) {
commands.get('underconstr').execute(vk, bot, prefix, lang, config, ctx, Markup)
} else if (ctx.message.text == prefix + lang.cmds_list_command) {
commands.get('cmd_list').execute(vk, bot, prefix, lang, config, ctx, Markup)
}
} catch(ex) {
console.log(ex)
}
});

bot.startPolling();
7 changes: 7 additions & 0 deletions commands/cmd_list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
name: 'cmd_list',
description: 'Список команд для VK-версии бота VisionOne',
async execute(vk, bot, prefix, lang, config, ctx, Markup){
ctx.reply(lang.cmds_list_message);
}
}
17 changes: 17 additions & 0 deletions commands/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
name: 'start',
description: 'Показывает приветственное сообщение.',
async execute(vk, bot, prefix, lang, config, ctx, Markup){
ctx.reply(lang.start_message(config), null, Markup.keyboard([
[
Markup.button(lang.start_buttons[0], 'primary'),
Markup.button(lang.start_buttons[1]),
],
[
Markup.button(lang.start_buttons[2]),
Markup.button(lang.start_buttons[3]),
]
]).inline()
);
}
}
7 changes: 7 additions & 0 deletions commands/stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
name: 'stats',
description: 'Показывает служебную информацию о боте.',
async execute(vk, bot, prefix, lang, config, ctx, Markup, os){
ctx.reply(lang.stats_message(os, process, config));
}
}
7 changes: 7 additions & 0 deletions commands/underconstr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
name: 'underconstr',
description: 'Пока находится в разработке.',
async execute(vk, bot, prefix, lang, config, ctx, Markup){
ctx.reply(lang.underconstr_message);
}
}
7 changes: 7 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
'bot_name': 'VisionOne',
'token': process.env.VKTOKEN,
'release_date': '30 апреля 2021 г.',
'version': '01A1-VK-210422',
'prefix': '[club202978127|@tinelix_visionone] '
}
30 changes: 30 additions & 0 deletions languages/ru.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
name: 'Russian',
localized_name: 'Русский',
region: 'russia',
start_command: 'Начать',
start_message: (config) => `Здравствуйте. Портированная, но уже переписанная версия бота ${config.bot_name} для ВКонтакте находится в стадии разработки.\n\nНо не переживайте, открытие бота запланировано на ${config.release_date} А пока воспользуйтесь готовыми фишками, нажав на соответствущую кнопку.`,
start_buttons: ['Статистика бота', 'О пользователе', 'О беседе', 'Еще >>'],
stats_command: 'Статистика бота',
stats_message: (os, process, config) => {
if (os.platform() == 'win32')
{platform = 'Windows'}
else if (os.platform() == 'android')
{platform = 'Android с Termux'}
else if (os.platform() == 'linux')
{platform = 'Linux'}
else {platform = 'Неизвестно'}
if (os.cpus().length == 1)
{core_unit = 'ядро'}
else if (os.cpus().length <= 4)
{core_unit = 'ядра'}
else {core_unit = 'ядер'};

return `ℹ Статистика бота\n\nПод управлением: ${platform} (${os.release()})\nЦП: ${os.cpus()[0].model} (${os.cpus().length} ${core_unit}, ${os.cpus()[0].speed} МГц)\nВерсия Node.js: ${process.version.slice(1)}\nВерсия бота: ${config['version']}\nАналитика: 💬 (в разработке)`
},
user_command: 'О пользователе',
conv_command: 'О беседе',
cmds_list_command: 'Еще »',
cmds_list_message: `📄 Список команд\n\n"Статистика бота" - просмотр системной информации, на чем запущен бот\n\nВсе остальные команды на данный момент не реализованы, но будут разрабатываться.`,
underconstr_message: 'На данный момент эта функция не реализована, поэтому потерпите некоторое время.'
}

0 comments on commit ec8b4ff

Please sign in to comment.