From 8aaec566d0d3807a5f41080e12e4862fae48fef2 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 24 Feb 2018 13:04:56 -0500 Subject: try this --- commands/join.js | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'commands') 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, }; -- cgit v1.2.3