[Trivia] Add multiple channel support
This commit is contained in:
@@ -6,9 +6,9 @@
|
|||||||
"defaultTokenSet": "bots.json",
|
"defaultTokenSet": "bots.json",
|
||||||
"admins": ["471344177045569546", "448294491032518666"],
|
"admins": ["471344177045569546", "448294491032518666"],
|
||||||
"channels": {
|
"channels": {
|
||||||
"hq-trivia": "568926468290248734",
|
"hq-trivia": ["568926468290248734", "578754960897081344"],
|
||||||
"hq-words": "568926468290248734",
|
"hq-words": ["568926468290248734"],
|
||||||
"confetti": "568927056172285981"
|
"confetti": ["568927056172285981"]
|
||||||
},
|
},
|
||||||
"logChannel": "572870712428199951"
|
"logChannel": "572870712428199951"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export default async (client, prize) => {
|
|||||||
const tokens = getTokens(discord.defaultTokenSet);
|
const tokens = getTokens(discord.defaultTokenSet);
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
const master = new Client(tokens[0], 0);
|
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();
|
await master.login();
|
||||||
master.testWs = client.testWs;
|
master.testWs = client.testWs;
|
||||||
master.logging = false;
|
master.logging = false;
|
||||||
@@ -20,7 +20,7 @@ export default async (client, prize) => {
|
|||||||
.setTitle('Game Live!')
|
.setTitle('Game Live!')
|
||||||
.setDescription(`HQ Trivia is live for **$${(prize || 5000).toLocaleString('en')}!**`)
|
.setDescription(`HQ Trivia is live for **$${(prize || 5000).toLocaleString('en')}!**`)
|
||||||
.setColor('#373C98');
|
.setColor('#373C98');
|
||||||
channel.send(embed);
|
channels.forEach(c => c.send(embed));
|
||||||
let correctCount = 0;
|
let correctCount = 0;
|
||||||
let questionCount;
|
let questionCount;
|
||||||
let questionNumber;
|
let questionNumber;
|
||||||
@@ -49,7 +49,8 @@ export default async (client, prize) => {
|
|||||||
const weight = client.weights.hq[i];
|
const weight = client.weights.hq[i];
|
||||||
embed.fields.push({ name: `${weight.toFixed(2)} | **${a.text}**`, value: '[]()' });
|
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 i = setInterval(() => {
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setTitle(`Question ${json.questionNumber}/${json.questionCount}:`)
|
.setTitle(`Question ${json.questionNumber}/${json.questionCount}:`)
|
||||||
@@ -60,7 +61,8 @@ export default async (client, prize) => {
|
|||||||
});
|
});
|
||||||
m.edit(embed);
|
m.edit(embed);
|
||||||
}, 2000);
|
}, 2000);
|
||||||
setTimeout(() => clearInterval(i), 10000);
|
setTimeout(() => clearInterval(i), 12000);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (json.type === 'questionSummary') {
|
if (json.type === 'questionSummary') {
|
||||||
const bestAnswer = client.weights.hq.indexOf(Math.max(...client.weights.hq));
|
const bestAnswer = client.weights.hq.indexOf(Math.max(...client.weights.hq));
|
||||||
@@ -73,12 +75,13 @@ export default async (client, prize) => {
|
|||||||
value: '[]()',
|
value: '[]()',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
const m = await channel.send(embed);
|
|
||||||
const correctIndex = json.answerCounts.map(a => a.correct).indexOf(true);
|
const correctIndex = json.answerCounts.map(a => a.correct).indexOf(true);
|
||||||
if (bestAnswer === correctIndex) {
|
channels.forEach(async (c) => {
|
||||||
await m.react('👍');
|
const m = await c.send(embed);
|
||||||
correctCount += 1;
|
if (bestAnswer === correctIndex) await m.react('👍');
|
||||||
} else await m.react('👎');
|
else await m.react('👎');
|
||||||
|
});
|
||||||
|
if (correctIndex === bestAnswer) correctCount += 1;
|
||||||
winners = json.advancingPlayersCount;
|
winners = json.advancingPlayersCount;
|
||||||
winnings = `$${((prize || 5000) / winners).toFixed(2)}`;
|
winnings = `$${((prize || 5000) / winners).toFixed(2)}`;
|
||||||
const correctUsers = client.userAnswers.hq.filter(u => u.answer === (correctIndex + 1));
|
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 () => {
|
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 image = genResults('HQ Trivia', winners, winnings, `${correctCount}/${questionCount}`);
|
||||||
const attachment = new MessageAttachment(image);
|
const attachment = new MessageAttachment(image);
|
||||||
channel.send(attachment);
|
channels.forEach(c => c.send(attachment));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user