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

feature: no game creation when there is no thread specified #177

Merged
merged 3 commits into from
Mar 16, 2017
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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sockmafia",
"version": "3.3.2",
"version": "3.4.0",
"description": "Mafia plugin for sockbot",
"main": "src/mafiabot.js",
"scripts": {
Expand Down
103 changes: 54 additions & 49 deletions src/mafiabot.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,57 +171,62 @@ function registerPlayers(game, players) {
exports.createFromFile = function (plugConfig) {
let game;

return dao.createGame(plugConfig.thread, plugConfig.name)
.catch((err) => {
/*eslint-disable no-console*/
if (err === 'E_GAME_EXISTS') {
console.log('Existing game found, augmenting');
return dao.getGameByTopicId(plugConfig.thread);
} else {
if (plugConfig.thread) {
return dao.createGame(plugConfig.thread, plugConfig.name)
.catch((err) => {
/*eslint-disable no-console*/
if (err === 'E_GAME_EXISTS') {
console.log('Existing game found, augmenting');
return dao.getGameByTopicId(plugConfig.thread);
} else {
console.log('ERROR! ' + err, err.stack);
/*eslint-enable no-console*/
throw err; // rethrow error to fail bot startup
}

})
.then((g) => {
game = g;
if (plugConfig.players) {
return registerPlayers(game, plugConfig.players);
} else {
return Promise.resolve();
}
})
.then(() => {
if (plugConfig.mods) {
return registerMods(game, plugConfig.mods);
} else {
return Promise.resolve();
}
})
.then(() => {
const prom = Object.keys(plugConfig.options).map((key) => {
if (game.getValue(key) === undefined) {
return game.setValue(key, plugConfig.options[key]);
}
return Promise.resolve();
});
return Promise.all(prom);
})
.then(() => {
if (plugConfig.voteBars) {
console.log('WARNING: Setting voteBars via old style config detected!'); //eslint-disable-line no-console
if (game.getValue('voteBars') === undefined) {
return game.setValue('voteBars', plugConfig.voteBars);
}
return Promise.resolve();
}
return Promise.resolve();
})
.catch((err) => {
/*eslint-disable no-console*/
console.log('ERROR! ' + err, err.stack);
/*eslint-enable no-console*/
throw err; // rethrow error to fail bot startup
}

})
.then((g) => {
game = g;
if (plugConfig.players) {
return registerPlayers(game, plugConfig.players);
} else {
return Promise.resolve();
}
})
.then(() => {
if (plugConfig.mods) {
return registerMods(game, plugConfig.mods);
} else {
return Promise.resolve();
}
})
.then(() => {
const prom = Object.keys(plugConfig.options).map((key) => {
if (game.getValue(key) === undefined) {
return game.setValue(key, plugConfig.options[key]);
}
return Promise.resolve();
});
return Promise.all(prom);
})
.then(() => {
if (plugConfig.voteBars) {
console.log('WARNING: Setting voteBars via old style config detected!'); //eslint-disable-line no-console
if (game.getValue('voteBars') === undefined) {
return game.setValue('voteBars', plugConfig.voteBars);
}
return Promise.resolve();
}
return Promise.resolve();
})
.catch((err) => {
/*eslint-disable no-console*/
console.log('ERROR! ' + err, err.stack);
/*eslint-enable no-console*/
throw err; // rethrow error to fail bot startup
});
} else {
debug('No game specified, skipping creation');
return Promise.resolve();
}
};