The wait time for a search sometimes doesn't work properly. I'm referring to this section: set googleantirepe 14
Code: Select all
##############################################################################################
## Advanced Google.tcl for eggdrop by CP1832 & Arnold_X-P networks: DALnet #tcls ChatZona #tcl Libera.Chat #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 {tls::socket -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 "ID-Key"
## time in seconds before requesting a search ##
set googleantirepe 14
set googleS_ignore [dict create]
##############################################################################################
## ## End Setup. ## ##
##############################################################################################
set gaucho "CP1832 & Arnold_X-P"
set googlever "v3.5.1"
setudef flag google
proc googleweb {nick host hand chan type search} {
global googlectry googlemax API_KEY SEARCH_ID url googlelogo googleantirepe googleS_ignore
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 {
if { $googleantirepe >= 0 } {
if {[dict exists $googleS_ignore $host] && [dict get $googleS_ignore $host] >= [unixtime]} {
putserv "NOTICE $nick :$googlelogo please must wait $googleantirepe seconds to perform a search."
return 0
}
dict set googleS_ignore $host [expr [unixtime] + $googleantirepe]
utimer $googleantirepe [list dict unset googleS_ignore $host]
}
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 [encoding convertfrom utf-8 "PRIVMSG $chan :$googlelogo $title $link"]
} else {
puthelp "PRIVMSG $chan :$googlelogo I can't find any results for 4$search."
}
}
}
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"
Someone help me with the aforementioned detail