mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Time multiplayer games out if both players drop out
This commit is contained in:
@@ -42,6 +42,7 @@ module.exports = class BalloonPopCommand extends Command {
|
||||
let winner = null;
|
||||
let remains = 500;
|
||||
let turns = 0;
|
||||
let lastTurnTimeout = false;
|
||||
while (!winner) {
|
||||
const user = userTurn ? msg.author : opponent;
|
||||
let pump;
|
||||
@@ -54,6 +55,7 @@ module.exports = class BalloonPopCommand extends Command {
|
||||
pump = await verify(msg.channel, user);
|
||||
}
|
||||
if (pump) {
|
||||
if (lastTurnTimeout) lastTurnTimeout = false;
|
||||
remains -= randomRange(25, 75);
|
||||
const popped = Math.floor(Math.random() * remains);
|
||||
if (popped <= 0) {
|
||||
@@ -67,11 +69,21 @@ module.exports = class BalloonPopCommand extends Command {
|
||||
userTurn = !userTurn;
|
||||
}
|
||||
} else {
|
||||
if (pump !== 0 && lastTurnTimeout) lastTurnTimeout = false;
|
||||
if (pump === 0) {
|
||||
if (lastTurnTimeout) {
|
||||
winner = 'time';
|
||||
break;
|
||||
} else {
|
||||
lastTurnTimeout = true;
|
||||
}
|
||||
}
|
||||
turns = 0;
|
||||
userTurn = !userTurn;
|
||||
}
|
||||
}
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (winner === 'time') return msg.say('Game ended due to inactivity.');
|
||||
return msg.say(`And the winner is... ${winner}! Great job!`);
|
||||
} catch (err) {
|
||||
this.client.games.delete(msg.channel.id);
|
||||
|
||||
@@ -36,6 +36,7 @@ module.exports = class BattleCommand extends Command {
|
||||
return msg.say('Looks like they declined...');
|
||||
}
|
||||
}
|
||||
let lastTurnTimeout = false;
|
||||
while (!battle.winner) {
|
||||
const choice = await battle.attacker.chooseAction(msg);
|
||||
if (choice === 'attack') {
|
||||
@@ -80,11 +81,19 @@ module.exports = class BattleCommand extends Command {
|
||||
} else if (choice === 'failed:time') {
|
||||
await msg.say(`Time's up, ${battle.attacker}!`);
|
||||
battle.reset();
|
||||
if (lastTurnTimeout) {
|
||||
battle.winner = 'time';
|
||||
break;
|
||||
} else {
|
||||
lastTurnTimeout = true;
|
||||
}
|
||||
} else {
|
||||
await msg.say('I do not understand what you want to do.');
|
||||
}
|
||||
if (choice !== 'failed:time' && lastTurnTimeout) lastTurnTimeout = false;
|
||||
}
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (battle.winner === 'time') return msg.say('Game ended due to inactivity.');
|
||||
return msg.say(`The match is over! Congrats, ${battle.winner}!`);
|
||||
} catch (err) {
|
||||
this.client.games.delete(msg.channel.id);
|
||||
|
||||
@@ -49,6 +49,7 @@ module.exports = class ConnectFourCommand extends Command {
|
||||
let userTurn = true;
|
||||
let winner = null;
|
||||
const colLevels = [5, 5, 5, 5, 5, 5, 5];
|
||||
let lastTurnTimeout = false;
|
||||
while (!winner && board.some(row => row.includes(null))) {
|
||||
const user = userTurn ? msg.author : opponent;
|
||||
const sign = userTurn ? 'user' : 'oppo';
|
||||
@@ -71,8 +72,14 @@ module.exports = class ConnectFourCommand extends Command {
|
||||
});
|
||||
if (!turn.size) {
|
||||
await msg.say('Sorry, time is up!');
|
||||
userTurn = !userTurn;
|
||||
continue;
|
||||
if (lastTurnTimeout) {
|
||||
winner = 'time';
|
||||
break;
|
||||
} else {
|
||||
lastTurnTimeout = true;
|
||||
userTurn = !userTurn;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const choice = turn.first().content;
|
||||
if (choice.toLowerCase() === 'end') {
|
||||
@@ -83,9 +90,11 @@ module.exports = class ConnectFourCommand extends Command {
|
||||
board[colLevels[i]][i] = sign;
|
||||
colLevels[i] -= 1;
|
||||
if (this.verifyWin(board)) winner = userTurn ? msg.author : opponent;
|
||||
if (lastTurnTimeout) lastTurnTimeout = false;
|
||||
userTurn = !userTurn;
|
||||
}
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (winner === 'time') return msg.say('Game ended due to inactivity.');
|
||||
return msg.say(winner ? `Congrats, ${winner}!` : 'Looks like it\'s a draw...');
|
||||
} catch (err) {
|
||||
this.client.games.delete(msg.channel.id);
|
||||
|
||||
@@ -41,6 +41,7 @@ module.exports = class DotsAndBoxesCommand extends Command {
|
||||
const oppoOwned = [];
|
||||
let userTurn = true;
|
||||
let winner = null;
|
||||
let lastTurnTimeout = false;
|
||||
while (taken.length < 40) {
|
||||
const user = userTurn ? msg.author : opponent;
|
||||
await msg.say(stripIndents`
|
||||
@@ -83,8 +84,14 @@ module.exports = class DotsAndBoxesCommand extends Command {
|
||||
});
|
||||
if (!turn.size) {
|
||||
await msg.say('Sorry, time is up!');
|
||||
userTurn = !userTurn;
|
||||
continue;
|
||||
if (lastTurnTimeout) {
|
||||
winner = 'time';
|
||||
break;
|
||||
} else {
|
||||
lastTurnTimeout = true;
|
||||
userTurn = !userTurn;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const choice = turn.first().content;
|
||||
if (choice.toLowerCase() === 'end') {
|
||||
@@ -112,7 +119,9 @@ module.exports = class DotsAndBoxesCommand extends Command {
|
||||
} else {
|
||||
userTurn = !userTurn;
|
||||
}
|
||||
if (lastTurnTimeout) lastTurnTimeout = false;
|
||||
}
|
||||
if (winner === 'time') return msg.say('Game ended due to inactivity.');
|
||||
winner = userOwned.length === oppoOwned.length
|
||||
? null
|
||||
: userOwned.length > oppoOwned.length ? msg.author : opponent;
|
||||
|
||||
@@ -46,6 +46,7 @@ module.exports = class EmojiEmojiRevolutionCommand extends Command {
|
||||
let turn = 0;
|
||||
let aPts = 0;
|
||||
let oPts = 0;
|
||||
let lastTurnTimeout = false;
|
||||
while (turn < 10) {
|
||||
++turn;
|
||||
const num = Math.floor(Math.random() * emojis.length);
|
||||
@@ -58,7 +59,12 @@ module.exports = class EmojiEmojiRevolutionCommand extends Command {
|
||||
});
|
||||
if (!win.size) {
|
||||
await msg.say('Hmm... No one even tried that round.');
|
||||
continue;
|
||||
if (lastTurnTimeout) {
|
||||
break;
|
||||
} else {
|
||||
lastTurnTimeout = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const winner = win.first().author;
|
||||
if (winner.id === msg.author.id) ++aPts;
|
||||
@@ -68,6 +74,7 @@ module.exports = class EmojiEmojiRevolutionCommand extends Command {
|
||||
**${msg.author.username}:** ${aPts}
|
||||
**${opponent.username}:** ${oPts}
|
||||
`);
|
||||
if (lastTurnTimeout) lastTurnTimeout = false;
|
||||
}
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (aPts === oPts) return msg.say('It\'s a tie!');
|
||||
|
||||
@@ -61,6 +61,7 @@ module.exports = class GuesspionageCommand extends Command {
|
||||
}
|
||||
const used = [];
|
||||
const userTurn = awaitedPlayers.slice(0);
|
||||
let lastTurnTimeout = false;
|
||||
while (userTurn.length) {
|
||||
++turn;
|
||||
const mainUser = pts.get(userTurn[0]).user;
|
||||
@@ -110,8 +111,14 @@ module.exports = class GuesspionageCommand extends Command {
|
||||
time: 30000
|
||||
});
|
||||
if (!everyoneElse.size) {
|
||||
await msg.say('Come on guys, get in the game!');
|
||||
continue;
|
||||
if (lastTurnTimeout) {
|
||||
await msg.say('Game ended due to inactivity.');
|
||||
break;
|
||||
} else {
|
||||
await msg.say('Come on guys, get in the game!');
|
||||
lastTurnTimeout = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const higherLower = everyoneElse.map(res => ({ guess: res.content.toLowerCase(), id: res.author.id }));
|
||||
for (const answer of higherLower) {
|
||||
@@ -136,6 +143,7 @@ module.exports = class GuesspionageCommand extends Command {
|
||||
|
||||
${userTurn.length ? '_Next round starting in 10 seconds..._' : ''}
|
||||
`);
|
||||
if (lastTurnTimeout) lastTurnTimeout = false;
|
||||
if (userTurn.length) await delay(10000);
|
||||
}
|
||||
this.client.games.delete(msg.channel.id);
|
||||
|
||||
@@ -56,6 +56,7 @@ module.exports = class LieSwatterCommand extends Command {
|
||||
});
|
||||
}
|
||||
const questions = await this.fetchQuestions();
|
||||
let lastTurnTimeout = false;
|
||||
while (questions.length) {
|
||||
++turn;
|
||||
const question = questions[0];
|
||||
@@ -81,7 +82,12 @@ module.exports = class LieSwatterCommand extends Command {
|
||||
});
|
||||
if (!msgs.size) {
|
||||
await msg.say(`No answers? Well, it was ${question.answer ? 'true' : 'a lie'}.`);
|
||||
continue;
|
||||
if (lastTurnTimeout) {
|
||||
break;
|
||||
} else {
|
||||
lastTurnTimeout = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const answers = msgs.map(res => {
|
||||
let answer;
|
||||
@@ -102,6 +108,7 @@ module.exports = class LieSwatterCommand extends Command {
|
||||
|
||||
${questions.length ? '_Next round starting in 5 seconds..._' : ''}
|
||||
`);
|
||||
if (lastTurnTimeout) lastTurnTimeout = false;
|
||||
if (questions.length) await delay(5000);
|
||||
}
|
||||
this.client.games.delete(msg.channel.id);
|
||||
|
||||
@@ -54,6 +54,7 @@ module.exports = class QuizDuelCommand extends Command {
|
||||
let winner = null;
|
||||
let userPoints = 0;
|
||||
let oppoPoints = 0;
|
||||
let lastTurnTimeout = false;
|
||||
while (!winner) {
|
||||
const question = await this.fetchQuestion();
|
||||
await msg.say(stripIndents`
|
||||
@@ -79,7 +80,13 @@ module.exports = class QuizDuelCommand extends Command {
|
||||
});
|
||||
if (!msgs.size) {
|
||||
await msg.say(`Sorry, time is up! It was ${question.correct}.`);
|
||||
continue;
|
||||
if (lastTurnTimeout) {
|
||||
winner = 'time';
|
||||
break;
|
||||
} else {
|
||||
lastTurnTimeout = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const result = msgs.first();
|
||||
const userWin = result.author.id === msg.author.id;
|
||||
@@ -92,8 +99,10 @@ module.exports = class QuizDuelCommand extends Command {
|
||||
${userWin ? '' : '**'}${oppoPoints}${userWin ? '' : '**'}
|
||||
`;
|
||||
await msg.say(`Nice one, ${result.author}! The score is now ${score}!`);
|
||||
if (lastTurnTimeout) lastTurnTimeout = false;
|
||||
}
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (winner === 'time') return msg.say('Game ended due to inactivity.');
|
||||
if (!winner) return msg.say('Aww, no one won...');
|
||||
return msg.say(`Congrats, ${winner}, you won!`);
|
||||
} catch (err) {
|
||||
|
||||
@@ -13,7 +13,7 @@ module.exports = class RussianRouletteCommand extends Command {
|
||||
args: [
|
||||
{
|
||||
key: 'opponent',
|
||||
prompt: 'What user would you like to gunfight?',
|
||||
prompt: 'What user would you like to play against?',
|
||||
type: 'user',
|
||||
default: () => this.client.user
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ module.exports = class TicTacToeCommand extends Command {
|
||||
const taken = [];
|
||||
let userTurn = true;
|
||||
let winner = null;
|
||||
let lastTurnTimeout = false;
|
||||
while (!winner && taken.length < 9) {
|
||||
const user = userTurn ? msg.author : opponent;
|
||||
const sign = userTurn ? 'X' : 'O';
|
||||
@@ -62,8 +63,14 @@ module.exports = class TicTacToeCommand extends Command {
|
||||
});
|
||||
if (!turn.size) {
|
||||
await msg.say('Sorry, time is up!');
|
||||
userTurn = !userTurn;
|
||||
continue;
|
||||
if (lastTurnTimeout) {
|
||||
winner = 'time';
|
||||
break;
|
||||
} else {
|
||||
userTurn = !userTurn;
|
||||
lastTurnTimeout = true;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const choice = turn.first().content;
|
||||
if (choice.toLowerCase() === 'end') {
|
||||
@@ -73,9 +80,11 @@ module.exports = class TicTacToeCommand extends Command {
|
||||
sides[Number.parseInt(choice, 10) - 1] = sign;
|
||||
taken.push(choice);
|
||||
if (this.verifyWin(sides)) winner = userTurn ? msg.author : opponent;
|
||||
if (lastTurnTimeout) lastTurnTimeout = false;
|
||||
userTurn = !userTurn;
|
||||
}
|
||||
this.client.games.delete(msg.channel.id);
|
||||
if (winner === 'time') return msg.say('Game ended due to inactivity.');
|
||||
return msg.say(winner ? `Congrats, ${winner}!` : 'Oh... The cat won.');
|
||||
} catch (err) {
|
||||
this.client.games.delete(msg.channel.id);
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "114.7.2",
|
||||
"version": "114.7.3",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user