mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 22:32:52 +02:00
Safebooru
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
const Command = require('../../structures/Command');
|
||||||
|
const { stripIndents } = require('common-tags');
|
||||||
|
const snekfetch = require('snekfetch');
|
||||||
|
const { promisifyAll } = require('tsubaki');
|
||||||
|
const xml = promisifyAll(require('xml2js'));
|
||||||
|
|
||||||
|
module.exports = class SafebooruCommand extends Command {
|
||||||
|
constructor(client) {
|
||||||
|
super(client, {
|
||||||
|
name: 'safebooru',
|
||||||
|
group: 'random-img',
|
||||||
|
memberName: 'safebooru',
|
||||||
|
description: 'Searches Safebooru with optional query.',
|
||||||
|
nsfw: true,
|
||||||
|
args: [
|
||||||
|
{
|
||||||
|
key: 'query',
|
||||||
|
prompt: 'What would you like to search for?',
|
||||||
|
type: 'string',
|
||||||
|
default: ''
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(msg, args) {
|
||||||
|
const { query } = args;
|
||||||
|
const { text } = await snekfetch
|
||||||
|
.get('http://safebooru.org/index.php')
|
||||||
|
.query({
|
||||||
|
page: 'dapi',
|
||||||
|
s: 'post',
|
||||||
|
q: 'index',
|
||||||
|
tags: query,
|
||||||
|
limit: 200
|
||||||
|
});
|
||||||
|
const { posts } = await xml.parseStringAsync(text);
|
||||||
|
if (posts.$.count === '0') return msg.say('No Results.');
|
||||||
|
return msg.say(stripIndents`
|
||||||
|
${query ? `Result for ${query}:` : 'Random Image:'}
|
||||||
|
http:${posts.post[Math.floor(Math.random() * posts.post.length)].$.file_url}
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
};
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "xiaobot",
|
"name": "xiaobot",
|
||||||
"version": "29.1.7",
|
"version": "29.2.0",
|
||||||
"description": "Your personal server companion.",
|
"description": "Your personal server companion.",
|
||||||
"main": "Shard.js",
|
"main": "Shard.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user