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.

TCL of google no longer works .. By FordLawnmower

Help for those learning Tcl or writing their own scripts.
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Post by Arnold_X-P »

I added and it does not work
I make the request in white and looking directly

if {$search == ""} {puthelp "PRIVMSG $chan :Error: <search> is empty"; return 1 }

so the bot should answer
in channel
[12:09] <Arnold_X-P> .google
[12:09] <@JulieTh> Error: <search> is empty

but never responds jumps directly to search request
example:
[12:09] <Arnold_X-P> .google
[12:09] <@JulieTh> Error querying Google: 403 -> ok

the correct is
[12:09] <Arnold_X-P> .google
[12:09] <@JulieTh> Error: <search> is empty
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

What piece of code are you using?
Once the game is over, the king and the pawn go back in the same box.
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Post by Arnold_X-P »

hi caesar
that tcl am using

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"
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
C
CP1832
Halfop
Posts: 68
Joined: Thu Oct 09, 2014 4:03 pm

Post by CP1832 »

Another mistake I found. args is a special name and is considered a list, so braces are added between the values. Renaming it solves the problem. With this 2 lines replacing the original ones it should work.

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.
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Post by Arnold_X-P »

Now if it's okay with no errors..

[16:05] <Arnold_X-P> .recargar
[16:05] -JulieTh:#tcls- el Rehashing fue completado...-= Ejecutado =-
[16:05] <Arnold_X-P> .google
[16:06] <@JulieTh> Error: <search> is empty
[16:06] <Arnold_X-P> .google tcl
[16:06] <@JulieTh> Error querying Google: 403 -> ok
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Post by Arnold_X-P »

friend
register as a user and password in google api
and register one but not my

set API_KEY "AIzaSyD290rR6-rFyDRDD5aOerzxflCfZskE7q0"
set SEARCH_ID "eggdrop"
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
C
CP1832
Halfop
Posts: 68
Joined: Thu Oct 09, 2014 4:03 pm

Post by CP1832 »

Arnold_X-P wrote:set API_KEY "AIzaSyD290rR6-rFyDRDD5aOerzxflCfZskE7q0"
set SEARCH_ID "eggdrop"
The API_KEY seems right but the search ID looks wrong, it has to be obtained from Image
I really don't remember how I got there and I can't find the tutorial I used, sorry. It has to somewhere here: https://www.google.com/search?q=api+key ... gws_rd=ssl
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Post by Arnold_X-P »

I try on many websites and it does not work
api to create the new search engine ....


:shock: :shock: :shock: :shock: :shock:
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Post by Arnold_X-P »

someone who teaches me google api register an account to use this tcl
someone who teaches me google api register an account to use this tcl


look manuals but there is not one clear that teaches detail

:cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry:
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Post by Arnold_X-P »

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


:roll: :roll: :roll: :roll: :roll: :roll:
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
C
CP1832
Halfop
Posts: 68
Joined: Thu Oct 09, 2014 4:03 pm

Post by CP1832 »

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


:roll: :roll: :roll: :roll: :roll: :roll:
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.

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
I edited the script and entered wrong API keys and started getting 400 errors as you are.

Code: Select all

(2016-07-01 16:50:20) CP1832: .google mirc
(2016-07-01 16:50:22) Eggdrop: Error querying Google: 400 -> ok
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Post by Arnold_X-P »

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
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
C
CP1832
Halfop
Posts: 68
Joined: Thu Oct 09, 2014 4:03 pm

Post by CP1832 »

Arnold_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
Hi Arnold_X-P, I found the manual I used to create my google search API: https://www.imarc.com/blog/google-custom-search
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

google

Post by Arnold_X-P »

Solved
This tcl for its correct functioning requires the following

in eggdrop
step 1
conf down and add in two tcl:
http.tcl
json.tcl

these three add tcl in the conf:
source scripts/http.tcl
source scripts/json.tcl

in windrop
step 1
conf down and add in three tcl:
http.tcl
tls.tcl
json.tcl

these three add tcl in the conf:
source scripts/http.tcl
source scripts/tls.tcl
source scripts/json.tcl

step two
then down
tls lib
unzip the contents and paste in your directory. example;
\lib\tcl8.5

and that's all ready, will be working well...

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" 
Last edited by Arnold_X-P on Thu Nov 18, 2021 3:27 am, edited 3 times in total.
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
t
taxick
Voice
Posts: 24
Joined: Thu Jul 12, 2007 11:44 am

Re: google

Post by taxick »

Hi.

I have followed your guide, but I get this error when i type "!google superman"
Google Timeout connecting to Google: protocol not supported
I'm running eggdrop 1.8.1 and I'm on Ubuntu 17.04

I have inserted my own keys, by following this guide: https://www.imarc.com/blog/google-custom-search

Hope you can help me out here

EDIT: I have try to turn my firewall off, and it doesn't help
Post Reply