mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 06:42:50 +02:00
5 New Commands
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
|
||||
module.exports = class IPInfoCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'ip-info',
|
||||
group: 'search',
|
||||
memberName: 'ip-info',
|
||||
description: 'Gets data for an IP address.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'ip',
|
||||
prompt: 'Which IP would you like to get information on?',
|
||||
type: 'string',
|
||||
parse: ip => encodeURIComponent(ip)
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { ip }) {
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
.get(`https://ipinfo.io/${ip}/json`);
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x9797FF)
|
||||
.setURL(`https://ipinfo.io/${ip}`)
|
||||
.setTitle(body.ip)
|
||||
.addField('❯ Hostname',
|
||||
body.hostname, true)
|
||||
.addField('❯ Location',
|
||||
body.loc, true)
|
||||
.addField('❯ Organization',
|
||||
body.org, true)
|
||||
.addField('❯ City',
|
||||
`${body.city} (${body.postal})`, true)
|
||||
.addField('❯ Region',
|
||||
body.region, true)
|
||||
.addField('❯ Country',
|
||||
body.country, true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
if (err.status === 404) return msg.say('Could not find any results.');
|
||||
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,45 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { xml2json } = require('xml-js');
|
||||
const { stripIndents } = require('common-tags');
|
||||
|
||||
module.exports = class SafebooruCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'safebooru',
|
||||
group: 'search',
|
||||
memberName: 'safebooru',
|
||||
description: 'Searches Safebooru for your query.',
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What image would you like to search for?',
|
||||
type: 'string',
|
||||
default: ''
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const { text } = await snekfetch
|
||||
.get('https://safebooru.org/index.php')
|
||||
.query({
|
||||
page: 'dapi',
|
||||
s: 'post',
|
||||
q: 'index',
|
||||
tags: query
|
||||
});
|
||||
const parsed = xml2json(text, { compact: true });
|
||||
if (parsed.posts.count === '0' || !parsed.posts.post.length) return msg.say('Could not find any results.');
|
||||
const posts = msg.channel.nsfw ? parsed.posts.post : parsed.posts.post.filter(post => post.rating === 's');
|
||||
return msg.say(stripIndents`
|
||||
${query ? `Results for ${query}:` : 'Random Image:'}
|
||||
https:${posts[Math.floor(Math.random() * posts.length)].file_url}
|
||||
`);
|
||||
} catch (err) {
|
||||
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user