diff options
| author | Unknown <jtsshieh@outlook.com> | 2018-02-24 13:04:56 -0500 |
|---|---|---|
| committer | Unknown <jtsshieh@outlook.com> | 2018-02-24 13:04:56 -0500 |
| commit | 8aaec566d0d3807a5f41080e12e4862fae48fef2 (patch) | |
| tree | 283d6a15cb45b4d26d05a1f7f8c17e81d6f21c0c | |
| parent | 0a37a04e7d5be6342189ddf229ab718d538b1c02 (diff) | |
| download | PokeBot-8aaec566d0d3807a5f41080e12e4862fae48fef2.tar.gz PokeBot-8aaec566d0d3807a5f41080e12e4862fae48fef2.tar.bz2 PokeBot-8aaec566d0d3807a5f41080e12e4862fae48fef2.zip | |
try this
| -rw-r--r-- | commands/join.js | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/commands/join.js b/commands/join.js index 3b8239c..b7fd916 100644 --- a/commands/join.js +++ b/commands/join.js @@ -1,35 +1,22 @@ exports.run = async (bot, msg, args) => { if (args.length < 1) return msg.reply('Please choose a team to join'); - let team; - - if (msg.member.roles.find('name', 'Mystic')) { - msg.member.removeRole(msg.guild.roles.find('name', 'Mystic')); - team = 'Mystic'; - } - else if (msg.member.roles.find('name', 'Valor')) { - msg.member.removeRole(msg.guild.roles.find('name', 'Valor')); - team = 'Valor'; - } - else if (msg.member.roles.find('name', 'Instinct')) { - msg.member.removeRole(msg.guild.roles.find('name', 'Instinct')); - team = 'Instinct'; - } + const team = findTeam(msg, args[0]); switch(args[0]) { case 'mystic': { msg.member.addRole(msg.guild.roles.find('name', 'Mystic')); - msg.reply(`Alright, ${team ? 'you have left team ' + team + 'and ' : 'you are have '}joined team Mystic.`); + msg.reply(`Alright, ${team ? 'you have left team ' + team + ' and ' : 'you are have '}joined team Mystic.`); break; } case 'valor' : { msg.member.addRole(msg.guild.roles.find('name', 'Valor')); - msg.reply(`Alright, ${team ? 'you have left team ' + team + 'and ' : 'you are have '}joined team Valor.`); + msg.reply(`Alright, ${team ? 'you have left team ' + team + ' and ' : 'you are have '}joined team Valor.`); break; } case 'instinct' : { msg.member.addRole(msg.guild.roles.find('name', 'Instinct')); - msg.reply(`Alright, ${team ? 'you have left team ' + team + 'and ' : 'you are have '}joined team Instinct.`); + msg.reply(`Alright, ${team ? 'you have left team ' + team + ' and ' : 'you are have '}joined team Instinct.`); break; } default : { @@ -39,8 +26,30 @@ exports.run = async (bot, msg, args) => { } }; +function findTeam(msg, team) { + + let oldTeam; + + if (msg.member.roles.find('name', 'Mystic')) { + if (team == 'mystic') return; + msg.member.removeRole(msg.guild.roles.find('name', 'Mystic')); + oldTeam = 'Mystic'; + } + else if (msg.member.roles.find('name', 'Valor')) { + if (team == 'valor') return; + msg.member.removeRole(msg.guild.roles.find('name', 'Valor')); + oldTeam = 'Valor'; + } + else if (msg.member.roles.find('name', 'Instinct')) { + if (team == 'instinct') return; + msg.member.removeRole(msg.guild.roles.find('name', 'Instinct')); + oldTeam = 'Instinct'; + } + return oldTeam; +} + exports.conf = { - aliases: ['pick'], + aliases: ['pick', 'choose'], guildOnly: true, }; |
