From d73f97d8f9dead116fdc2d77f2e370a874fa927c Mon Sep 17 00:00:00 2001 From: Quinella Date: Tue, 8 Oct 2013 23:34:47 +0200 Subject: [PATCH] Changed the behavior of /challenge /challenge now opens the challenge window instead of the user window (like /user does) /challenge also accepts multiple parameters now: user, format, team user is the name(id) of the user you want to challenge format is the format you want. It gets changed to an id, so you can enter it in any way you want. For example: ou, ou no stealth rock, etc. team is the name of the team you wish to use. It also gets changed to an id and stops at the first match (problem: multiple teams with the same name?) Both the format and team parameters are optional --- js/client-chat.js | 27 +++++++++++++++++++++++++++ js/client-mainmenu.js | 21 +++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/js/client-chat.js b/js/client-chat.js index 043298660..fe750ba60 100644 --- a/js/client-chat.js +++ b/js/client-chat.js @@ -393,6 +393,15 @@ switch (cmd.toLowerCase()) { case 'challenge': + var targets = target.split(',').map($.trim); + + if (!targets[0]) targets[0] = prompt('Who?'); + target = toId(targets[0]); + this.challengeData = { userid: target, format: targets[1] || '', team: targets[2] || '' }; + app.on('response:userdetails', this.challengeUserdetails, this); + app.send('/cmd userdetails '+target); + return false; + case 'user': case 'open': if (!target) target = prompt('Who?'); @@ -601,6 +610,24 @@ } return text; + }, + + challengeData: {}, + challengeUserdetails: function (data) { + app.off('response:userdetails', this.challengeUserdetails); + + if (!data || this.challengeData.userid !== data.userid) return; + + if (data.rooms === false) { + this.add('This player does not exist or is not online.'); + return; + } + + app.rooms[''].requestNotifications(); + app.focusRoom(''); + var name = data.name || this.challengeData.userid; + if (/^[a-z0-9]/i.test(name)) name = ' ' + name; + app.rooms[''].challenge(name, this.challengeData.format, this.challengeData.team); } }); diff --git a/js/client-mainmenu.js b/js/client-mainmenu.js index f6d39d64e..9e0077879 100644 --- a/js/client-mainmenu.js +++ b/js/client-mainmenu.js @@ -253,7 +253,7 @@ }, clickUsername: function(e) { e.stopPropagation(); - var name = $(e.currentTarget).data('name'); + var name = $(e.currentTarget).data('name');console.log("HAHAHAHAHA", name); app.addPopup(UserPopup, {name: name, sourceEl: e.currentTarget}); }, clickPMBackground: function(e) { @@ -420,16 +420,29 @@ }, // challenge buttons - challenge: function(name) { + challenge: function(name, format, team) { var userid = toId(name); var $challenge = this.$('.pm-window-'+userid+' .challenge'); if ($challenge.length && !$challenge.find('button[name=dismissChallenge]').length) { return; } + + if (format) format = toId(format); + var teamIndex = undefined; + if (Storage.teams && team) { + var team = toId(team); + for (var i = 0; i < Storage.teams.length; i++) { + if (team === toId(Storage.teams[i].name || '')) { + teamIndex = i; + break; + } + } + } + $challenge = this.openChallenge(name); var buf = '

Challenge '+Tools.escapeHTML(name)+'?

'; - buf += '

'+this.renderFormats()+'

'; - buf += '

'+this.renderTeams()+'

'; + buf += '

'+this.renderFormats(format)+'

'; + buf += '

'+this.renderTeams(format, teamIndex)+'

'; buf += '

'; $challenge.html(buf); },