mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-10 19:04:42 +02:00
Google Image Search
This commit is contained in:
@@ -24,9 +24,8 @@ module.exports = class DefineCommand extends commando.Command {
|
|||||||
console.log(`[Command] ${message.content}`);
|
console.log(`[Command] ${message.content}`);
|
||||||
let thingToSearch = encodeURI(message.content.split(" ").slice(1).join(" "));
|
let thingToSearch = encodeURI(message.content.split(" ").slice(1).join(" "));
|
||||||
message.channel.send('Searching...').then(msg => {
|
message.channel.send('Searching...').then(msg => {
|
||||||
const SEARCH_URL = `https://www.google.com/search?q=${thingToSearch}`;
|
|
||||||
request
|
request
|
||||||
.get(SEARCH_URL)
|
.get(`https://www.google.com/search?q=${thingToSearch}`)
|
||||||
.then(function(response) {
|
.then(function(response) {
|
||||||
const $ = cheerio.load(response.text);
|
const $ = cheerio.load(response.text);
|
||||||
let href = $('.r').first().find('a').first().attr('href');
|
let href = $('.r').first().find('a').first().attr('href');
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
const commando = require('discord.js-commando');
|
||||||
|
const request = require('superagent');
|
||||||
|
const cheerio = require('cheerio');
|
||||||
|
|
||||||
|
module.exports = class DefineCommand extends commando.Command {
|
||||||
|
constructor(Client) {
|
||||||
|
super(Client, {
|
||||||
|
name: 'image',
|
||||||
|
aliases: [
|
||||||
|
'searchimage',
|
||||||
|
'googleimages'
|
||||||
|
],
|
||||||
|
group: 'search',
|
||||||
|
memberName: 'image',
|
||||||
|
description: 'Searches Google for an Image. (;image Cat)',
|
||||||
|
examples: [';image Cat']
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(message) {
|
||||||
|
if (message.channel.type !== 'dm') {
|
||||||
|
if (!message.channel.permissionsFor(this.client.user).hasPermission(['SEND_MESSAGES', 'READ_MESSAGES'])) return;
|
||||||
|
}
|
||||||
|
console.log(`[Command] ${message.content}`);
|
||||||
|
let thingToSearch = encodeURI(message.content.split(" ").slice(1).join(" "));
|
||||||
|
message.channel.send('Searching...').then(msg => {
|
||||||
|
request
|
||||||
|
.get(`https://www.google.com/search?tbm=isch&gs_l=img&q=${encodeURI(thingToSearch)}`)
|
||||||
|
.then(function(response) {
|
||||||
|
const $ = cheerio.load(response.text);
|
||||||
|
const result = $('.images_table').find('img').first().attr('src');
|
||||||
|
msg.edit(result);
|
||||||
|
}).catch(function(err) {
|
||||||
|
msg.edit(':x: Error! No Results Found!');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user