mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-16 00:12:32 +02:00
Jeopardy Command
This commit is contained in:
@@ -136,7 +136,7 @@ in the appropriate channel's topic to use it.
|
|||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
Total: 413
|
Total: 414
|
||||||
|
|
||||||
### Utility:
|
### Utility:
|
||||||
|
|
||||||
@@ -383,6 +383,7 @@ Total: 413
|
|||||||
* **hangman:** Prevent a man from being hanged by guessing a word as fast as you can.
|
* **hangman:** Prevent a man from being hanged by guessing a word as fast as you can.
|
||||||
* **horse-race:** Bet on the fastest horse in a 6-horse race.
|
* **horse-race:** Bet on the fastest horse in a 6-horse race.
|
||||||
* **hunger-games:** Simulate a Hunger Games match with up to 24 tributes.
|
* **hunger-games:** Simulate a Hunger Games match with up to 24 tributes.
|
||||||
|
* **jeopardy:** Answer a Jeopardy question.
|
||||||
* **lottery:** Attempt to win the lottery with 6 numbers.
|
* **lottery:** Attempt to win the lottery with 6 numbers.
|
||||||
* **mad-libs:** Choose words that fill in the blanks to create a crazy story!
|
* **mad-libs:** Choose words that fill in the blanks to create a crazy story!
|
||||||
* **math-quiz:** See how fast you can answer a math problem in a given time limit.
|
* **math-quiz:** See how fast you can answer a math problem in a given time limit.
|
||||||
@@ -901,6 +902,7 @@ here.
|
|||||||
- [JellyNeo Item Database](https://items.jellyneo.net/)
|
- [JellyNeo Item Database](https://items.jellyneo.net/)
|
||||||
* neopets-item (Item Data)
|
* neopets-item (Item Data)
|
||||||
- [Jeopardy](https://www.jeopardy.com/)
|
- [Jeopardy](https://www.jeopardy.com/)
|
||||||
|
* jeopardy (Original Show)
|
||||||
* jeopardy-question (Original Show)
|
* jeopardy-question (Original Show)
|
||||||
- [Jessica Knable](https://picsart.com/u/jessicaknable)
|
- [Jessica Knable](https://picsart.com/u/jessicaknable)
|
||||||
* hearts ([Image](https://picsart.com/i/sticker-hearts-heart-borders-frames-round-frame-border-love-263412201018212))
|
* hearts ([Image](https://picsart.com/i/sticker-hearts-heart-borders-frames-round-frame-border-love-263412201018212))
|
||||||
@@ -910,6 +912,8 @@ here.
|
|||||||
* to-be-continued (Original Anime)
|
* to-be-continued (Original Anime)
|
||||||
- [Jon Bernhardt](http://web.mit.edu/jonb/www/)
|
- [Jon Bernhardt](http://web.mit.edu/jonb/www/)
|
||||||
* bart-chalkboard ([Akbar Font](https://www.wobblymusic.com/groening/akbar.html))
|
* bart-chalkboard ([Akbar Font](https://www.wobblymusic.com/groening/akbar.html))
|
||||||
|
- [jService](http://jservice.io/)
|
||||||
|
* jeopardy (API)
|
||||||
- [Kickstarter](https://www.kickstarter.com/)
|
- [Kickstarter](https://www.kickstarter.com/)
|
||||||
* kickstarter (API)
|
* kickstarter (API)
|
||||||
- [KINMOZA!](http://www.kinmosa.com/)
|
- [KINMOZA!](http://www.kinmosa.com/)
|
||||||
@@ -1029,6 +1033,7 @@ here.
|
|||||||
- [OpenWeatherMap](https://openweathermap.org/)
|
- [OpenWeatherMap](https://openweathermap.org/)
|
||||||
* weather ([API](https://openweathermap.org/api))
|
* weather ([API](https://openweathermap.org/api))
|
||||||
- [OPTIFONT](http://opti.netii.net/)
|
- [OPTIFONT](http://opti.netii.net/)
|
||||||
|
* jeopardy ([Korinna Agency Font](https://fontmeme.com/fonts/korinna-agency-font/))
|
||||||
* jeopardy-question ([Korinna Agency Font](https://fontmeme.com/fonts/korinna-agency-font/))
|
* jeopardy-question ([Korinna Agency Font](https://fontmeme.com/fonts/korinna-agency-font/))
|
||||||
- [osu!](https://osu.ppy.sh/home)
|
- [osu!](https://osu.ppy.sh/home)
|
||||||
* osu ([API](https://github.com/ppy/osu-api/wiki))
|
* osu ([API](https://github.com/ppy/osu-api/wiki))
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ module.exports = class JeopardyQuestionCommand extends Command {
|
|||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'jeopardy-question',
|
name: 'jeopardy-question',
|
||||||
aliases: ['jeopardy', 'clue-card', 'jeopardy-clue-card', 'jeopardy-clue'],
|
aliases: ['clue-card', 'jeopardy-clue-card', 'jeopardy-clue'],
|
||||||
group: 'edit-image',
|
group: 'edit-image',
|
||||||
memberName: 'jeopardy-question',
|
memberName: 'jeopardy-question',
|
||||||
description: 'Sends a Jeopardy Question with the text of your choice.',
|
description: 'Sends a Jeopardy Question with the text of your choice.',
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
const Command = require('../../structures/Command');
|
||||||
|
const request = require('node-superfetch');
|
||||||
|
const { createCanvas, registerFont } = require('canvas');
|
||||||
|
const path = require('path');
|
||||||
|
const { wrapText } = require('../../util/Canvas');
|
||||||
|
registerFont(path.join(__dirname, '..', '..', 'assets', 'fonts', 'OPTIKorinna-Agency.otf'), { family: 'Korinna' });
|
||||||
|
|
||||||
|
module.exports = class JeopardyCommand extends Command {
|
||||||
|
constructor(client) {
|
||||||
|
super(client, {
|
||||||
|
name: 'jeopardy',
|
||||||
|
group: 'games-sp',
|
||||||
|
memberName: 'jeopardy',
|
||||||
|
description: 'Answer a Jeopardy question.',
|
||||||
|
credit: [
|
||||||
|
{
|
||||||
|
name: 'jService',
|
||||||
|
url: 'http://jservice.io/',
|
||||||
|
reason: 'API'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Jeopardy',
|
||||||
|
url: 'https://www.jeopardy.com/',
|
||||||
|
reason: 'Original Show'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'OPTIFONT',
|
||||||
|
url: 'http://opti.netii.net/',
|
||||||
|
reason: 'Korinna Agency Font',
|
||||||
|
reasonURL: 'https://fontmeme.com/fonts/korinna-agency-font/'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(msg) {
|
||||||
|
try {
|
||||||
|
const question = await this.fetchQuestion();
|
||||||
|
const clueCard = await this.generateClueCard(question.question);
|
||||||
|
await msg.reply(`The category is: **${question.category.title.toUpperCase()}**. 30 seconds, good luck.`, {
|
||||||
|
files: [{ attachment: clueCard, name: 'clue-card.png' }]
|
||||||
|
});
|
||||||
|
const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
|
||||||
|
max: 1,
|
||||||
|
time: 30000
|
||||||
|
});
|
||||||
|
if (!msgs.size) return msg.reply(`Time's up, the answer was **${question.answer}**.`);
|
||||||
|
const win = msgs.first().content.toLowerCase() === question.answer.toLowerCase();
|
||||||
|
if (!win) return msg.reply(`The answer was **${question.answer}**.`);
|
||||||
|
return msg.reply(`The answer was **${question.answer}**. Good job!`);
|
||||||
|
} catch (err) {
|
||||||
|
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fetchQuestion() {
|
||||||
|
const { body } = await request
|
||||||
|
.get('http://jservice.io/api/random')
|
||||||
|
.query({ count: 1 });
|
||||||
|
return body[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
async generateClueCard(question) {
|
||||||
|
const canvas = createCanvas(1280, 720);
|
||||||
|
const ctx = canvas.getContext('2d');
|
||||||
|
ctx.fillStyle = '#030e78';
|
||||||
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||||
|
ctx.textAlign = 'center';
|
||||||
|
ctx.textBaseline = 'top';
|
||||||
|
ctx.fillStyle = 'white';
|
||||||
|
ctx.font = '62px Korinna';
|
||||||
|
const lines = await wrapText(ctx, question.toUpperCase(), 813);
|
||||||
|
const topMost = (canvas.height / 2) - (((52 * lines.length) / 2) + ((20 * (lines.length - 1)) / 2));
|
||||||
|
for (let i = 0; i < lines.length; i++) {
|
||||||
|
const height = topMost + ((52 + 20) * i);
|
||||||
|
ctx.fillStyle = 'black';
|
||||||
|
ctx.fillText(lines[i], (canvas.width / 2) + 6, height + 6);
|
||||||
|
ctx.fillStyle = 'white';
|
||||||
|
ctx.fillText(lines[i], canvas.width / 2, height);
|
||||||
|
}
|
||||||
|
return canvas.toBuffer();
|
||||||
|
}
|
||||||
|
};
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiao",
|
"name": "xiao",
|
||||||
"version": "114.5.8",
|
"version": "114.6.0",
|
||||||
"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