Local Xiao Command
@@ -38,7 +38,6 @@ DEVIANTART_SECRET=
|
|||||||
GIPHY_KEY=
|
GIPHY_KEY=
|
||||||
GITHUB_ACCESS_TOKEN=
|
GITHUB_ACCESS_TOKEN=
|
||||||
GOV_KEY=
|
GOV_KEY=
|
||||||
IMGUR_KEY=
|
|
||||||
OPENWEATHERMAP_KEY=
|
OPENWEATHERMAP_KEY=
|
||||||
OSU_KEY=
|
OSU_KEY=
|
||||||
SPOTIFY_KEY=
|
SPOTIFY_KEY=
|
||||||
@@ -47,6 +46,3 @@ USPS_USERID=
|
|||||||
WEBSTER_KEY=
|
WEBSTER_KEY=
|
||||||
XIAO_GITHUB_REPO_NAME=
|
XIAO_GITHUB_REPO_NAME=
|
||||||
XIAO_GITHUB_REPO_USERNAME=
|
XIAO_GITHUB_REPO_USERNAME=
|
||||||
|
|
||||||
# Imgur album IDs
|
|
||||||
XIAO_ALBUM_ID=
|
|
||||||
|
|||||||
|
After Width: | Height: | Size: 100 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 177 KiB |
|
After Width: | Height: | Size: 513 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 168 KiB |
|
After Width: | Height: | Size: 62 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 66 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 207 KiB |
|
After Width: | Height: | Size: 251 KiB |
|
After Width: | Height: | Size: 95 KiB |
|
After Width: | Height: | Size: 264 KiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 323 KiB |
|
After Width: | Height: | Size: 205 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 694 KiB |
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 193 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
After Width: | Height: | Size: 191 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 208 KiB |
|
After Width: | Height: | Size: 73 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 159 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 914 KiB |
|
After Width: | Height: | Size: 79 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 1.1 MiB |
@@ -1,7 +1,9 @@
|
|||||||
const ImgurAlbumCommand = require('../../structures/commands/ImgurAlbum');
|
const Command = require('../../framework/Command');
|
||||||
const { XIAO_ALBUM_ID } = process.env;
|
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) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'xiao',
|
name: 'xiao',
|
||||||
@@ -22,7 +24,8 @@ module.exports = class XiaoCommand extends ImgurAlbumCommand {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
generateText() {
|
run(msg) {
|
||||||
return 'It\'s me, yes?';
|
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!`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
const request = require('node-superfetch');
|
|
||||||
const Command = require('../../framework/Command');
|
|
||||||
const path = require('path');
|
|
||||||
const { reactIfAble } = require('../../util/Util');
|
|
||||||
const { IMGUR_KEY } = process.env;
|
|
||||||
|
|
||||||
module.exports = class ImgurAlbumCommand extends Command {
|
|
||||||
constructor(client, info) {
|
|
||||||
super(client, info);
|
|
||||||
|
|
||||||
this.albumID = info.albumID;
|
|
||||||
this.cache = null;
|
|
||||||
this.credit.push({
|
|
||||||
name: 'Imgur',
|
|
||||||
url: 'https://imgur.com/',
|
|
||||||
reason: 'API',
|
|
||||||
reasonURL: 'https://apidocs.imgur.com/'
|
|
||||||
});
|
|
||||||
this.audio = info.audio || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
async run(msg, { user }) {
|
|
||||||
if (this.audio) {
|
|
||||||
const connection = msg.guild ? this.client.voice.connections.get(msg.guild.id) : null;
|
|
||||||
if (msg.guild && connection && !this.client.dispatchers.has(msg.guild.id)) {
|
|
||||||
const dispatcher = connection.play(path.join(__dirname, '..', '..', 'assets', 'sounds', this.audio));
|
|
||||||
this.client.dispatchers.set(msg.guild.id, dispatcher);
|
|
||||||
dispatcher.once('finish', () => this.client.dispatchers.delete(msg.guild.id));
|
|
||||||
dispatcher.once('error', () => this.client.dispatchers.delete(msg.guild.id));
|
|
||||||
await reactIfAble(msg, this.client.user, '🔉');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const image = await this.random();
|
|
||||||
if (!image) return msg.reply('This album has no images...');
|
|
||||||
return msg.say(this.generateText(msg, user), { files: [image] });
|
|
||||||
} catch (err) {
|
|
||||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
generateText() {
|
|
||||||
throw new Error('The generateText method is required.');
|
|
||||||
}
|
|
||||||
|
|
||||||
async random() {
|
|
||||||
if (this.cache) return this.cache[Math.floor(Math.random() * this.cache.length)];
|
|
||||||
const { body } = await request
|
|
||||||
.get(`https://api.imgur.com/3/album/${this.albumID}`)
|
|
||||||
.set({ Authorization: `Client-ID ${IMGUR_KEY}` });
|
|
||||||
if (!body.data.images.length) return null;
|
|
||||||
this.cache = body.data.images.map(image => image.link);
|
|
||||||
setTimeout(() => { this.cache = null; }, 3.6e+6);
|
|
||||||
return body.data.images[Math.floor(Math.random() * body.data.images.length)].link;
|
|
||||||
}
|
|
||||||
};
|
|
||||||