mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 02:15:10 +02:00
LOGOS :(
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { xml2js } = require('xml-js');
|
||||
const { stripIndents } = require('common-tags');
|
||||
const { shorten } = require('../../structures/Util');
|
||||
const ratings = {
|
||||
s: 'Safe',
|
||||
q: 'Questionable'
|
||||
};
|
||||
|
||||
module.exports = class SafebooruCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -11,6 +16,7 @@ module.exports = class SafebooruCommand extends Command {
|
||||
group: 'search',
|
||||
memberName: 'safebooru',
|
||||
description: 'Searches Safebooru for your query.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
@@ -36,10 +42,19 @@ module.exports = class SafebooruCommand extends Command {
|
||||
if (parsed._attributes.count === '0' || !parsed.post.length) return msg.say('Could not find any results.');
|
||||
const posts = msg.channel.nsfw ? parsed.post : parsed.post.filter(post => post._attributes.rating === 's');
|
||||
if (!posts.length) return msg.say('Could not find any results.');
|
||||
return msg.say(stripIndents`
|
||||
${query ? `Results for ${query}:` : 'Random Image:'}
|
||||
https:${posts[Math.floor(Math.random() * posts.length)]._attributes.file_url}
|
||||
`);
|
||||
const data = posts[Math.floor(Math.random() * posts.length)]._attributes;
|
||||
const embed = new MessageEmbed()
|
||||
.setAuthor('Safebooru', 'https://i.imgur.com/iGMNwhf.jpg')
|
||||
.setColor(0xC6D2E1)
|
||||
.setURL(`http://safebooru.org/index.php?page=post&s=view&id=${data.id}`)
|
||||
.setImage(`https:${data.file_url}`)
|
||||
.addField('❯ Upload Date',
|
||||
new Date(data.created_at).toDateString(), true)
|
||||
.addField('❯ Rating',
|
||||
ratings[data.rating], true)
|
||||
.addField('❯ Tags',
|
||||
shorten(data.tags, 1000));
|
||||
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