diff --git a/src/mod_controller.js b/src/mod_controller.js index 300fe99..a43a89b 100644 --- a/src/mod_controller.js +++ b/src/mod_controller.js @@ -249,7 +249,7 @@ class MafiaModController { } if (command.parent.ids.topic === -1) { //Command came from a chat - return this.dao.getGameByChatId(command.parent.ids.chat); + return this.dao.getGameByChatId(command.parent.ids.room); } else { return this.dao.getGameByTopicId(command.parent.ids.topic); } diff --git a/src/player_controller.js b/src/player_controller.js index f09c524..2b56440 100644 --- a/src/player_controller.js +++ b/src/player_controller.js @@ -98,7 +98,7 @@ class MafiaPlayerController { const text = '@' + target.username + ' has been lynched! Stay tuned for the flip.' + ' It is now Night.'; view.respondInThread(game.topicId, text); - this.forum.emit('mafia:playerLynched', target.username); + this.forum.emit('mafia:playerLynched'); }) .catch((error) => { const text = 'Error when lynching player: ' + error.toString(); @@ -251,9 +251,6 @@ class MafiaPlayerController { getGame(command) { //First check for 'in soandso' syntax - debug('Checking to see if command is in a game'); - - for (let i = 0; i < command.args.length; i++) { if (command.args[i].toLowerCase() === 'in' && command.args[i + 1]) { const target = command.args.slice(i + 1, command.args.length).join(' '); @@ -265,14 +262,10 @@ class MafiaPlayerController { } } - debug('Game not explicitly supplied, checking for implicit game'); - if (command.parent.ids.topic === -1) { - debug('Searching for game by chat ID ' + command.parent.ids.room); //Command came from a chat return this.dao.getGameByChatId(command.parent.ids.room); } else { - debug('Searching for game by topic ID ' + command.parent.ids.topic); return this.dao.getGameByTopicId(command.parent.ids.topic); } } @@ -1133,7 +1126,15 @@ class MafiaPlayerController { throw new Error('Target is invalid'); } - return command.getPost().catch(() => command.getChat()); + return command.getPost().catch(() => { + //So we tried to get a post and failed + //The most common reason for that is that + //there is no post. Which means we're in a chat. + //So return a pseudo object with the chat ID. + //Why not a real chat? They can't be retrieved by ID + //which is also why we can't just call command.getChat() + return {id: command.parent.ids.chat}; + }); }).then((post) => { let actionToken = 'target'; diff --git a/test/unit/modControllerTest.js b/test/unit/modControllerTest.js index b2b947b..60c2b2a 100644 --- a/test/unit/modControllerTest.js +++ b/test/unit/modControllerTest.js @@ -63,7 +63,7 @@ describe('mod controller', () => { parent: { ids: { topic: -1, - chat: 12 + room: 12 } }, args: [] diff --git a/test/unit/playerControllerTest.js b/test/unit/playerControllerTest.js index c42be10..611ee6d 100644 --- a/test/unit/playerControllerTest.js +++ b/test/unit/playerControllerTest.js @@ -2205,9 +2205,6 @@ describe('player controller', () => { const command = { getTopic: () => Promise.reject('Do not call me! you will break chat functionality'), getPost: () => Promise.reject('Do not call me! you will break chat functionality'), - getChat: () => Promise.resolve({ - id: 42 - }), getUser: () => Promise.resolve({ username: 'tehNinja' }), @@ -2216,7 +2213,8 @@ describe('player controller', () => { parent: { ids: { topic: -1, - chat: 123 + chat: 42, + room: 123 } } };