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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Successed rewriting code to JavaScript (node.js)
- Loading branch information
Showing
7 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] ' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: 'На данный момент эта функция не реализована, поэтому потерпите некоторое время.' | ||
} |