Skip to content

Commit

Permalink
Fix: Allow specifying targets with @. Closes #146
Browse files Browse the repository at this point in the history
  • Loading branch information
yamikuronue committed Aug 16, 2016
1 parent de4f89e commit 0834bb9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/player_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -971,16 +971,23 @@ class MafiaPlayerController {
command.args.shift();
}

const target = command.args.shift();
//const gameName = Utils.argParse(command.args, []) || command.parent.ids.topic;


let target = command.args.shift();

if (!target) {
command.reply('Invalid command: Usage `!chat with somePlayer`');
return Promise.resolve();
}



if (target.startsWith('@')) {
target = target.substring(1);
}
//const gameName = Utils.argParse(command.args, []) || command.parent.ids.topic;




let game = null;
let postmanToggle;
let user;
Expand Down
12 changes: 12 additions & 0 deletions test/unit/playerControllerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2487,6 +2487,18 @@ describe('player controller', () => {
controller.forum.User.getByName.should.be.calledWith(target);
});
});
it('should include target when target has an "@"', () => {
const target = `user${Math.random()}`,
user = {
id: Math.random()
};

command.args = [`@${target}`];
controller.forum.User.getByName.resolves(user);
return controller.createChatHandler(command).then(() => {
game.getPlayer.should.be.calledWith(target);
});
});
it('should send expected message', () => {
game.name = `NAME ${Math.random()} NAME`;
const expected = `This is an officially sanctioned chat for ${game.name}`;
Expand Down

0 comments on commit 0834bb9

Please sign in to comment.