egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

I need script for searching

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
SlaSerX
Voice


Joined: 30 Nov 2013
Posts: 9

PostPosted: Mon Dec 21, 2020 5:06 am    Post subject: I need script for searching Reply with quote

Hello i need a script which search on https://darkhelp.uk/ when type example !search terms
he search on https://darkhelp.uk/ and show result in channel

Thx for helping
Back to top
View user's profile Send private message
CP1832
Halfop


Joined: 09 Oct 2014
Posts: 68

PostPosted: Mon Dec 21, 2020 10:29 pm    Post subject: Re: I need script for searching Reply with quote

This is the script I'm using to query google. You can replace the youtube section of the code (at the very bottom) with whichever site you want to google into.
Code:
##############################################################################################
##  ## 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) ##  ##
##############################################################################################

catch {package require foobar}
catch {package require http}
catch {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 -tls1 1]
set url https://$url
} else { set url http://$url }

##############################################################################################
##  ##                             Start Setup.                                         ##  ##
##############################################################################################
## Change the character between the "" below to change the command character/trigger.       ##
set cmdchar "."
## 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 "1"
set API_KEY   "YOUR API KEY"
set SEARCH_ID   "YOUR ID"
##############################################################################################
##  ##                           End Setup.                                              ## ##
##############################################################################################

proc googleweb {nick host hand chan type search site} {
      global googlectry googlemax API_KEY SEARCH_ID url
        if {$search == ""} {puthelp "PRIVMSG $chan :Error: <search> is blank"; return 1 }
      if {$type == ""} {
   set googleurl $url[::http::formatQuery alt json key $API_KEY cx $SEARCH_ID hl $googlectry siteSearch $site q $search]
   } else { set googleurl $url[::http::formatQuery alt json key $API_KEY cx $SEARCH_ID hl $googlectry siteSearch $site q $search searchType $type] }
      if {[catch {http::geturl $googleurl -timeout 5000} sockerr]} {
         puthelp "privmsg $chan :Timeout querying 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]} {
               puthelp "PRIVMSG $chan :[encoding convertfrom utf-8 [dehex $title]] $link"
            } else {
               puthelp "PRIVMSG $chan :Google found no results"
            }
         }
      }
return 1
}

proc dehex {string} {
    regsub -all {[\[]} $string "\(" string
    regsub -all {[\]]} $string "\)" string
    regsub -all {^\{|\}$} $string "" string
    set string [subst [regsub -nocase -all {\\u([a-f0-9]{4})} $string {[format %c [decimal \1]]}]]
    set string [subst [regsub -nocase -all {\%([a-f0-9]{2})} $string {[format %c [decimal \1]]}]]
    set string [subst [regsub -nocase -all {\&#([0-9]{2});} $string {[format %c \1]}]]
    set string [subst [regsub -nocase -all {\&#x([0-9]{2});} $string {[format %c [decimal \1]]}]]
    set string [string map {&quot; \" &middot; · &amp; & <b> \002 </b> \002 &ndash; – &raquo; \
    » &laquo; « &Uuml; Ü &uuml; ü &Aacute; Á &aacute; á &Eacute; É &eacute; é &Iacute; Í &iacute; \
    í &Oacute; Ó &oacute; ó &Ntilde; Ñ &ntilde; ñ &Uacute; Ú &uacute; ú &aelig; æ &nbsp; " " &apos; \' \
   \( \002\(\002 \) \002\)\002 \{ \002\{\002 \} \002\}\002} $string]
    return $string
}

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 - ${cmdchar}google google
bind pub - ${cmdchar}gimage gimage

proc youtube {nick host hand chan text} { googleweb $nick $host $hand $chan "" $text youtube.com/watch }

foreach bind [binds youtube] {lassign $bind type flags mask num proc; unbind $type $flags $mask $proc}

bind pub - ${cmdchar}youtube youtube

putlog "Google script loaded"
Back to top
View user's profile Send private message
SlaSerX
Voice


Joined: 30 Nov 2013
Posts: 9

PostPosted: Tue Dec 22, 2020 11:50 am    Post subject: Reply with quote

i try but
20<SlaSerX>30 .google linux
18<Test118> Error querying Google: 403 -> ok
20<SlaSerX>30 .google test
18<Test118> Error querying Google: 403 -> ok

i setup my api and etc
Back to top
View user's profile Send private message
CP1832
Halfop


Joined: 09 Oct 2014
Posts: 68

PostPosted: Tue Dec 22, 2020 12:30 pm    Post subject: Reply with quote

SlaSerX wrote:
i try but
20<SlaSerX>30 .google linux
18<Test118> Error querying Google: 403 -> ok
20<SlaSerX>30 .google test
18<Test118> Error querying Google: 403 -> ok

i setup my api and etc
It's a 403 error. That means someone is banning you from accessing google, maybe a proxy? Are you sure the API key and the search ID work? It works flawlessly on my end
Code:
(2020-12-22 13:27:56) CP1832: .youtube elephant stone
(2020-12-22 13:28:00) BOT: The Stone Roses - Elephant Stone https://www.youtube.com/watch?v=LcyK-edUByk
Back to top
View user's profile Send private message
SlaSerX
Voice


Joined: 30 Nov 2013
Posts: 9

PostPosted: Tue Dec 22, 2020 4:10 pm    Post subject: Reply with quote

from where u take api and token from google console ?
Back to top
View user's profile Send private message
ComputerTech
Master


Joined: 22 Feb 2020
Posts: 393

PostPosted: Thu Dec 24, 2020 6:28 pm    Post subject: Reply with quote

SlaSerX wrote:
from where u take api and token from google console ?


This should be sufficient.

https://developers.google.com/webmaster-tools/search-console-api/v1/configure
_________________
ComputerTech
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber