Files
cortex-bot/utils.js
Hepller 69da2dd68b v0.7.3
2021-09-12 22:32:54 +03:00

43 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** __ __ __ ___ ___ __ __ ___
* / ' / \ |__) | |__ \_/ |__) / \ |
* \__. \__/ | \ | |___ / \ |__) \__/ |
*
* @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
}
/**
* Форматирует текст (устанавливает заглавную букву и точку в конце)
* @param {string} text Текст для форматирования
*/
static formatText(text) {
return text.charAt(0).toUpperCase() + text.slice(1) + '.'
}
}