-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprefix.js
67 lines (61 loc) · 2.36 KB
/
prefix.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const { stripIndents, oneLine } = require('common-tags');
const Command = require('../base');
module.exports = class PrefixCommand extends Command {
constructor(client) {
super(client, {
name: 'prefix',
group: 'util',
memberName: 'prefix',
description: 'Shows or sets the command prefix.',
format: '[prefix/"default"/"none"]',
details: oneLine`
If no prefix is provided, the current prefix will be shown.
If the prefix is "default", the prefix will be reset to the bot's default prefix.
If the prefix is "none", the prefix will be removed entirely, only allowing mentions to run commands.
Only administrators may change the prefix.
`,
examples: ['prefix', 'prefix -', 'prefix omg!', 'prefix default', 'prefix none'],
args: [
{
key: 'prefix',
prompt: 'What would you like to set the bot\'s prefix to?',
type: 'string',
max: 15,
default: ''
}
]
});
}
async run(msg, args) {
// Just output the prefix
if(!args.prefix) {
const prefix = msg.guild ? msg.guild.commandPrefix : this.client.commandPrefix;
return msg.reply(stripIndents`
${prefix ? `The command prefix is \`${prefix}\`.` : 'There is no command prefix.'}
To run commands, use ${msg.anyUsage('command')}.
`);
}
// Check the user's permission before changing anything
if(msg.guild) {
if(!msg.member.hasPermission('ADMINISTRATOR') && !this.client.isOwner(msg.author)) {
return msg.reply('Only administrators may change the command prefix.');
}
} else if(!this.client.isOwner(msg.author)) {
return msg.reply('Only the bot owner(s) may change the global command prefix.');
}
// Save the prefix
const lowercase = args.prefix.toLowerCase();
const prefix = lowercase === 'none' ? '' : args.prefix;
let response;
if(lowercase === 'default') {
if(msg.guild) msg.guild.commandPrefix = null; else this.client.commandPrefix = null;
const current = this.client.commandPrefix ? `\`${this.client.commandPrefix}\`` : 'no prefix';
response = `Reset the command prefix to the default (currently ${current}).`;
} else {
if(msg.guild) msg.guild.commandPrefix = prefix; else this.client.commandPrefix = prefix;
response = prefix ? `Set the command prefix to \`${args.prefix}\`.` : 'Removed the command prefix entirely.';
}
msg.reply(`${response} To run commands, use ${msg.anyUsage('command')}.`);
return null;
}
};