Akinator is Back!

This commit is contained in:
Dragon Fire
2020-05-19 08:49:05 -04:00
parent 08de0201a2
commit a255cad1da
3 changed files with 97 additions and 2 deletions
+4 -1
View File
@@ -136,7 +136,7 @@ in the appropriate channel's topic to use it.
## Commands
Total: 424
Total: 425
### Utility:
@@ -375,6 +375,7 @@ Total: 424
### Single-Player Games:
* **akinator:** Think about a real or fictional character, I will try to guess who it is.
* **blackjack:** Play a game of blackjack.
* **box-choosing:** Do you believe that there are choices in life? Taken from Higurashi Chapter 4.
* **bubble-wrap:** Pop some bubble wrap.
@@ -672,6 +673,8 @@ here.
* adorable (API)
- [Advice Slip](https://adviceslip.com/)
* advice ([API](https://api.adviceslip.com/))
- [Akinator](https://en.akinator.com/)
* akinator (API)
- [Alexey Star](https://alexeystar.com/)
* hollywood-star ([Hollywood Star Font](https://alexeystar.com/hollywood-star-font/))
- [Alpha Vantage](https://www.alphavantage.co/)
+91
View File
@@ -0,0 +1,91 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const Aki = require('aki-api');
const { stripIndents } = require('common-tags');
const { verify } = require('../../util/Util');
module.exports = class AkinatorCommand extends Command {
constructor(client) {
super(client, {
name: 'akinator',
aliases: ['aki'],
group: 'games',
memberName: 'akinator',
description: 'Think about a real or fictional character, I will try to guess who it is.',
clientPermissions: ['EMBED_LINKS'],
credit: [
{
name: 'Akinator',
url: 'https://en.akinator.com/',
reason: 'API'
}
]
});
}
async run(msg) {
const current = this.client.games.get(msg.channel.id);
if (current) return msg.reply(`Please wait until the current game of \`${current.name}\` is finished.`);
try {
const aki = new Aki('en');
let ans = null;
let win = false;
let forceGuess = false;
this.client.games.set(msg.channel.id, { name: this.name });
while (aki.guessCount < 3) {
if (aki.progress >= 70 || forceGuess) {
await aki.win();
const guess = aki.answers[0];
const embed = new MessageEmbed()
.setColor(0xF78B26)
.setTitle(`I'm ${Math.round(guess.proba * 100)}% sure it's...`)
.setDescription(`${guess.name}${guess.description ? `\n_${guess.description}_` : ''}`)
.setThumbnail(guess.absolute_picture_path || null);
await msg.embed(embed);
const verification = await verify(msg.channel, msg.author);
if (verification === 0) {
win = 'time';
break;
} else if (verification) {
win = false;
break;
} else {
const exMsg = aki.guessCount > 3 || forceGuess ? 'I give up.' : 'I can keep going!';
await msg.say(`Hmm... Is that so? ${exMsg}`);
if (aki.guessCount > 3 || forceGuess) {
win = true;
break;
}
}
}
const data = ans === null ? await aki.start() : await aki.step(ans);
if (!data || !data.answers || aki.currentStep >= 80) break;
const answers = data.answers.map(answer => answer.toLowerCase());
answers.push('end');
await msg.say(stripIndents`
**${++aki.currentStep}.** ${data.question} (${Math.round(Number.parseInt(aki.progress, 10))}%)
${data.answers.join(' | ')}
`);
const filter = res => res.author.id === msg.author.id && answers.includes(res.content.toLowerCase());
const msgs = await msg.channel.awaitMessages(filter, {
max: 1,
time: 30000
});
if (!msgs.size) {
await msg.say('Sorry, time is up!');
win = 'time';
break;
}
if (msgs.first().content.toLowerCase() === 'end') forceGuess = true;
else ans = answers.indexOf(msgs.first().content.toLowerCase());
}
this.client.games.delete(msg.channel.id);
if (win === 'time') return msg.say('I guess your silence means I have won.');
if (win) return msg.say('Bravo, you have defeated me.');
return msg.say('Guessed right one more time! I love playing with you!');
} catch (err) {
this.client.games.delete(msg.channel.id);
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+2 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "114.15.0",
"version": "114.16.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {
@@ -34,6 +34,7 @@
"@discordjs/collection": "^0.1.5",
"@discordjs/opus": "^0.3.2",
"@vitalets/google-translate-api": "^3.0.0",
"aki-api": "github:jgoralcz/aki-api",
"canvas": "^2.6.1",
"cheerio": "^1.0.0-rc.3",
"cloc": "^2.5.1",