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