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: 260
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

##############################################################################################
##  ##                             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.7"
setudef flag google

proc googleweb {nick host hand chan type search} {
      global googlectry googlemax API_KEY SEARCH_ID url googlelogo googleantirepe googleS_ignore
        http::register https 443 {tls::socket -tls1 1}
  set url "https://www.googleapis.com/customsearch/v1?"
      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 - .ghgoogle
bind pub - .google google
bind pub - !google google
bind pub - .gimagen gimage
bind pub - !gimagen gimage

putlog "Google search loaded by $gaucho $googlever" 

Someone help me with the aforementioned detail
Last edited by Arnold_X-P on Wed Oct 22, 2025 1:18 am, edited 5 times 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: 1374
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: 260
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
User avatar
Arnold_X-P
Master
Posts: 260
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Re: Google Search

Post by Arnold_X-P »

I found this error in the Google search :
In the first search it works well for me
.ghgoogle irc
The detail is in the second search it gives me a result and then tells me : I can't find any results for calgaruns it
.ghgoogle calgaruns it
Image
Apparently something is wrong on line 69 & 70
Partyline doesn't show me any errors.
Last edited by Arnold_X-P on Wed Oct 22, 2025 1:20 am, 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
Arnold_X-P
Master
Posts: 260
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Re: Google Search

Post by Arnold_X-P »

I also uploaded the code to the paste page and it made me notice that it has errors in http://paste.tclhelp.net/?id=72ne
Image
Can you help me with those two options that I showed?
.: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: 1374
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: Google Search

Post by CrazyCat »

Well, you use tls but I can't see any package require tls
This is probably the main trouble.

And I don't see any bind for .ghgoogle so I don't think you shhow us the script you actually use.
User avatar
Arnold_X-P
Master
Posts: 260
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Re: Google Search

Post by Arnold_X-P »

the code I use

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 ##

package require http
package require json

##############################################################################################
##  ##                             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.7"
setudef flag google

proc googleweb {nick host hand chan type search} {
      global googlectry googlemax API_KEY SEARCH_ID url googlelogo googleantirepe googleS_ignore
        http::register https 443 {tls::socket -tls1 1}
  set url "https://www.googleapis.com/customsearch/v1?"
      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 $index $title $link"]
            } else {
               puthelp "PRIVMSG $chan :$googlelogo I can't find any results for $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 - .ghgoogle google
bind pub - .google google
bind pub - !google google
bind pub - .gimagen gimage
bind pub - !gimagen gimage

putlog "Google search loaded by $gaucho $googlever" 
and the paste http://paste.tclhelp.net/?id=72nf
.: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: 1374
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: Google Search

Post by CrazyCat »

As previous: add package require tls.

And concerning the warnings on tclhelp, don't mind about them. They are just warning because the code isn't following the good precepts of coding.
User avatar
Arnold_X-P
Master
Posts: 260
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Re: Google Search

Post by Arnold_X-P »

has TLS installed.
.: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