mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 14:19:11 +02:00
Beep
This commit is contained in:
@@ -7,11 +7,11 @@ const { QUIZLET_KEY } = process.env;
|
|||||||
module.exports = class QuizletGameCommand extends Command {
|
module.exports = class QuizletGameCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'quizlet-game',
|
name: 'quizlet',
|
||||||
aliases: ['quizlet-quiz', 'quizlet-test'],
|
aliases: ['quizlet-game', 'quizlet-quiz', 'quizlet-test'],
|
||||||
group: 'games',
|
group: 'games',
|
||||||
memberName: 'quizlet-game',
|
memberName: 'quizlet',
|
||||||
description: 'Shuffle a Quizlet study deck and play a game similar to a quiz.',
|
description: 'Shuffle a Quizlet study set and play a game similar to a quiz.',
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
key: 'id',
|
key: 'id',
|
||||||
@@ -26,7 +26,7 @@ module.exports = class QuizletGameCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async run(msg, { id }) {
|
async run(msg, { id }) {
|
||||||
if (this.playing.has(msg.channel.id)) return msg.say('Only one fight may be occurring per channel.');
|
if (this.playing.has(msg.channel.id)) return msg.say('Only one game may be occurring per channel.');
|
||||||
this.playing.add(msg.channel.id);
|
this.playing.add(msg.channel.id);
|
||||||
try {
|
try {
|
||||||
const { body } = await snekfetch
|
const { body } = await snekfetch
|
||||||
@@ -38,13 +38,17 @@ module.exports = class QuizletGameCommand extends Command {
|
|||||||
const term = terms[0];
|
const term = terms[0];
|
||||||
await msg.say(stripIndents`
|
await msg.say(stripIndents`
|
||||||
**You have 30 seconds to answer which word this is. (type "end game" to end the game)**
|
**You have 30 seconds to answer which word this is. (type "end game" to end the game)**
|
||||||
${term.definition}${term.image ? `\n${term.image.url}` : ''}
|
${term.definition}
|
||||||
|
${term.image ? term.image.url : ''}
|
||||||
`);
|
`);
|
||||||
const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
|
const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, {
|
||||||
max: 1,
|
max: 1,
|
||||||
time: 30000
|
time: 30000
|
||||||
});
|
});
|
||||||
if (!msgs.size) break;
|
if (!msgs.size) {
|
||||||
|
await msg.say('Time!');
|
||||||
|
break;
|
||||||
|
}
|
||||||
const choice = msgs.first().content.toLowerCase();
|
const choice = msgs.first().content.toLowerCase();
|
||||||
if (choice === 'end game') break;
|
if (choice === 'end game') break;
|
||||||
if (choice !== term.term.toLowerCase()) {
|
if (choice !== term.term.toLowerCase()) {
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
const { Command } = require('discord.js-commando');
|
|
||||||
const { MessageEmbed } = require('discord.js');
|
|
||||||
const snekfetch = require('snekfetch');
|
|
||||||
const { QUIZLET_KEY } = process.env;
|
|
||||||
|
|
||||||
module.exports = class QuizletCommand extends Command {
|
|
||||||
constructor(client) {
|
|
||||||
super(client, {
|
|
||||||
name: 'quizlet',
|
|
||||||
aliases: ['quizlet-set'],
|
|
||||||
group: 'search',
|
|
||||||
memberName: 'quizlet',
|
|
||||||
description: 'Searches Quizlet for study sets.',
|
|
||||||
clientPermissions: ['EMBED_LINKS'],
|
|
||||||
args: [
|
|
||||||
{
|
|
||||||
key: 'query',
|
|
||||||
prompt: 'What study set would you like to search for?',
|
|
||||||
type: 'string'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async run(msg, { query }) {
|
|
||||||
try {
|
|
||||||
const { body } = await snekfetch
|
|
||||||
.get('https://api.quizlet.com/2.0/search/sets')
|
|
||||||
.query({
|
|
||||||
q: query,
|
|
||||||
client_id: QUIZLET_KEY
|
|
||||||
});
|
|
||||||
if (!body.sets.length) return msg.say('Could not find any results.');
|
|
||||||
const data = body.sets[0];
|
|
||||||
const embed = new MessageEmbed()
|
|
||||||
.setAuthor('Quizlet', 'https://i.imgur.com/mUvSPJn.png')
|
|
||||||
.setColor(0x4257B2)
|
|
||||||
.setURL(`https://quizlet.com${data.url}`)
|
|
||||||
.setTitle(data.title)
|
|
||||||
.addField('❯ Creator',
|
|
||||||
data.created_by, true)
|
|
||||||
.addField('❯ ID',
|
|
||||||
data.id, true)
|
|
||||||
.addField('❯ Term Count',
|
|
||||||
data.term_count, true);
|
|
||||||
return msg.embed(embed);
|
|
||||||
} catch (err) {
|
|
||||||
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user