mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-24 02:15:10 +02:00
snekfetch
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { promisify } = require('tsubaki');
|
||||
const xml = promisify(require('xml2js').parseString);
|
||||
const { ANIMELIST_LOGIN } = process.env;
|
||||
@@ -16,8 +16,7 @@ module.exports = class AnimeCommand extends Command {
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What anime would you like to search for?',
|
||||
type: 'string',
|
||||
parse: query => encodeURIComponent(query)
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -29,9 +28,11 @@ module.exports = class AnimeCommand extends Command {
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { text } = await request
|
||||
.get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/anime/search.xml?q=${query}`)
|
||||
.buffer(true);
|
||||
const { text } = await snekfetch
|
||||
.get(`https://${ANIMELIST_LOGIN}@myanimelist.net/api/anime/search.xml`)
|
||||
.query({
|
||||
q: query
|
||||
});
|
||||
const { anime } = await xml(text);
|
||||
const synopsis = anime.entry[0].synopsis[0].substr(0, 2000)
|
||||
.replace(/(<br \/>)/g, '')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { DISCORD_BOTS_KEY } = process.env;
|
||||
|
||||
module.exports = class BotSearchCommand extends Command {
|
||||
@@ -26,7 +26,7 @@ module.exports = class BotSearchCommand extends Command {
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { bot } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
const { body } = await snekfetch
|
||||
.get(`https://bots.discord.pw/api/bots/${bot.id}`)
|
||||
.set({ 'Authorization': DISCORD_BOTS_KEY });
|
||||
const embed = new RichEmbed()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { WORDNIK_KEY } = process.env;
|
||||
|
||||
module.exports = class DefineCommand extends Command {
|
||||
@@ -27,8 +27,14 @@ module.exports = class DefineCommand extends Command {
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`http://api.wordnik.com:80/v4/word.json/${query}/definitions?limit=1&includeRelated=false&useCanonical=false&api_key=${WORDNIK_KEY}`);
|
||||
const { body } = await snekfetch
|
||||
.get(`http://api.wordnik.com:80/v4/word.json/${query}/definitions`)
|
||||
.query({
|
||||
limit: 1,
|
||||
includeRelated: false,
|
||||
useCanonical: false,
|
||||
api_key: WORDNIK_KEY
|
||||
});
|
||||
if (!body.length) throw new Error('No Results.');
|
||||
const embed = new RichEmbed()
|
||||
.setColor(0x9797FF)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
|
||||
module.exports = class ForecastCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -25,8 +25,12 @@ module.exports = class ForecastCommand extends Command {
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where u=\'f\' AND woeid in (select woeid from geo.places(1) where text="${query}")&format=json`);
|
||||
const { body } = await snekfetch
|
||||
.get('https://query.yahooapis.com/v1/public/yql')
|
||||
.query({
|
||||
q: `select * from weather.forecast where u=\'f\' AND woeid in (select woeid from geo.places(1) where text="${query}")`,
|
||||
format: 'json'
|
||||
});
|
||||
if (!body.query.count) throw new Error('Location Not Found.');
|
||||
const forecasts = body.query.results.channel.item.forecast;
|
||||
const embed = new RichEmbed()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
const cheerio = require('cheerio');
|
||||
const querystring = require('querystring');
|
||||
|
||||
@@ -14,8 +14,7 @@ module.exports = class GoogleCommand extends Command {
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What would you like to search for?',
|
||||
type: 'string',
|
||||
parse: query => encodeURIComponent(query)
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -25,8 +24,11 @@ module.exports = class GoogleCommand extends Command {
|
||||
const { query } = args;
|
||||
const message = await msg.say('Searching...');
|
||||
try {
|
||||
const { text } = await request
|
||||
.get(`https://www.google.com/search?q=${query}`);
|
||||
const { text } = await snekfetch
|
||||
.get(`https://www.google.com/search`)
|
||||
.query({
|
||||
q: query
|
||||
});
|
||||
const $ = cheerio.load(text);
|
||||
let href = $('.r').first().find('a').first().attr('href');
|
||||
if (!href) throw new Error('No Results.');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
|
||||
module.exports = class IMDBCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -13,8 +13,7 @@ module.exports = class IMDBCommand extends Command {
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What movie or TV Show would you like to search for?',
|
||||
type: 'string',
|
||||
parse: query => encodeURIComponent(query)
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -26,8 +25,12 @@ module.exports = class IMDBCommand extends Command {
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`http://www.omdbapi.com/?t=${query}&plot=full`);
|
||||
const { body } = await snekfetch
|
||||
.get(`http://www.omdbapi.com/`)
|
||||
.query({
|
||||
t: query,
|
||||
plot: 'full'
|
||||
});
|
||||
if (body.Error) throw new Error('No Results.');
|
||||
const embed = new RichEmbed()
|
||||
.setColor(0xDBA628)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
|
||||
module.exports = class KonachanCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -26,8 +26,12 @@ module.exports = class KonachanCommand extends Command {
|
||||
return msg.say('This Command requires the `Attach Files` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`https://konachan.net/post.json?tags=${query ? `${query}%20` : ''}order:random&limit=1`);
|
||||
const { body } = await snekfetch
|
||||
.get('https://konachan.net/post.json')
|
||||
.query({
|
||||
tags: `${query ? `${query} ` : ''}order:random`,
|
||||
limit: 1
|
||||
});
|
||||
if (!body.length) throw new Error('No Results.');
|
||||
return msg.channel.send(query ? `Result for ${query}:` : 'Random Image:', { files: [`https:${body[0].file_url}`] })
|
||||
.catch(err => msg.say(err));
|
||||
|
||||
+10
-5
@@ -1,5 +1,5 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { GOOGLE_KEY } = process.env;
|
||||
|
||||
module.exports = class MapCommand extends Command {
|
||||
@@ -24,8 +24,7 @@ module.exports = class MapCommand extends Command {
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What location you like to get a map image for?',
|
||||
type: 'string',
|
||||
parse: query => encodeURIComponent(query)
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -37,8 +36,14 @@ module.exports = class MapCommand extends Command {
|
||||
return msg.say('This Command requires the `Attach Files` Permission.');
|
||||
const { zoom, query } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`https://maps.googleapis.com/maps/api/staticmap?center=${query}&zoom=${zoom}&size=500x500&key=${GOOGLE_KEY}`);
|
||||
const { body } = await snekfetch
|
||||
.get('https://maps.googleapis.com/maps/api/staticmap')
|
||||
.query({
|
||||
center: query,
|
||||
zoom,
|
||||
size: '500x500',
|
||||
key: GOOGLE_KEY
|
||||
});
|
||||
return msg.channel.send({ files: [{ attachment: body, name: 'map.png' }] })
|
||||
.catch(err => msg.say(err));
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
module.exports = class NeopetCommand extends Command {
|
||||
@@ -13,8 +13,7 @@ module.exports = class NeopetCommand extends Command {
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What pet would you like to get the image of?',
|
||||
type: 'string',
|
||||
parse: query => encodeURIComponent(query)
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -23,8 +22,13 @@ module.exports = class NeopetCommand extends Command {
|
||||
async run(msg, args) {
|
||||
const { query } = args;
|
||||
try {
|
||||
const { text } = await request
|
||||
.get(`http://www.sunnyneo.com/petimagefinder.php?name=${query}&size=5&mood=1`);
|
||||
const { text } = await snekfetch
|
||||
.get('http://www.sunnyneo.com/petimagefinder.php')
|
||||
.query({
|
||||
name: query,
|
||||
size: 5,
|
||||
mood: 1
|
||||
});
|
||||
const $ = cheerio.load(text);
|
||||
const link = $('textarea').first().text();
|
||||
if (!link.includes('cp')) throw new Error('Invalid Pet Name.');
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { OSU_KEY } = process.env;
|
||||
|
||||
module.exports = class OsuCommand extends Command {
|
||||
@@ -14,8 +14,7 @@ module.exports = class OsuCommand extends Command {
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What osu username would you like to search for?',
|
||||
type: 'string',
|
||||
parse: query => encodeURIComponent(query)
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -27,8 +26,13 @@ module.exports = class OsuCommand extends Command {
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`https://osu.ppy.sh/api/get_user?k=${OSU_KEY}&u=${query}&type=string`);
|
||||
const { body } = await snekfetch
|
||||
.get('https://osu.ppy.sh/api/get_user')
|
||||
.query({
|
||||
k: OSU_KEY,
|
||||
u: query,
|
||||
type: 'string'
|
||||
});
|
||||
if (!body.length) throw new Error('No Results.');
|
||||
const embed = new RichEmbed()
|
||||
.setColor(0xFF66AA)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { SOUNDCLOUD_KEY } = process.env;
|
||||
|
||||
module.exports = class SoundCloudCommand extends Command {
|
||||
@@ -14,8 +14,7 @@ module.exports = class SoundCloudCommand extends Command {
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What do you want to search SoundCloud for?',
|
||||
type: 'string',
|
||||
parse: text => encodeURIComponent(text)
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -27,8 +26,12 @@ module.exports = class SoundCloudCommand extends Command {
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`https://api.soundcloud.com/tracks?q=${query}&client_id=${SOUNDCLOUD_KEY}`);
|
||||
const { body } = await snekfetch
|
||||
.get(`https://api.soundcloud.com/tracks`)
|
||||
.query({
|
||||
q: query,
|
||||
client_id: SOUNDCLOUD_KEY
|
||||
});
|
||||
if (!body.length) throw new Error('No Results.');
|
||||
const embed = new RichEmbed()
|
||||
.setColor(0xF15A22)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
|
||||
module.exports = class UrbanCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -13,8 +13,7 @@ module.exports = class UrbanCommand extends Command {
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What would you like to define?',
|
||||
type: 'string',
|
||||
parse: text => encodeURIComponent(text)
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -26,8 +25,11 @@ module.exports = class UrbanCommand extends Command {
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`http://api.urbandictionary.com/v0/define?term=${query}`);
|
||||
const { body } = await snekfetch
|
||||
.get(`http://api.urbandictionary.com/v0/define`)
|
||||
.query({
|
||||
term: query
|
||||
});
|
||||
if (!body.list.length) throw new Error('No Results.');
|
||||
const embed = new RichEmbed()
|
||||
.setColor(0x32a8f0)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { WATTPAD_KEY } = process.env;
|
||||
|
||||
module.exports = class WattpadCommand extends Command {
|
||||
@@ -14,8 +14,7 @@ module.exports = class WattpadCommand extends Command {
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What book would you like to search for?',
|
||||
type: 'string',
|
||||
parse: text => encodeURIComponent(text)
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -27,8 +26,12 @@ module.exports = class WattpadCommand extends Command {
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`https://api.wattpad.com:443/v4/stories?query=${query}&limit=1`)
|
||||
const { body } = await snekfetch
|
||||
.get(`https://api.wattpad.com:443/v4/stories`)
|
||||
.query({
|
||||
query,
|
||||
limit: 1
|
||||
})
|
||||
.set({ 'Authorization': `Basic ${WATTPAD_KEY}` });
|
||||
if (!body.stories.length) throw new Error('No Results.');
|
||||
const embed = new RichEmbed()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
|
||||
module.exports = class WeatherCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -25,8 +25,12 @@ module.exports = class WeatherCommand extends Command {
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where u=\'f\' AND woeid in (select woeid from geo.places(1) where text="${query}")&format=json`);
|
||||
const { body } = await snekfetch
|
||||
.get('https://query.yahooapis.com/v1/public/yql')
|
||||
.query({
|
||||
q: `select * from weather.forecast where u=\'f\' AND woeid in (select woeid from geo.places(1) where text="${query}")`,
|
||||
format: 'json'
|
||||
});
|
||||
if (!body.query.count) throw new Error('Location Not Found.');
|
||||
const embed = new RichEmbed()
|
||||
.setColor(0x0000FF)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
|
||||
module.exports = class WikipediaCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -13,8 +13,7 @@ module.exports = class WikipediaCommand extends Command {
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What would you like to search for?',
|
||||
type: 'string',
|
||||
parse: text => encodeURIComponent(text)
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -26,8 +25,18 @@ module.exports = class WikipediaCommand extends Command {
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`https://en.wikipedia.org/w/api.php?action=query&prop=extracts&format=json&titles=${query}&exintro=&explaintext=&redirects=&formatversion=2`);
|
||||
const { body } = await snekfetch
|
||||
.get('https://en.wikipedia.org/w/api.php')
|
||||
.query({
|
||||
action: 'query',
|
||||
prop: 'extracts',
|
||||
format: 'json',
|
||||
titles: query,
|
||||
exintro: '',
|
||||
explaintext: '',
|
||||
redirects: '',
|
||||
formatversion: 2
|
||||
});
|
||||
if (body.query.pages[0].missing) throw new Error('No Results.');
|
||||
const embed = new RichEmbed()
|
||||
.setColor(0xE7E7E7)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
const { GOOGLE_KEY } = process.env;
|
||||
|
||||
module.exports = class YouTubeCommand extends Command {
|
||||
@@ -14,8 +14,7 @@ module.exports = class YouTubeCommand extends Command {
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What would you like to search for?',
|
||||
type: 'string',
|
||||
parse: text => encodeURIComponent(text)
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -27,8 +26,15 @@ module.exports = class YouTubeCommand extends Command {
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&maxResults=1&q=${query}&key=${GOOGLE_KEY}`);
|
||||
const { body } = await snekfetch
|
||||
.get('https://www.googleapis.com/youtube/v3/search')
|
||||
.query({
|
||||
part: 'snippet',
|
||||
type: 'video',
|
||||
maxResults: 1,
|
||||
q: query,
|
||||
key: GOOGLE_KEY
|
||||
});
|
||||
if (!body.items.length) throw new Error('No Results.');
|
||||
const embed = new RichEmbed()
|
||||
.setColor(0xDD2825)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const { RichEmbed } = require('discord.js');
|
||||
const request = require('superagent');
|
||||
const snekfetch = require('snekfetch');
|
||||
|
||||
module.exports = class YuGiOhCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -26,7 +26,7 @@ module.exports = class YuGiOhCommand extends Command {
|
||||
return msg.say('This Command requires the `Embed Links` Permission.');
|
||||
const { query } = args;
|
||||
try {
|
||||
const { body } = await request
|
||||
const { body } = await snekfetch
|
||||
.get(`http://yugiohprices.com/api/card_data/${query}`);
|
||||
if (body.status === 'fail') throw new Error('No Results.');
|
||||
if (body.data.card_type === 'monster') {
|
||||
|
||||
Reference in New Issue
Block a user