Skip to content
This repository has been archived by the owner on Jan 31, 2021. It is now read-only.

Commit

Permalink
Apples to Apples is essentially a shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonfire535 committed Aug 29, 2018
1 parent 81c361c commit 3229b67
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 92 deletions.
89 changes: 2 additions & 87 deletions commands/games/apples-to-apples.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
const { Command, Argument } = require('discord-akairo');
const { escapeMarkdown } = require('discord.js');
const { stripIndents } = require('common-tags');
const { shuffle } = require('../../util/Util');
const Game = require('../../structures/Game');

module.exports = class ApplesToApplesCommand extends Command {
constructor() {
Expand Down Expand Up @@ -30,88 +26,7 @@ module.exports = class ApplesToApplesCommand extends Command {
});
}

async exec(msg, { maxPts, bot }) {
if (this.client.games.has(msg.channel.id)) return msg.util.reply('Only one game may be occurring per channel.');
const { blackCards, whiteCards } = this.client.decks.get('apples');
this.client.games.set(msg.channel.id, new Game(msg.channel, whiteCards, blackCards, 'Green'));
const game = this.client.games.get(msg.channel.id);
try {
const awaitedPlayers = await game.awaitPlayers(msg, bot ? this.client.user : null);
if (!awaitedPlayers) {
this.client.games.delete(msg.channel.id);
return msg.util.sendNew('Game could not be started...');
}
game.createJoinLeaveCollector(msg.channel, game);
while (!game.winner) {
const czar = game.changeCzar();
for (const player of game.players.values()) {
if (player.id === czar.id) continue;
if (player.kickable) game.kick(player);
}
if (game.players.size < 3) {
await msg.util.sendNew('Oh... It looks like everyone left...');
break;
}
const black = game.blackDeck.draw();
await msg.util.sendNew(stripIndents`
The card czar will be ${czar.user}!
The Green Card is: **${escapeMarkdown(black.text)}**
Sending DMs...
`);
const chosenCards = [];
const turns = await Promise.all(game.players.map(player => player.turn(black, chosenCards)));
const extra = turns.reduce((a, b) => a + b);
if (!chosenCards.length) {
await msg.util.sendNew('Hmm... No one even tried.');
continue;
}
const cards = shuffle(chosenCards);
await msg.util.sendNew(stripIndents`
${czar.user}, which card${black.pick > 1 ? 's' : ''} do you pick?
**Green Card**: ${escapeMarkdown(black.text)}
${cards.map((card, i) => `**${i + 1}.** ${card.cards.join(' | ')}`).join('\n')}
`);
const filter = res => {
if (res.author.id !== czar.user.id) return false;
if (!/^[0-9]+$/g.test(res.content)) return false;
if (!cards[Number.parseInt(res.content, 10) - 1]) return false;
return true;
};
const chosen = await msg.channel.awaitMessages(filter, {
max: 1,
time: 120000
});
if (!chosen.size) {
await msg.util.sendNew('Hmm... No one wins. Dealing back cards...');
for (const pick of cards) {
for (const card of pick.cards) game.players.get(pick.id).hand.add(card);
}
game.czar.strikes++;
continue;
}
const player = game.players.get(cards[Number.parseInt(chosen.first().content, 10) - 1].id);
if (!player) {
await msg.util.sendNew('Oh no, I think that player left! No awesome points will be awarded...');
continue;
}
player.points += 1 + extra;
if (player.points >= maxPts) {
game.winner = player.user;
} else {
const addS = player.points > 1 ? 's' : '';
await msg.util.sendNew(`Nice, ${player.user}! You now have **${player.points}** awesome point${addS}!`);
}
}
game.stopJoinLeaveCollector();
this.client.games.delete(msg.channel.id);
if (!game.winner) return msg.util.sendNew('See you next time!');
return msg.util.sendNew(`And the winner is... ${game.winner}! Great job!`);
} catch (err) {
game.stopJoinLeaveCollector();
this.client.games.delete(msg.channel.id);
return msg.util.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
exec(msg, { maxPts, bot }) {
return this.handler.modules.get('cards-against-humanity').exec(msg, { maxPts, bot, whitelist: 'apples' }, 'Green');
}
};
8 changes: 4 additions & 4 deletions commands/games/cards-against-humanity.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ module.exports = class CardsAgainstHumanityCommand extends Command {
});
}

async exec(msg, { maxPts, bot, blacklist, whitelist }) { // eslint-disable-line complexity
async exec(msg, { maxPts, bot, blacklist, whitelist }, blackType = 'Black') { // eslint-disable-line complexity
if (this.client.games.has(msg.channel.id)) return msg.util.reply('Only one game may be occurring per channel.');
if (blacklist && whitelist) return msg.util.reply('Both a blacklist and a whitelist? That sounds weird.');
const { blackCards, whiteCards } = this.client.decks.generate(blacklist, whitelist);
if (!blackCards.length || !whiteCards.length) return msg.util.reply('Your filter filters out every card...');
this.client.games.set(msg.channel.id, new Game(msg.channel, whiteCards, blackCards, 'Black'));
this.client.games.set(msg.channel.id, new Game(msg.channel, whiteCards, blackCards, blackType));
const game = this.client.games.get(msg.channel.id);
try {
const awaitedPlayers = await game.awaitPlayers(msg, bot ? this.client.user : null);
Expand All @@ -69,7 +69,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command {
const black = game.blackDeck.draw();
await msg.util.sendNew(stripIndents`
The card czar will be ${czar.user}!
The Black Card is: **${escapeMarkdown(black.text)}**
The ${blackType} Card is: **${escapeMarkdown(black.text)}**
Sending DMs...
`);
Expand All @@ -83,7 +83,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command {
const cards = shuffle(chosenCards);
await msg.util.sendNew(stripIndents`
${czar.user}, which card${black.pick > 1 ? 's' : ''} do you pick?
**Black Card**: ${escapeMarkdown(black.text)}
**${blackType} Card**: ${escapeMarkdown(black.text)}
${cards.map((card, i) => `**${i + 1}.** ${card.cards.join(' | ')}`).join('\n')}
`);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rando-cardrissian",
"version": "6.3.1",
"version": "6.3.2",
"description": "Cards Against Humanity, but for Discord!",
"main": "Rando.js",
"scripts": {
Expand Down

0 comments on commit 3229b67

Please sign in to comment.