mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-21 22:14:34 +02:00
Local Xiao Command
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
|
||||
const { XIAO_ALBUM_ID } = process.env;
|
||||
const Command = require('../../framework/Command');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const images = fs.readdirSync(path.join(__dirname, '..', '..', 'assets', 'images', 'xiao'));
|
||||
|
||||
module.exports = class XiaoCommand extends ImgurAlbumCommand {
|
||||
module.exports = class XiaoCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'xiao',
|
||||
@@ -22,7 +24,8 @@ module.exports = class XiaoCommand extends ImgurAlbumCommand {
|
||||
});
|
||||
}
|
||||
|
||||
generateText() {
|
||||
return 'It\'s me, yes?';
|
||||
run(msg) {
|
||||
const image = images[Math.floor(Math.random() * images.length)];
|
||||
return msg.say({ files: [path.join(__dirname, '..', '..', 'assets', 'images', 'xiao', images[image])] });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const request = require('node-superfetch');
|
||||
const { IMGUR_KEY } = process.env;
|
||||
|
||||
module.exports = class ImgurCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'imgur',
|
||||
group: 'search',
|
||||
memberName: 'imgur',
|
||||
description: 'Searches Imgur for your query.',
|
||||
credit: [
|
||||
{
|
||||
name: 'Imgur',
|
||||
url: 'https://imgur.com/',
|
||||
reason: 'API',
|
||||
reasonURL: 'https://apidocs.imgur.com/'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What image would you like to search for?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const { body } = await request
|
||||
.get('https://api.imgur.com/3/gallery/search')
|
||||
.query({ q: query })
|
||||
.set({ Authorization: `Client-ID ${IMGUR_KEY}` });
|
||||
const images = body.data.filter(image => image.images && (msg.channel.nsfw ? true : !image.nsfw));
|
||||
if (!images.length) return msg.say('Could not find any results.');
|
||||
return msg.say(images[Math.floor(Math.random() * images.length)].images[0].link);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user