v0.7.2
This commit is contained in:
@@ -9,10 +9,13 @@
|
||||
const {VK} = require('vk-io')
|
||||
const Markov = require('markov-generator')
|
||||
|
||||
/** Функции */
|
||||
const Utils = require('./utils')
|
||||
|
||||
// Конфиг, паттерн и файл проекта
|
||||
const config = require('./config')
|
||||
const data = require(`./data`)
|
||||
const project = require('./package')
|
||||
const config = require('../config')
|
||||
const data = require('../data')
|
||||
const project = require('../package')
|
||||
|
||||
/** VK API */
|
||||
const vk = new VK({token: config.token, v: 5.131})
|
||||
@@ -36,10 +39,10 @@ vk.updates.on('message_new', async ctx => {
|
||||
if (!ctx.isChat || ctx.isOutbox || ctx.isGroup) return
|
||||
|
||||
// Генерация сообщения с определенным шансом
|
||||
if (Math.random() * 100 < config.chance) {
|
||||
if (Utils.getWithChance(config.chance)) {
|
||||
|
||||
// Статус набора текста
|
||||
ctx.setActivity()
|
||||
await ctx.setActivity()
|
||||
|
||||
/** Сгенерированный текст */
|
||||
const sentence = new Markov({input: data, minLenght: config.min_words}).makeChain()
|
||||
@@ -48,8 +51,8 @@ vk.updates.on('message_new', async ctx => {
|
||||
if (sentence.split('').length > config.max_symbols) return console.warn(warn_prefix, `#${ctx.chatId} Symbols limit exceeded (${sentence.split('').length}/${config.max_symbols})`)
|
||||
|
||||
// Отправка сообщения
|
||||
ctx.send(sentence)
|
||||
.then(() => console.log(succes_prefix, `#${ctx.chatId} Text generated`))
|
||||
await ctx.send(sentence)
|
||||
.then(() => console.log(succes_prefix, `#${ctx.chatId} Text generated (${Utils.getTimeString()})`))
|
||||
}
|
||||
})
|
||||
|
||||
35
core/utils.js
Normal file
35
core/utils.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/** __ __ __ ___ ___
|
||||
* / ' / \ |__) | |__ \_/
|
||||
* \__. \__/ | \ | |___ / \
|
||||
*
|
||||
* @copyright © 2021 hepller
|
||||
*/
|
||||
|
||||
/** Функции */
|
||||
module.exports = class Utils {
|
||||
|
||||
/** Получает текущее время в формате `hh:mm:ss` */
|
||||
static getTimeString() {
|
||||
|
||||
// Переменные
|
||||
let hours = new Date().getHours()
|
||||
let minutes = new Date().getMinutes()
|
||||
let seconds = new Date().getSeconds()
|
||||
|
||||
// Исправление одинарных символов
|
||||
if (hours < 10) hours = `0${hours}`
|
||||
if (minutes < 10) minutes = `0${minutes}`
|
||||
if (seconds < 10) seconds = `0${seconds}`
|
||||
|
||||
// Возвращение строки
|
||||
return `${hours}:${minutes}:${seconds}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает `true` с определенным шансом
|
||||
* @param {number} likelihood Вероятность (%)
|
||||
*/
|
||||
static getWithChance(likelihood) {
|
||||
return Math.random() * 100 < likelihood
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "cortex-bot",
|
||||
"version": "0.7.1",
|
||||
"version": "0.7.2",
|
||||
"description": "vk text generator bot",
|
||||
"main": "bot.js",
|
||||
"main": "core/core.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/hepller/cortex-bot.git"
|
||||
|
||||
Reference in New Issue
Block a user