Code: Select all
##############################################################################################
## ## Advanced Google.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help ## ##
##############################################################################################
## ## To use this script you must set channel flag +google (ie .chanset #chan +google) ## ##
##############################################################################################
package require http
package require json
if {[catch {package require tls}]} {
set httpsSupport false
} else {
set httpsSupport true
}
set url "www.googleapis.com/customsearch/v1?"
if {$httpsSupport} {
::http::register https 443 [list ::tls::socket -request 1 -require 0 -ssl3 1 -tls1 1]
set url https://$url
} else { set url http://$url }
##############################################################################################
## ## Start Setup. ## ##
##############################################################################################
## Change the country code between the "" below to change the language of your results. ##
set googlectry "en"
## Change the number between the "" below to change the number of results returned. ##
set googlemax "3"
set API_KEY "AIzaSyD290rR6-rFyDRDD5aOerzxflCfZskE7q0"
set SEARCH_ID "eggdroptcl"
##############################################################################################
## ## End Setup. ## ##
##############################################################################################
setudef flag google
proc googleweb {nick host hand chan type search} {
global googlectry googlemax API_KEY SEARCH_ID url
if {![channel get $chan google]} {return}
if {$search == ""} {puthelp "PRIVMSG $chan :Error: <search> is empty"; return 1 }
if {$type == ""} {
set googleurl $url[::http::formatQuery alt json key $API_KEY cx $SEARCH_ID hl $googlectry q $search]
} else { set googleurl $url[::http::formatQuery alt json key $API_KEY cx $SEARCH_ID hl $googlectry q $search searchType $type] }
if {[catch {http::geturl $googleurl -timeout 5000} sockerr]} {
puthelp "privmsg $chan :Timeout connecting to Google: $sockerr"
return 1
} elseif {[http::ncode $sockerr] != 200 || ![string equal [http::status $sockerr] "ok"]} {
puthelp "privmsg $chan :Error querying Google: [http::ncode $sockerr] -> [http::status $sockerr]"
http::cleanup $sockerr
return 1
} else {
set data [http::data $sockerr]
http::cleanup $sockerr
set json [ ::json::json2dict $data ]
for { set i 0 } { $i < $googlemax } { incr i } {
set title ""
set link ""
catch { set title [ dict get [ lindex [ dict get $json items ] $i ] title ] }
catch { set link [ dict get [ lindex [ dict get $json items ] $i ] link ] }
set index [ expr $i + 1 ]
if {[string length $title] && [string length $link]} {
putserv "PRIVMSG $chan :$title $link"
} else {
puthelp "PRIVMSG $chan :Google found no results"
}
}
}
return 1
}
proc google {nick host hand chan args} { googleweb $nick $host $hand $chan "" $args}
proc gimage {nick host hand chan args} { googleweb $nick $host $hand $chan image $args}
foreach bind [binds google] {lassign $bind type flags mask num proc; unbind $type $flags $mask $proc}
foreach bind [binds gimage] {lassign $bind type flags mask num proc; unbind $type $flags $mask $proc}
bind pub - .google google
bind pub - !google google
bind pub - .gimage gimage
putlog "Google script loaded"
Code: Select all
proc google {nick host hand chan text} { googleweb $nick $host $hand $chan "" $text}
proc gimage {nick host hand chan text} { googleweb $nick $host $hand $chan image $text}
https://www.tcl.tk/man/tcl8.5/TclCmd/proc.htm wrote:If the last formal argument has the name args, then a call to the procedure may contain more actual arguments than the procedure has formals. In this case, all of the actual arguments starting at the one that would be assigned to args are combined into a list (as if the list command had been used); this combined value is assigned to the local variable args.
The API_KEY seems right but the search ID looks wrong, it has to be obtained fromArnold_X-P wrote:set API_KEY "AIzaSyD290rR6-rFyDRDD5aOerzxflCfZskE7q0"
set SEARCH_ID "eggdrop"
Hi Arnold, that error is caused due to having a wrong API key or search ID. I have them right and the bot answers every query perfectly.Arnold_X-P wrote:CP1832., this tcl does not work and does not seek
just launch this and never looking:
<@Arnold_X-P> .google mirc
<@JulieTh> Error querying Google: 403 -> ok
<@Arnold_X-P> .google irc
<@JulieTh> Error querying Google: 400 -> ok
and believes the current account and does not work tcl
Code: Select all
(2016-07-01 16:52:04) CP1832: .google mcgyver eggdrop
(2016-07-01 16:52:06) Eggdrop: How to Build an Egg Drop Container with Straws | Egg Drop, Straws ... https://www.pinterest.com/pin/484066659919400998/
(2016-07-01 16:56:19) CP1832: .google stone roses this is the one
(2016-07-01 16:56:21) Eggdrop: The Stone Roses - This Is The One - YouTube https://www.youtube.com/watch?v=-aqY-8cMVdg
Code: Select all
(2016-07-01 16:50:20) CP1832: .google mirc
(2016-07-01 16:50:22) Eggdrop: Error querying Google: 400 -> ok
Hi Arnold_X-P, I found the manual I used to create my google search API: https://www.imarc.com/blog/google-custom-searchArnold_X-P wrote:try a lot of forms and I cannot create an api for the searcher google
use manuals and the same happens to me ..
someone can prepare a manual of as to create an api for search in google
Code: Select all
##############################################################################################
## ## Advanced Google.tcl for eggdrop by CP1832 & Arnold_X-P network: DALnet irc.dal.net channel #tcls
##############################################################################################
## ## To use this script you must set channel flag +google (ie .chanset #chan +google) ## ##
##############################################################################################
## This tcl requires the following in eggdrop: http.tcl json.tcl ##
## This tcl requires the following in windrop: http.tcl json.tcl tls.tcl ##
package require http
package require json
if {[catch {package require tls}]} {
set httpsSupport false
} else {
set httpsSupport true
}
set url "www.googleapis.com/customsearch/v1?"
if {$httpsSupport} {
::http::register https 443 [list ::tls::socket -request 1 -require 0 -ssl3 1 -tls1 1]
set url https://$url
} else { set url http://$url }
##############################################################################################
## ## Start Setup. ## ##
##############################################################################################
## Change the country code between the "" below to change the language of your results. ##
set googlectry "en"
## Change the number between the "" below to change the number of results returned. ##
set googlemax "3"
set googlelogo "12G4o7o12g3l4e"
## google api ##
#you must create a key for your google search engine in https://cloud.google.com/docs/authentication/api-keys?visit_id=637728160970526198-325218571&rd=1 #creating_an_api_key#
set API_KEY "your-api-key"
set SEARCH_ID "your-id"
##############################################################################################
## ## End Setup. ## ##
##############################################################################################
set gaucho "CP1832 & Arnold_X-P"
set googlever "v3.0.0"
setudef flag google
proc googleweb {nick host hand chan type search} {
global googlectry googlemax API_KEY SEARCH_ID url googlelogo
if {![channel get $chan google]} {return}
if {$search == ""} {puthelp "PRIVMSG $chan :Error: <search> is empty"; return 1 }
if {$type == ""} {
set googleurl $url[::http::formatQuery alt json key $API_KEY cx $SEARCH_ID hl $googlectry q $search]
} else { set googleurl $url[::http::formatQuery alt json key $API_KEY cx $SEARCH_ID hl $googlectry q $search searchType $type] }
if {[catch {http::geturl $googleurl -timeout 5000} sockerr]} {
puthelp "privmsg $chan :$googlelogo Timeout connecting to Google: $sockerr"
return 1
} elseif {[http::ncode $sockerr] != 200 || ![string equal [http::status $sockerr] "ok"]} {
puthelp "privmsg $chan :$googlelogo Error querying Google: [http::ncode $sockerr] -> [http::status $sockerr]"
http::cleanup $sockerr
return 1
} else {
set data [http::data $sockerr]
http::cleanup $sockerr
set json [ ::json::json2dict $data ]
for { set i 0 } { $i < $googlemax } { incr i } {
set title ""
set link ""
catch { set title [ dict get [ lindex [ dict get $json items ] $i ] title ] }
catch { set link [ dict get [ lindex [ dict get $json items ] $i ] link ] }
set index [ expr $i + 1 ]
if {[string length $title] && [string length $link]} {
putserv "PRIVMSG $chan :$googlelogo $title $link"
} else {
puthelp "PRIVMSG $chan :$googlelogo found no results"
}
}
}
return 1
}
proc google {nick host hand chan text} { googleweb $nick $host $hand $chan "" $text}
proc gimage {nick host hand chan text} { googleweb $nick $host $hand $chan image $text}
foreach bind [binds google] {lassign $bind type flags mask num proc; unbind $type $flags $mask $proc}
foreach bind [binds gimage] {lassign $bind type flags mask num proc; unbind $type $flags $mask $proc}
bind pub - .google google
bind pub - !google google
putlog "Google search loaded by $gaucho $googlever"
I'm running eggdrop 1.8.1 and I'm on Ubuntu 17.04Google Timeout connecting to Google: protocol not supported