mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-15 15:57:47 +02:00
Button-based join game
This commit is contained in:
@@ -34,7 +34,7 @@ module.exports = class AkinatorCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { region }) {
|
async run(msg, { region }) {
|
||||||
const aki = new Aki(region, !msg.channel.nsfw);
|
const aki = new Aki({ region, childMode: !msg.channel.nsfw });
|
||||||
let ans = null;
|
let ans = null;
|
||||||
let win = false;
|
let win = false;
|
||||||
let timesGuessed = 0;
|
let timesGuessed = 0;
|
||||||
|
|||||||
+20
-20
@@ -35,62 +35,62 @@
|
|||||||
"#util": "./util/Util.js"
|
"#util": "./util/Util.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@discordjs/collection": "^0.1.6",
|
"@discordjs/collection": "^0.2.1",
|
||||||
"@discordjs/opus": "^0.5.0",
|
"@discordjs/opus": "^0.5.3",
|
||||||
"@tensorflow/tfjs-node": "^3.6.1",
|
"@tensorflow/tfjs-node": "^3.8.0",
|
||||||
"@vitalets/google-translate-api": "^7.0.0",
|
"@vitalets/google-translate-api": "^7.0.0",
|
||||||
"aki-api": "^5.2.1",
|
"aki-api": "^6.0.5",
|
||||||
"bombsweeper.js": "^1.0.1",
|
"bombsweeper.js": "^1.0.1",
|
||||||
"canvas": "^2.8.0",
|
"canvas": "^2.8.0",
|
||||||
"cheerio": "^1.0.0-rc.9",
|
"cheerio": "^1.0.0-rc.10",
|
||||||
"city-timezones": "^1.2.0",
|
"city-timezones": "^1.2.0",
|
||||||
"cloc": "^2.8.0",
|
"cloc": "^2.8.0",
|
||||||
"common-tags": "^1.8.0",
|
"common-tags": "^1.8.0",
|
||||||
"connect4-ai": "^0.1.3",
|
"connect4-ai": "^0.1.3",
|
||||||
"custom-translate": "^2.2.8",
|
"custom-translate": "^2.2.8",
|
||||||
"didyoumean2": "^4.2.0",
|
"didyoumean2": "^5.0.0",
|
||||||
"discord.js": "github:discordjs/discord.js",
|
"discord.js": "github:discordjs/discord.js",
|
||||||
"discord.js-docs": "github:TeeSeal/discord.js-docs",
|
"discord.js-docs": "github:TeeSeal/discord.js-docs",
|
||||||
"dotenv": "^9.0.2",
|
"dotenv": "^10.0.0",
|
||||||
"emoji-regex": "^9.2.2",
|
"emoji-regex": "^9.2.2",
|
||||||
"eslint": "^7.26.0",
|
"eslint": "^7.32.0",
|
||||||
"fen-validator": "^1.4.1",
|
"fen-validator": "^1.4.1",
|
||||||
"font-finder": "^1.1.0",
|
"font-finder": "^1.1.0",
|
||||||
"gifencoder": "^2.0.1",
|
"gifencoder": "^2.0.1",
|
||||||
"gm": "^1.23.1",
|
"gm": "^1.23.1",
|
||||||
"html-entities": "^2.3.2",
|
"html-entities": "^2.3.2",
|
||||||
"image-to-ascii": "^3.0.13",
|
"image-to-ascii": "^3.0.13",
|
||||||
"ioredis": "^4.27.2",
|
"ioredis": "^4.27.7",
|
||||||
"js-beautify": "^1.13.13",
|
"js-beautify": "^1.14.0",
|
||||||
"js-chess-engine": "^0.11.3",
|
"js-chess-engine": "^0.11.3",
|
||||||
"jszip": "^3.6.0",
|
"jszip": "^3.7.0",
|
||||||
"kuroshiro": "^1.1.2",
|
"kuroshiro": "^1.2.0",
|
||||||
"kuroshiro-analyzer-kuromoji": "^1.1.0",
|
"kuroshiro-analyzer-kuromoji": "^1.1.0",
|
||||||
"mathjs": "^9.4.0",
|
"mathjs": "^9.4.4",
|
||||||
"minimist": "^1.2.5",
|
"minimist": "^1.2.5",
|
||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
"moment-duration-format": "^2.3.2",
|
"moment-duration-format": "^2.3.2",
|
||||||
"moment-timezone": "^0.5.33",
|
"moment-timezone": "^0.5.33",
|
||||||
"node-superfetch": "^0.2.3",
|
"node-superfetch": "^0.2.3",
|
||||||
"nsfwjs": "^2.4.0",
|
"nsfwjs": "^2.4.1",
|
||||||
"ntcjs": "^1.1.2",
|
"ntcjs": "^1.1.2",
|
||||||
"parse-domain": "^3.0.3",
|
"parse-domain": "^3.0.3",
|
||||||
"pokersolver": "^2.1.4",
|
"pokersolver": "^2.1.4",
|
||||||
"random-js": "^2.1.0",
|
"random-js": "^2.1.0",
|
||||||
"rss-parser": "^3.12.0",
|
"rss-parser": "^3.12.0",
|
||||||
"semver": "^7.3.5",
|
"semver": "^7.3.5",
|
||||||
"sherlockjs": "^1.4.0",
|
"sherlockjs": "^1.4.2",
|
||||||
"stackblur-canvas": "^2.5.0",
|
"stackblur-canvas": "^2.5.0",
|
||||||
"tesseract.js": "^2.1.4",
|
"tesseract.js": "^2.1.5",
|
||||||
"text-diff": "^1.0.1",
|
"text-diff": "^1.0.1",
|
||||||
"tictactoe-minimax-ai": "^1.2.1",
|
"tictactoe-minimax-ai": "^1.2.1",
|
||||||
"twemoji-parser": "^13.0.0",
|
"twemoji-parser": "^13.1.0",
|
||||||
"user-agents": "^1.0.658",
|
"user-agents": "^1.0.731",
|
||||||
"valid-url": "^1.0.9",
|
"valid-url": "^1.0.9",
|
||||||
"wavefile": "^11.0.0",
|
"wavefile": "^11.0.0",
|
||||||
"winston": "^3.3.3",
|
"winston": "^3.3.3",
|
||||||
"wuzzy": "^0.1.7",
|
"wuzzy": "^0.1.8",
|
||||||
"ytdl-core": "^4.8.0",
|
"ytdl-core": "^4.9.0",
|
||||||
"zip-to-timezone": "^1.1.5"
|
"zip-to-timezone": "^1.1.5"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
|
|||||||
+32
-18
@@ -1,3 +1,4 @@
|
|||||||
|
const { MessageActionRow, MessageButton } = require('discord.js');
|
||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
const request = require('node-superfetch');
|
const request = require('node-superfetch');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@@ -333,34 +334,47 @@ module.exports = class Util {
|
|||||||
static async awaitPlayers(msg, max, min, blacklist) {
|
static async awaitPlayers(msg, max, min, blacklist) {
|
||||||
if (max === 1) return [msg.author.id];
|
if (max === 1) return [msg.author.id];
|
||||||
const addS = min - 1 === 1 ? '' : 's';
|
const addS = min - 1 === 1 ? '' : 's';
|
||||||
await msg.say(stripIndents`
|
const row = new MessageActionRow().addComponents(
|
||||||
You will need at least ${min - 1} more player${addS} (at max ${max - 1}). To join, type \`join game\`.
|
new MessageButton().setCustomID('join').setLabel('Join Game').setStyle('PRIMARY'),
|
||||||
As the host, ${msg.author}, you can type \`start game\` to start the game early.
|
new MessageButton().setCustomID('start').setLabel('Start Game').setStyle('SUCCESS')
|
||||||
`);
|
);
|
||||||
|
let text = stripIndents`
|
||||||
|
You will need at least ${min - 1} more player${addS} (at max ${max - 1}).
|
||||||
|
As the host, ${msg.author}, you can start the game early.
|
||||||
|
`;
|
||||||
|
text += '\n';
|
||||||
|
await msg.say(text, { components: [row] });
|
||||||
const joined = [];
|
const joined = [];
|
||||||
joined.push(msg.author.id);
|
joined.push(msg.author.id);
|
||||||
const filter = res => {
|
const filter = interaction => {
|
||||||
if (res.author.bot) return false;
|
if (interaction.user.bot) return false;
|
||||||
if (blacklist.includes(res.author.id)) return false;
|
if (blacklist.includes(interaction.user.id)) return false;
|
||||||
if (res.author.id === msg.author.id && res.content.toLowerCase() === 'start game') return true;
|
if (interaction.user.id !== msg.author.id && interaction.customID === 'start') return false;
|
||||||
if (joined.includes(res.author.id)) return false;
|
if (joined.includes(interaction.user.id)) return false;
|
||||||
if (res.content.toLowerCase() !== 'join game') return false;
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
const collector = msg.channel.createMessageCollector(filter, { max: max - 1, time: 120000 });
|
const collector = msg.channel.createMessageComponentCollector(filter, {
|
||||||
collector.on('collect', res => {
|
componentType: 'BUTTON',
|
||||||
if (res.content.toLowerCase() === 'start game') {
|
max: max - 1,
|
||||||
Util.reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅');
|
time: 120000
|
||||||
|
});
|
||||||
|
collector.on('collect', interaction => {
|
||||||
|
if (interaction.customID === 'start') {
|
||||||
|
interaction.deferUpdate();
|
||||||
collector.stop();
|
collector.stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
joined.push(res.author.id);
|
joined.push(res.author.id);
|
||||||
Util.reactIfAble(res, res.author, SUCCESS_EMOJI_ID, '✅');
|
text += '✅';
|
||||||
|
interaction.update(text);
|
||||||
});
|
});
|
||||||
return new Promise(res => {
|
return new Promise(res => {
|
||||||
collector.once('end', verify => {
|
collector.once('end', () => {
|
||||||
verify.set(msg.id, msg);
|
if (joined.length < min) {
|
||||||
if (joined.length < min) return res(false);
|
interaction.update('Failed to start the game.', { components: [] });
|
||||||
|
return res(false);
|
||||||
|
}
|
||||||
|
interaction.update('Let the game begin!', { components: [] });
|
||||||
return res(joined);
|
return res(joined);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user