Made image use DuckDuckGo instead of Google Custom Search
This commit is contained in:
parent
ce27b9090e
commit
af8bce1d3e
5 changed files with 83 additions and 30 deletions
|
@ -1,26 +1,25 @@
|
|||
const client = require("../utils/client.js");
|
||||
const paginator = require("../utils/pagination/pagination.js");
|
||||
const fetch = require("node-fetch");
|
||||
const { image_search } = require("duckduckgo-images-api");
|
||||
|
||||
exports.run = async (message, args) => {
|
||||
if (!message.channel.guild.members.get(client.user.id).permission.has("addReactions") && !message.channel.permissionsOf(client.user.id).has("addReactions")) return `${message.author.mention}, I don't have the \`Add Reactions\` permission!`;
|
||||
if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
|
||||
if (args.length === 0) return `${message.author.mention}, you need to provide something to search for!`;
|
||||
const embeds = [];
|
||||
const request = await fetch(`https://www.googleapis.com/customsearch/v1?key=${process.env.GOOGLE}&cx=${process.env.CSE}&safe=active&searchType=image&q=${encodeURIComponent(args.join(" "))}`);
|
||||
const images = await request.json();
|
||||
const images = await image_search({ query: args.join(" "), moderate: true });
|
||||
if (images.error && images.error.code === 403) return `${message.author.mention}, the daily search quota has been exceeded. Check back later.`;
|
||||
if (!images.items) return `${message.author.mention}, I couldn't find any results!`;
|
||||
for (const [i, value] of images.items.entries()) {
|
||||
if (images.length === 0) return `${message.author.mention}, I couldn't find any results!`;
|
||||
for (const [i, value] of images.entries()) {
|
||||
embeds.push({
|
||||
"embed": {
|
||||
"title": "Search Results",
|
||||
"color": 16711680,
|
||||
"footer": {
|
||||
"text": `Page ${i + 1} of ${images.items.length}`
|
||||
"text": `Page ${i + 1} of ${images.length}`
|
||||
},
|
||||
"image": {
|
||||
"url": value.link
|
||||
"url": value.image
|
||||
},
|
||||
"author": {
|
||||
"name": message.author.username,
|
||||
|
@ -34,6 +33,5 @@ exports.run = async (message, args) => {
|
|||
|
||||
exports.aliases = ["im", "photo", "img"];
|
||||
exports.category = 1;
|
||||
exports.help = "Searches for images on Google";
|
||||
exports.requires = "google";
|
||||
exports.help = "Searches for images on DuckDuckGo";
|
||||
exports.params = "[query]";
|
Loading…
Add table
Add a link
Reference in a new issue