Anagramica Command

This commit is contained in:
Dragon Fire
2020-05-29 18:09:35 -04:00
parent 85566ea819
commit 30efb1646c
4 changed files with 116 additions and 2 deletions
+4 -1
View File
@@ -224,7 +224,7 @@ in the appropriate channel's topic to use it.
## Commands
Total: 445
Total: 446
### Utility:
@@ -470,6 +470,7 @@ Total: 445
### Single-Player Games:
* **akinator:** Think about a real or fictional character, I will try to guess who it is.
* **anagramica:** Try to find all the anagrams for a given set of letters.
* **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.
@@ -1119,6 +1120,8 @@ here.
- [Mattel](https://www.mattel.com/en-us)
* 8-ball ([Original Concept](https://www.mattelgames.com/games/en-us/kids/magic-8-ball))
* i-have-the-power (Image, Original "He-Man" Show)
- [Max Irwin](http://binarymax.com/)
* anagramica ([Original "Anagramica" Game, API](http://anagramica.com/))
- [Mayo Clinic](https://www.mayoclinic.org/)
* mayo-clinic (Disease Data)
- [MDN Web Docs](https://developer.mozilla.org/en-US/)
+28
View File
@@ -0,0 +1,28 @@
{
"a": 1,
"b": 2,
"c": 2,
"d": 2,
"e": 1,
"f": 3,
"g": 2,
"h": 4,
"i": 1,
"j": 4,
"k": 3,
"l": 2,
"m": 2,
"n": 1,
"o": 1,
"p": 2,
"q": 5,
"r": 1,
"s": 1,
"t": 1,
"u": 2,
"v": 3,
"w": 3,
"x": 5,
"y": 3,
"z": 4
}
+83
View File
@@ -0,0 +1,83 @@
const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
const request = require('node-superfetch');
const scores = require('../../assets/json/anagramica');
const pool = 'abcdefghijklmnopqrstuvwxyz'.split('');
const { SUCCESS_EMOJI_ID, FAILURE_EMOJI_ID } = process.env;
module.exports = class AnagramicaCommand extends Command {
constructor(client) {
super(client, {
name: 'anagramica',
aliases: ['anagram-game', 'anagram-quiz'],
group: 'games-sp',
memberName: 'anagramica',
description: 'Try to find all the anagrams for a given set of letters.',
credit: [
{
name: 'Max Irwin',
url: 'http://binarymax.com/',
reason: 'Original "Anagramica" Game, API',
reasonURL: 'http://anagramica.com/'
}
],
args: [
{
key: 'time',
prompt: 'How long should the game last in seconds? Max 90, min 15.',
type: 'integer',
max: 90,
min: 15
}
]
});
}
async run(msg, { time }) {
try {
const { valid, letters } = await this.fetchList();
let points = 0;
await msg.reply(stripIndents`
**You have ${time} seconds to provide anagrams for the following letters:**
${letters.map(letter => `\`${letter.toUpperCase()}\``).join(' ')}
`);
const filter = res => {
if (res.author.id !== msg.author.id) return false;
const score = this.getScore(letters, res.content.toLowerCase());
if (!score) return false;
if (!valid.includes(res.content.toLowerCase())) {
points -= score;
res.react(FAILURE_EMOJI_ID || '❌').catch(() => null);
return false;
}
points += score;
res.react(SUCCESS_EMOJI_ID || '✅').catch(() => null);
return true;
};
const msgs = await msg.channel.awaitMessages(filter, {
time: time * 1000
});
if (!msgs.size) return msg.reply('Couldn\'t even think of one? Ouch.');
if (points < 1) return msg.reply(`Ouch, your final score was **${points}**. Try harder next time!`);
return msg.reply(`Nice job! Your final score was **${points}**!`);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
async fetchList() {
const letters = [];
for (let i = 0; i < 10; i++) letters.push(pool[Math.floor(Math.random() * pool.length)]);
const { body } = await request.get(`http://www.anagramica.com/all/${letters.join('')}`);
return { valid: body.all, letters };
}
getScore(letters, word) {
let score = 0;
for (const letter of word.split('')) {
if (!letters[letter]) return null;
score += scores[letter];
}
return score;
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "114.30.5",
"version": "114.31.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {