2019-09-13 20:02:41 +00:00
const client = require ( "../utils/client.js" ) ;
2019-12-06 18:47:40 +00:00
const paginator = require ( "../utils/pagination/pagination.js" ) ;
2020-04-24 01:54:57 +00:00
const { image _search } = require ( "duckduckgo-images-api" ) ;
2019-09-13 20:02:41 +00:00
exports . run = async ( message , args ) => {
2020-09-01 22:10:19 +00:00
if ( message . channel . guild && ! 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 && ! 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! ` ;
2019-09-13 20:02:41 +00:00
if ( args . length === 0 ) return ` ${ message . author . mention } , you need to provide something to search for! ` ;
const embeds = [ ] ;
2020-04-24 01:54:57 +00:00
const images = await image _search ( { query : args . join ( " " ) , moderate : true } ) ;
2020-02-06 00:22:43 +00:00
if ( images . error && images . error . code === 403 ) return ` ${ message . author . mention } , the daily search quota has been exceeded. Check back later. ` ;
2020-04-24 01:54:57 +00:00
if ( images . length === 0 ) return ` ${ message . author . mention } , I couldn't find any results! ` ;
for ( const [ i , value ] of images . entries ( ) ) {
2019-09-13 20:02:41 +00:00
embeds . push ( {
"embed" : {
"title" : "Search Results" ,
"color" : 16711680 ,
"footer" : {
2020-04-24 01:54:57 +00:00
"text" : ` Page ${ i + 1 } of ${ images . length } `
2019-09-13 20:02:41 +00:00
} ,
"image" : {
2020-04-24 01:54:57 +00:00
"url" : value . image
2019-09-13 20:02:41 +00:00
} ,
"author" : {
"name" : message . author . username ,
"icon_url" : message . author . avatarURL
}
}
} ) ;
}
return paginator ( message , embeds ) ;
} ;
exports . aliases = [ "im" , "photo" , "img" ] ;
2019-12-02 20:47:22 +00:00
exports . category = 1 ;
2020-04-24 01:54:57 +00:00
exports . help = "Searches for images on DuckDuckGo" ;
2019-12-05 16:58:46 +00:00
exports . params = "[query]" ;