Bug Fixes

This commit is contained in:
Daniel Odendahl Jr
2017-11-07 14:04:22 +00:00
parent f30c3b88f6
commit f2169219d5
2 changed files with 47 additions and 35 deletions
+6 -5
View File
@@ -70,13 +70,14 @@ module.exports = class CardsAgainstHumanityCommand extends Command {
**Black Card**: ${escapeMarkdown(black.text)} **Black Card**: ${escapeMarkdown(black.text)}
**Card Czar**: ${czar.user.username} **Card Czar**: ${czar.user.username}
Pick **${black.pick}** cards! Pick **${black.pick}** card${black.pick > 1 ? 's' : ''}!
`); `);
const chosen = []; const chosen = [];
const filter = res => { const filter = res => {
if (chosen.includes(res.content)) return false; const existing = hand[parseInt(res.content, 10) - 1];
if (!hand[parseInt(res.content, 10) - 1]) return false; if (!existing) return false;
chosen.push(hand[parseInt(res.content, 10) - 1]); if (chosen.includes(existing)) return false;
chosen.push(existing);
return true; return true;
}; };
const choices = await player.user.dmChannel.awaitMessages(filter, { const choices = await player.user.dmChannel.awaitMessages(filter, {
@@ -100,7 +101,7 @@ module.exports = class CardsAgainstHumanityCommand extends Command {
} }
const cards = shuffle(chosenCards); const cards = shuffle(chosenCards);
await msg.say(stripIndents` await msg.say(stripIndents`
${czar.user}, which cards do you pick? ${czar.user}, which card${black.pick > 1 ? 's' : ''} do you pick?
**Black Card**: ${escapeMarkdown(black.text)} **Black Card**: ${escapeMarkdown(black.text)}
${cards.map((card, i) => `**${i + 1}.** ${card.cards.join(', ')}`).join('\n')} ${cards.map((card, i) => `**${i + 1}.** ${card.cards.join(', ')}`).join('\n')}
+41 -30
View File
@@ -27,20 +27,7 @@ module.exports = class WizardConventionCommand extends Command {
this.playing.delete(msg.channel.id); this.playing.delete(msg.channel.id);
return msg.say('Game could not be started...'); return msg.say('Game could not be started...');
} }
let roles = ['dragon', 'healer', 'mind reader']; const players = await this.generatePlayers(awaitedPlayers);
for (let i = 0; i < (awaitedPlayers.length - 2); i++) roles.push(`pleb ${i + 1}`);
roles = shuffle(roles);
const players = new Collection();
let i = 1;
for (const player of awaitedPlayers) {
players.set(i, {
id: i,
user: player,
role: roles[i - 1]
});
await player.send(`Your role will be: ${roles[i - 1]}!`);
i++;
}
let turn = 1; let turn = 1;
while (players.size > 2 && players.exists('role', 'dragon')) { while (players.size > 2 && players.exists('role', 'dragon')) {
let eaten = null; let eaten = null;
@@ -48,15 +35,14 @@ module.exports = class WizardConventionCommand extends Command {
await msg.say(`Night ${turn}, sending DMs...`); await msg.say(`Night ${turn}, sending DMs...`);
for (const player of players.values()) { for (const player of players.values()) {
if (player.role.includes('pleb')) continue; if (player.role.includes('pleb')) continue;
const valid = players.filter(p => p.role !== player.role); const valid = players.filterArray(p => p.role !== player.role);
await player.user.send(stripIndents` await player.user.send(stripIndents`
${questions[player.role]} Please type the number. ${questions[player.role]} Please type the number.
${valid.map(p => `**${p.id}.** ${p.user.tag}`).join('\n')} ${valid.map((p, i) => `**${i + 1}.** ${p.user.tag}`).join('\n')}
`); `);
const filter = res => valid.map(p => p.id.toString()).includes(res.content); const decision = await player.user.dmChannel.awaitMessages(res => valid[parseInt(res.content, 10) - 1], {
const decision = await player.user.dmChannel.awaitMessages(filter, {
max: 1, max: 1,
time: 30000 time: 120000
}); });
if (!decision.size) { if (!decision.size) {
await player.user.send('Sorry, time is up!'); await player.user.send('Sorry, time is up!');
@@ -101,28 +87,36 @@ module.exports = class WizardConventionCommand extends Command {
Who is this mysterious dragon? You have one minute to decide. Who is this mysterious dragon? You have one minute to decide.
`); `);
} }
await wait(60000); await wait(120000);
const playersArr = Array.from(players.values());
await msg.say(stripIndents` await msg.say(stripIndents`
Who do you think is the dragon? Please type the number. Who do you think is the dragon? Please type the number.
${players.map(p => `**${p.id}.** ${p.user.tag}`).join('\n')} ${playersArr.map((p, i) => `**${i + 1}.** ${p.user.tag}`).join('\n')}
`); `);
const voted = []; const voted = [];
const filter2 = res => { const filter = res => {
if (!players.exists(p => p.user.id === res.author.id)) return false; if (!players.exists(p => p.user.id === res.author.id)) return false;
if (voted.includes(res.author.id)) return false; if (voted.includes(res.author.id)) return false;
if (!players.has(parseInt(res.content, 10))) return false; if (!playersArr[parseInt(res.content, 10) - 1]) return false;
voted.push(res.author.id); voted.push(res.author.id);
return true; return true;
}; };
const votes = await msg.channel.awaitMessages(filter2, { time: 30000 }); const votes = await msg.channel.awaitMessages(filter, {
max: players.size,
time: 120000
});
const counts = new Collection(); const counts = new Collection();
for (const vote of votes.values()) { for (const vote of votes.values()) {
const player = players.get(parseInt(vote.content, 10)); const player = players.get(playersArr[parseInt(vote.content, 10) - 1].id);
counts.set(player.id, { if (counts.has(player.id)) {
id: player.id, ++counts.get(player.id).votes;
votes: counts.has(player.id) ? ++counts.get(player.id).votes : 1, } else {
user: player.user counts.set(player.id, {
}); id: player.id,
votes: 1,
user: player.user
});
}
} }
if (!counts.size) { if (!counts.size) {
await msg.say('No one will be expelled.'); await msg.say('No one will be expelled.');
@@ -142,4 +136,21 @@ module.exports = class WizardConventionCommand extends Command {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`); return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
} }
} }
async generatePlayers(list) {
let roles = ['dragon', 'healer', 'mind reader'];
for (let i = 0; i < (list.length - 2); i++) roles.push(`pleb ${i + 1}`);
roles = shuffle(roles);
const players = new Collection();
let i = 0;
for (const user of list) {
players.set(user.id, {
id: user.id,
user,
role: roles[i]
});
await user.send(`Your role will be: ${roles[i]}!`);
i++;
}
}
}; };