galactic-bot/structure/client/components/settings/utility/GuildPrefix.js
2020-05-24 01:11:57 +03:00

62 lines
1.4 KiB
JavaScript

const { Setting } = require('../../../../interfaces/');
class GuildPrefixSetting extends Setting {
constructor(client) {
super(client, {
name: 'guildPrefix',
index: 'prefix',
module: 'utility',
display: 'prefix',
aliases: [
'prefix'
],
guarded: true,
resolve: 'GUILD',
default: {
prefix: '-'
},
custom: true
});
this.client = client;
}
async handle(message, params) {
let [ prefix ] = params;
const MaxCharacters = 6;
if(prefix.length > MaxCharacters) return {
msg: message.format('S_GUILDPREFIX_LENGTH', { length: prefix.length, max: MaxCharacters }),
error: true
};
if(prefix.includes(' ')) return {
msg: message.format('S_GUILDPREFIX_SPACES'),
error: true
};
if (prefix === 'reset') ({ prefix } = this.default);
await message.guild._updateSettings({ [this.index]: prefix });
return {
msg: message.format('S_GUILDPREFIX_SUCCESS', { prefix }),
error: false
};
}
fields(guild) {
return {
name: '》Prefix',
value: `\`${guild.prefix}\``
};
}
}
module.exports = GuildPrefixSetting;