Local Xiao Command

This commit is contained in:
Dragon Fire
2024-03-21 21:44:56 -04:00
parent d1104a9670
commit 498390a9eb
43 changed files with 8 additions and 108 deletions
-4
View File
@@ -38,7 +38,6 @@ DEVIANTART_SECRET=
GIPHY_KEY=
GITHUB_ACCESS_TOKEN=
GOV_KEY=
IMGUR_KEY=
OPENWEATHERMAP_KEY=
OSU_KEY=
SPOTIFY_KEY=
@@ -47,6 +46,3 @@ USPS_USERID=
WEBSTER_KEY=
XIAO_GITHUB_REPO_NAME=
XIAO_GITHUB_REPO_USERNAME=
# Imgur album IDs
XIAO_ALBUM_ID=
Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 513 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 264 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 694 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 193 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 208 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 159 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 914 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

+8 -5
View File
@@ -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])] });
}
};
-43
View File
@@ -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!`);
}
}
};
-56
View File
@@ -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;
}
};