This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Google Search

Support & discussion of released scripts, and announcements of new releases.
Post Reply
User avatar
Arnold_X-P
Master
Posts: 243
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Google Search

Post by Arnold_X-P »

Please help.
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
Last edited by Arnold_X-P on Sun May 11, 2025 12:22 pm, edited 1 time in total.
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
networks: DALnet #tcls ChatZona #tcl Libera.Chat #tcls
User avatar
CrazyCat
Revered One
Posts: 1347
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: Google Search

Post by CrazyCat »

Why do you unset googleS_ignore (even with a timer) ? It's useless and probably the root cause of your trouble.

You'd better remove the line, and you can add a debug:
# utimer $googleantirepe [list dict unset googleS_ignore $host]
putlog "Time for $host is [dict get googleS_ignore $host]"
User avatar
Arnold_X-P
Master
Posts: 243
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Re: Google Search

Post by Arnold_X-P »

I'm not sure it will work but I will apply it.

Code: Select all

# utimer $googleantirepe [list dict unset googleS_ignore $host]
putlog "Time for $host is [dict get googleS_ignore $host]"
I apply what you recommend to remove, the TCL stops working and gives me an error

Code: Select all

[16:46:32] Tcl error [google]: missing value to go with key
I have to put it back the way it was before and it works

Code: Select all

utimer $googleantirepe [list dict unset googleS_ignore $host]
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
networks: DALnet #tcls ChatZona #tcl Libera.Chat #tcls
Post Reply