Skip to content

Commit

Permalink
nickname command now accepts user ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Sankarsan Kampa committed Jan 27, 2018
1 parent ac37f7b commit 0ec2198
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion changes.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"improved": [
"Are you a Patreon creator and hosting Bastion yourself? The `patrons` command will now show your patrons and not the patrons of the Bastion bot project.",
"`clearWarn`, `deafen`, `kick`, `mute`, `removeAllRoles`, `softBan`, `textMute`, `textUnMute`, `unDeafen`, `unMute` and `warn` commands can be used with the ID of the user. No need to mention them anymore.",
"`clearWarn`, `deafen`, `kick`, `mute`, `nickname`, `removeAllRoles`, `softBan`, `textMute`, `textUnMute`, `unDeafen`, `unMute` and `warn` commands can be used with the ID of the user. No need to mention them anymore.",
"Under-the-hood improvements"
],
"added": [],
Expand Down
29 changes: 19 additions & 10 deletions modules/moderation/nickname.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

exports.exec = async (Bastion, message, args) => {
try {
let user = message.mentions.users.first();
let user;
if (message.mentions.users.size) {
user = message.mentions.users.first();
}
else if (args.id) {
user = await Bastion.fetchUser(args.id);
}
if (!user) {
/**
* The command was ran with invalid parameters.
Expand All @@ -25,24 +31,23 @@ exports.exec = async (Bastion, message, args) => {
nickStat = 'Can\'t change server owner\'s nickname.';
}
else {
args = args.slice(1);
args = args.join(' ');
args.nick = args.nick.join(' ');

if (args.length > 32) {
if (args.nick > 32) {
color = Bastion.colors.RED;
nickStat = 'Nickname can\'t be longer than 32 characters.';
}
else {
if (args.length < 1) {
if (args.nick < 1) {
color = Bastion.colors.RED;
nickStat = `${message.author.tag} removed the nickname of ${user.tag}`;
}
else {
color = Bastion.colors.GREEN;
nickStat = `${message.author.tag} set the nickname of ${user.tag} to **${args}**`;
nickStat = `${message.author.tag} set the nickname of ${user.tag} to **${args.nick}**`;
}
}
await member.setNickname(args);
await member.setNickname(args.nick);
}

message.channel.send({
Expand All @@ -61,14 +66,18 @@ exports.exec = async (Bastion, message, args) => {

exports.config = {
aliases: [ 'nick' ],
enabled: true
enabled: true,
argsDefinitions: [
{ name: 'id', type: String, defaultOption: true },
{ name: 'nick', alias: 'n', type: String, multiple: true, defaultValue: [] }
]
};

exports.help = {
name: 'nickname',
botPermission: 'MANAGE_NICKNAMES',
userTextPermission: 'MANAGE_NICKNAMES',
userVoicePermission: '',
usage: 'nickname <@user-mention> [nick]',
example: [ 'nickname @user#0001 The Legend', 'nickname @user#0001' ]
usage: 'nickname < @USER_MENTION | USER_ID > [-n nick]',
example: [ 'nickname @user#0001 -n The Legend', 'nickname 167147569575323761' ]
};

0 comments on commit 0ec2198

Please sign in to comment.