Check room exists before removing user.
This commit is contained in:
parent
5336070245
commit
2a9311f021
|
@ -123,7 +123,9 @@ function onJoin(data, bot) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function onLeave(data, bot) {
|
function onLeave(data, bot) {
|
||||||
|
if (bot.rooms[data.roomId]) {
|
||||||
bot.rooms[data.roomId].users = bot.rooms[data.roomId].users.filter((userId) => userId !== data.userId);
|
bot.rooms[data.roomId].users = bot.rooms[data.roomId].users.filter((userId) => userId !== data.userId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onMessage(message, bot, games) {
|
function onMessage(message, bot, games) {
|
||||||
|
|
|
@ -5,11 +5,7 @@ const timers = require('timers/promises');
|
||||||
|
|
||||||
const questions = require('../../assets/jeopardy.json');
|
const questions = require('../../assets/jeopardy.json');
|
||||||
|
|
||||||
const settings = {
|
const settings = { ...config.trivia };
|
||||||
rounds: config.trivia.rounds,
|
|
||||||
timeout: config.trivia.timeout,
|
|
||||||
mode: config.trivia.mode,
|
|
||||||
};
|
|
||||||
|
|
||||||
let game = null;
|
let game = null;
|
||||||
|
|
||||||
|
@ -100,6 +96,8 @@ async function playRound(context, round = 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await timers.setTimeout(2000);
|
||||||
|
|
||||||
const leaders = Object.entries(game.points).sort(([, scoreA], [, scoreB]) => scoreB - scoreA).map(([username, score], index) => {
|
const leaders = Object.entries(game.points).sort(([, scoreA], [, scoreB]) => scoreB - scoreA).map(([username, score], index) => {
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
return `**@${username}** with **${score}** points`;
|
return `**@${username}** with **${score}** points`;
|
||||||
|
@ -107,6 +105,7 @@ async function playRound(context, round = 0) {
|
||||||
|
|
||||||
return `**@${username}** with **${score}** points`;
|
return `**@${username}** with **${score}** points`;
|
||||||
}).join(', ');
|
}).join(', ');
|
||||||
|
|
||||||
context.sendMessage(`That's the end of the game! Best players: ${leaders}`, context.room.id);
|
context.sendMessage(`That's the end of the game! Best players: ${leaders}`, context.room.id);
|
||||||
|
|
||||||
game = null;
|
game = null;
|
||||||
|
|
Loading…
Reference in New Issue