2024-08-12 05:13:32 -04:00
|
|
|
const { languages, getMessage } = require('../util/lang.js')
|
|
|
|
const fs = require('fs')
|
2024-08-25 21:53:03 -04:00
|
|
|
const settings = require('../settings.json')
|
2024-08-12 05:13:32 -04:00
|
|
|
module.exports = {
|
|
|
|
execute: (c) => {
|
2024-08-24 10:15:39 -04:00
|
|
|
if (c.type === 'console') {
|
2024-08-23 10:44:32 -04:00
|
|
|
c.reply({
|
|
|
|
text: getMessage(c.lang, 'command.settings.disabled.console'),
|
|
|
|
color: c.colors.secondary
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2024-08-25 21:53:03 -04:00
|
|
|
if (settings.userSettingsDisabled) {
|
|
|
|
c.reply({
|
|
|
|
text: getMessage(c.lang, 'command.settings.disabled.global'),
|
|
|
|
color: c.colors.secondary
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2024-09-12 00:26:36 -04:00
|
|
|
let subcmd
|
|
|
|
if (c.args.length >= 1) subcmd = c.args.splice(0, 1)[0].toLowerCase()
|
2024-08-12 05:13:32 -04:00
|
|
|
switch (subcmd) {
|
2024-08-22 07:34:39 -04:00
|
|
|
case 'set':{
|
|
|
|
const allowedKeys = ['colorPrimary', 'colorSecondary', 'lang']
|
2024-08-12 05:13:32 -04:00
|
|
|
const key = c.args.splice(0, 1)[0]
|
2024-08-22 07:34:39 -04:00
|
|
|
if (!allowedKeys.includes(key)) {
|
2024-08-12 05:13:32 -04:00
|
|
|
c.reply({
|
|
|
|
text: getMessage(c.lang, 'command.settings.error.invalidKey'),
|
|
|
|
color: c.colors.secondary
|
2024-08-22 07:34:39 -04:00
|
|
|
})
|
|
|
|
return
|
2024-08-12 05:13:32 -04:00
|
|
|
}
|
2024-08-22 07:34:39 -04:00
|
|
|
const value = c.args.join(' ')
|
|
|
|
if (value === '' && key === 'lang') {
|
2024-08-12 05:13:32 -04:00
|
|
|
// Show all valid languages to user
|
2024-08-22 07:34:39 -04:00
|
|
|
for (const item of languages) {
|
2024-08-12 05:13:32 -04:00
|
|
|
c.reply({
|
2024-08-22 07:34:39 -04:00
|
|
|
translate: '%s (%s)',
|
2024-08-12 05:13:32 -04:00
|
|
|
color: c.colors.secondary,
|
2024-08-22 07:34:39 -04:00
|
|
|
with: [
|
2024-08-12 05:13:32 -04:00
|
|
|
{
|
2024-08-22 07:34:39 -04:00
|
|
|
text: getMessage(item, 'language.name'),
|
|
|
|
color: c.colors.primary
|
2024-08-12 05:13:32 -04:00
|
|
|
},
|
|
|
|
{
|
2024-08-22 07:34:39 -04:00
|
|
|
text: getMessage(item, 'language.region'),
|
2024-08-12 05:13:32 -04:00
|
|
|
color: c.colors.primary
|
|
|
|
}
|
|
|
|
],
|
2024-08-22 07:34:39 -04:00
|
|
|
hoverEvent: {
|
|
|
|
action: 'show_text',
|
2024-08-12 05:13:32 -04:00
|
|
|
value: {
|
2024-08-22 07:34:39 -04:00
|
|
|
translate: getMessage(item, 'command.settings.setLanguage'),
|
|
|
|
with: [
|
2024-08-12 05:13:32 -04:00
|
|
|
{
|
2024-08-22 07:34:39 -04:00
|
|
|
text: `${c.prefix}settings set lang ${item}`,
|
2024-08-12 05:13:32 -04:00
|
|
|
color: c.colors.secondary
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2024-08-22 07:34:39 -04:00
|
|
|
if (value === '') {
|
2024-08-12 05:13:32 -04:00
|
|
|
c.reply({
|
|
|
|
text: getMessage(c.lang, 'command.settings.error.mustProvideValue'),
|
|
|
|
color: c.colors.secondary
|
2024-08-22 07:34:39 -04:00
|
|
|
})
|
|
|
|
return
|
2024-08-12 05:13:32 -04:00
|
|
|
}
|
2024-08-22 07:34:39 -04:00
|
|
|
if (key === 'lang' && !languages.includes(value)) {
|
2024-08-12 05:13:32 -04:00
|
|
|
c.reply({
|
|
|
|
text: getMessage(c.lang, 'command.settings.error.invalidLanguage'),
|
|
|
|
color: c.colors.secondary
|
2024-08-22 07:34:39 -04:00
|
|
|
})
|
|
|
|
return
|
2024-08-12 05:13:32 -04:00
|
|
|
}
|
|
|
|
c.prefs[key] = value
|
|
|
|
|
|
|
|
// Save to file
|
|
|
|
fs.writeFileSync(`userPref/${c.uuid}.json`, JSON.stringify(c.prefs))
|
|
|
|
|
|
|
|
// Delete require cache
|
2024-08-22 07:34:39 -04:00
|
|
|
for (const i in require.cache) {
|
|
|
|
if (i.endsWith(`${c.uuid}.json`)) delete require.cache[i]
|
2024-08-12 05:13:32 -04:00
|
|
|
}
|
|
|
|
c.reply({
|
|
|
|
text: getMessage(c.lang, 'command.settings.saved'),
|
|
|
|
color: c.colors.secondary
|
2024-08-22 07:34:39 -04:00
|
|
|
})
|
|
|
|
break
|
|
|
|
}
|
|
|
|
case 'get':
|
2024-08-12 05:13:32 -04:00
|
|
|
c.reply({
|
2024-08-22 07:34:39 -04:00
|
|
|
translate: '%s: %s',
|
|
|
|
color: c.colors.primary,
|
|
|
|
with: [
|
2024-08-12 05:13:32 -04:00
|
|
|
{
|
|
|
|
text: getMessage(c.lang, 'command.settings.get.colorPrimary'),
|
|
|
|
color: c.colors.secondary
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: c.colors.primary,
|
|
|
|
color: c.colors.primary
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
c.reply({
|
2024-08-22 07:34:39 -04:00
|
|
|
translate: '%s: %s',
|
|
|
|
color: c.colors.primary,
|
|
|
|
with: [
|
2024-08-12 05:13:32 -04:00
|
|
|
{
|
|
|
|
text: getMessage(c.lang, 'command.settings.get.colorSecondary'),
|
|
|
|
color: c.colors.secondary
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: c.colors.secondary,
|
|
|
|
color: c.colors.secondary
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
c.reply({
|
2024-08-22 07:34:39 -04:00
|
|
|
translate: '%s: %s (%s)',
|
|
|
|
color: c.colors.primary,
|
|
|
|
with: [
|
2024-08-12 05:13:32 -04:00
|
|
|
{
|
|
|
|
text: getMessage(c.lang, 'command.settings.get.language'),
|
2024-08-22 07:34:39 -04:00
|
|
|
color: c.colors.secondary
|
2024-08-12 05:13:32 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
text: getMessage(c.lang, 'language.name'),
|
|
|
|
color: c.colors.primary
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text: getMessage(c.lang, 'language.region'),
|
|
|
|
color: c.colors.primary
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
c.reply({
|
|
|
|
translate: getMessage(c.lang, 'command.cloop.error.subcommand'),
|
|
|
|
color: c.colors.secondary,
|
|
|
|
with: [
|
|
|
|
{
|
|
|
|
text: `${c.prefix}help settings`,
|
|
|
|
color: c.colors.primary
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|