This commit is contained in:
Hepller
2021-09-09 14:48:52 +03:00
parent 3a9f74b3f9
commit a8e1b1b2a6
3 changed files with 47 additions and 9 deletions

35
core/utils.js Normal file
View 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
}
}