Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Gosh darned chat IDs were wrong. #160

Merged
merged 1 commit into from
Sep 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mod_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 10 additions & 9 deletions src/player_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class MafiaPlayerController {
const text = '@' + target.username + ' has been lynched! Stay tuned for the flip.' +
' <b>It is now Night.</b>';
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();
Expand Down Expand Up @@ -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(' ');
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion test/unit/modControllerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('mod controller', () => {
parent: {
ids: {
topic: -1,
chat: 12
room: 12
}
},
args: []
Expand Down
6 changes: 2 additions & 4 deletions test/unit/playerControllerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}),
Expand All @@ -2216,7 +2213,8 @@ describe('player controller', () => {
parent: {
ids: {
topic: -1,
chat: 123
chat: 42,
room: 123
}
}
};
Expand Down