forked from Galactic/galactic-bot
welcomer setting
This commit is contained in:
parent
aa0e2c354f
commit
d9aa6bb0e9
77
structure/client/components/settings/utility/Welcomer.js
Normal file
77
structure/client/components/settings/utility/Welcomer.js
Normal file
@ -0,0 +1,77 @@
|
||||
const { Setting } = require('../../../../interfaces/');
|
||||
|
||||
class WelcomerSetting extends Setting {
|
||||
|
||||
constructor(client) {
|
||||
|
||||
super(client, {
|
||||
name: 'welcomer',
|
||||
module: 'utility',
|
||||
aliases: [
|
||||
|
||||
],
|
||||
usage: '<value>',
|
||||
examples: [
|
||||
'welcomer Welcome to {guildname}!',
|
||||
'welcomer <on|off>',
|
||||
'welcomer reset'
|
||||
],
|
||||
guarded: false,
|
||||
resolve: 'GUILD',
|
||||
default: {
|
||||
welcomer: {
|
||||
message: 'Welcome to {guildname}!',
|
||||
enabled: false
|
||||
}
|
||||
},
|
||||
custom: true
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
async handle(message, params) {
|
||||
|
||||
const { guild } = message;
|
||||
const setting = guild._settings[this.index] || this.default[this.index];
|
||||
const { resolver } = this.client;
|
||||
const response = await resolver.resolveMethod(params);
|
||||
const langParams = {};
|
||||
let index = null;
|
||||
|
||||
if(resolver.resolveBoolean(params[0]) !== null) {
|
||||
setting.enabled = resolver.resolveBoolean(params[0]);
|
||||
index = 'S_WELCOMER_TOGGLE';
|
||||
langParams.toggle = message.format('ON_OFF_TOGGLE', { toggle: setting.enabled }, true)
|
||||
} else {
|
||||
setting.message = message.content.replace(guild.prefix, '').replace(message._caller, '').replace(message._settingCaller, '').trim();
|
||||
index = 'S_WELCOMER_SET';
|
||||
langParams.change = setting.message;
|
||||
}
|
||||
|
||||
await message.guild._updateSettings({ [this.index]: setting });
|
||||
return {
|
||||
error: false,
|
||||
msg: message.format(index, langParams)
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
async fields(guild) {
|
||||
const setting = guild._settings[this.index] || this.default[this.index];
|
||||
return [
|
||||
{
|
||||
name: '》Enabled',
|
||||
value: setting.enabled,
|
||||
inline: false
|
||||
},
|
||||
{
|
||||
name: '》Message',
|
||||
value: setting.message.substring(0,1021) + setting.message.length > 1021 ? '...' : '',
|
||||
inline: false
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = WelcomerSetting;
|
Loading…
Reference in New Issue
Block a user