[Trivia] Add multiple channel support

This commit is contained in:
vilP1L
2019-05-16 22:12:40 -04:00
parent d3541f4bd9
commit a6193465ad
2 changed files with 27 additions and 24 deletions

View File

@@ -6,9 +6,9 @@
"defaultTokenSet": "bots.json",
"admins": ["471344177045569546", "448294491032518666"],
"channels": {
"hq-trivia": "568926468290248734",
"hq-words": "568926468290248734",
"confetti": "568927056172285981"
"hq-trivia": ["568926468290248734", "578754960897081344"],
"hq-words": ["568926468290248734"],
"confetti": ["568927056172285981"]
},
"logChannel": "572870712428199951"
},

View File

@@ -10,7 +10,7 @@ export default async (client, prize) => {
const tokens = getTokens(discord.defaultTokenSet);
// eslint-disable-next-line max-len
const master = new Client(tokens[0], 0);
const channel = client.channels.get(discord.channels['hq-trivia']);
const channels = discord.channels['hq-trivia'].map(c => client.channels.get(c));
await master.login();
master.testWs = client.testWs;
master.logging = false;
@@ -20,7 +20,7 @@ export default async (client, prize) => {
.setTitle('Game Live!')
.setDescription(`HQ Trivia is live for **$${(prize || 5000).toLocaleString('en')}!**`)
.setColor('#373C98');
channel.send(embed);
channels.forEach(c => c.send(embed));
let correctCount = 0;
let questionCount;
let questionNumber;
@@ -49,7 +49,8 @@ export default async (client, prize) => {
const weight = client.weights.hq[i];
embed.fields.push({ name: `${weight.toFixed(2)} | **${a.text}**`, value: '[]()' });
});
const m = await channel.send(embed);
channels.forEach(async (c) => {
const m = await c.send(embed);
const i = setInterval(() => {
const embed = new MessageEmbed()
.setTitle(`Question ${json.questionNumber}/${json.questionCount}:`)
@@ -60,7 +61,8 @@ export default async (client, prize) => {
});
m.edit(embed);
}, 2000);
setTimeout(() => clearInterval(i), 10000);
setTimeout(() => clearInterval(i), 12000);
});
}
if (json.type === 'questionSummary') {
const bestAnswer = client.weights.hq.indexOf(Math.max(...client.weights.hq));
@@ -73,12 +75,13 @@ export default async (client, prize) => {
value: '[]()',
});
});
const m = await channel.send(embed);
const correctIndex = json.answerCounts.map(a => a.correct).indexOf(true);
if (bestAnswer === correctIndex) {
await m.react('👍');
correctCount += 1;
} else await m.react('👎');
channels.forEach(async (c) => {
const m = await c.send(embed);
if (bestAnswer === correctIndex) await m.react('👍');
else await m.react('👎');
});
if (correctIndex === bestAnswer) correctCount += 1;
winners = json.advancingPlayersCount;
winnings = `$${((prize || 5000) / winners).toFixed(2)}`;
const correctUsers = client.userAnswers.hq.filter(u => u.answer === (correctIndex + 1));
@@ -95,9 +98,9 @@ export default async (client, prize) => {
}
});
master.ws.on('close', async () => {
await channel.send('**GAME OVER!**');
channels.forEach(c => c.send('**GAME OVER!**'));
const image = genResults('HQ Trivia', winners, winnings, `${correctCount}/${questionCount}`);
const attachment = new MessageAttachment(image);
channel.send(attachment);
channels.forEach(c => c.send(attachment));
});
};