2024-07-30 05:56:23 -04:00
|
|
|
const fs = require('fs')
|
|
|
|
const languages = {}
|
|
|
|
const loadplug = (botno) => {
|
|
|
|
const bpl = fs.readdirSync('util/lang')
|
|
|
|
for (const i in bpl) {
|
|
|
|
if (!bpl[i].endsWith('.json')) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
languages[bpl[i].split('.')[0]] = require(`./lang/${bpl[i]}`)
|
|
|
|
} catch (e) { console.log(e) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
loadplug()
|
|
|
|
const getMessage = function (l, msg, with2) {
|
|
|
|
let message = msg.replace(/%%/g, '\ue123')
|
|
|
|
if (languages[l] && languages[l][message] !== undefined) {
|
|
|
|
message = languages[l][message].replace(/%%/g, '\ue123')
|
|
|
|
} else if (languages[l] && languages['en-US'][message] !== undefined) {
|
|
|
|
message = languages['en-US'][message].replace(/%%/g, '\ue123')
|
|
|
|
}
|
|
|
|
for (const i in with2) {
|
|
|
|
message = message.replace(/%s/, with2[i].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
|
|
|
message = message.replaceAll(`%${+i + 1}$s`, with2[i].replace(/%s/g, '\ue124').replace(/\$s/g, '\ue125'))
|
|
|
|
}
|
|
|
|
return message.replace(/\ue123/g, '%').replace(/\ue124/g, '%s').replace(/\ue125/g, '$s')
|
|
|
|
}
|
|
|
|
module.exports = {
|
|
|
|
getMessage,
|
|
|
|
formatTime: function (time, language) {
|
|
|
|
let finalString = ''
|
|
|
|
const seconds = Math.floor(time / 1000) % 60
|
|
|
|
const minutes = Math.floor(time / 60000) % 60
|
|
|
|
const hours = Math.floor(time / 3600000) % 24
|
|
|
|
const days = Math.floor(time / 86400000) % 7
|
|
|
|
const weeks = Math.floor(time / 604800000)
|
|
|
|
if (weeks !== 0) {
|
2024-08-04 01:41:32 -04:00
|
|
|
finalString += weeks
|
|
|
|
finalString += `${weeks === 1 ? getMessage(language, 'time.week') : getMessage(language, 'time.weekPlural')}`
|
2024-07-30 05:56:23 -04:00
|
|
|
}
|
|
|
|
if (days !== 0) {
|
2024-08-04 01:41:32 -04:00
|
|
|
finalString += days
|
|
|
|
finalString += `${days === 1 ? getMessage(language, 'time.day') : getMessage(language, 'time.dayPlural')}`
|
2024-07-30 05:56:23 -04:00
|
|
|
}
|
|
|
|
if (hours !== 0) {
|
2024-08-04 01:41:32 -04:00
|
|
|
finalString += hours
|
|
|
|
finalString += `${hours === 1 ? getMessage(language, 'time.hour') : getMessage(language, 'time.hourPlural')}`
|
2024-07-30 05:56:23 -04:00
|
|
|
}
|
|
|
|
if (minutes !== 0) {
|
2024-08-04 01:41:32 -04:00
|
|
|
finalString += minutes
|
|
|
|
finalString += `${minutes === 1 ? getMessage(language, 'time.minute') : getMessage(language, 'time.minutePlural')}`
|
2024-07-30 05:56:23 -04:00
|
|
|
}
|
|
|
|
if (seconds !== 0) {
|
2024-08-04 01:41:32 -04:00
|
|
|
finalString += seconds
|
|
|
|
finalString += `${seconds === 1 ? getMessage(language, 'time.second') : getMessage(language, 'time.secondPlural')}`
|
2024-07-30 05:56:23 -04:00
|
|
|
}
|
|
|
|
return finalString
|
|
|
|
}
|
|
|
|
}
|