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.

Updated horoscope pls

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
User avatar
Dominatez
Halfop
Posts: 50
Joined: Mon Jan 14, 2019 5:08 pm
Location: United Kingdom

Post by Dominatez »

Heartbroken,

Firstly. Thank you for fixing this and making it work, which is an amazing job.

Secondly, today it has started spewing this out.

Somethings wrong with <strong class="date">(.*?)</p>

Somethings wrong with <div class="ratings">(.+?)</div>

Somethings wrong with <h3>(.*?)</h3>.+?love\">(.*?)</p>.+?friend\">(.*?)</p>.+?career\">(.*?)</p>

Any ideas ?

This is the full script for the latest eggdrop.
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

Updated, Thank you!

Image

This one for Tcl8.6:

Code: Select all

# This script using some of Tcl8.6's commands,also needs Tcl-TLS for https links and tcllib for fixed outputs! 
 package require http 
 package require htmlparse 
 package require tls 1.6.4 
 package require textutil::split 
 package present Tcl 8.6 
 package require eggdrop 1.8 

 # to activate on your #channel : .chanset #channel +Horoscope in PartyLine 
 setudef flag Horoscope 

 namespace eval Horoscope { 
     # You can add multiple Horoscope commands with a space between. 
    variable HoroCMD ".horo !horo !horoscope" 
     
    # Would you like to use this script commands in your bot's pvt? 
    # 1 yes , 0 no 
    variable HoroEggPM 1 
     
    # users able to make horo queries in seconds:times 
    variable FludControl 10:3 
     
    # eggdrop user flags : general flags|channel flags 
    variable HoroCmdFlags -|- 
    
    # How many chars would allow to print in a line 
    variable HoroCharsInLineLen 312 
     
    # daily horo query link 
    variable DailyHoroURL {https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-today.aspx} 
     
    # rating stars regexp 
    variable HoroStarsRE {star-ratings\">.+?</div>(.+?)</div>} 
     
    # daily horoscope regexp 
    variable HoroDailyRE {<p><strong>(.*?)</p>} 
     
    # matches regexp 
    variable HoroMatchesRE {<h3>(.*?)</h3>.+?love.+?>(.*?)</p>.+?friend.+?>(.*?)</p>.+?career.+?>(.*?)</p>} 
     
    # for filled star highlight 
    variable UnicodeBlackStar \u2605 
     
    # for filled star outputs 
    variable UnicodeWhiteStar \u2606 
     
    # connection timeout time in seconds 
    variable TimeOutHoro 12 
     
    # ratings title: 
    variable MoodRatings "\00314Today's Star Ratings - Your general mood\003" 
    # end of settings 
     
    foreach CmdSign [split $HoroCMD { }] { 
       bind pub $HoroCmdFlags $CmdSign [namespace current]::HorosPubProcName 
       if {$HoroEggPM >= 1 && [string length $HoroEggPM]} { 
          bind msg $HoroCmdFlags $CmdSign [namespace current]::EggPvtHorosProcName 
       } 
    }; 
    putlog "[file tail [info script]] Loaded!" 

    namespace path {::http:: ::htmlparse:: ::textutil::split::} 
    register https 443 [list tls::socket -ssl2 0 -ssl3 0 -tls1 1] 

    proc MainHoroProcName {nick uhost hand chan text} { 
       variable FludControl ; 
       set TargetHost [lindex [split $uhost @] 1] 
       if {![info exists ::HoroFludVar($TargetHost)] && ![info exists ::HoroFludVar($nick)]} { 
          array set ::HoroFludVar [list $nick [clock seconds] $TargetHost 0] 
       } else { 
          incr ::HoroFludVar($TargetHost) 
       } 
       if {([expr {[clock seconds] - $::HoroFludVar($nick)}] <= [lindex [split $FludControl :] 0]) && ($::HoroFludVar($TargetHost) >= [lindex [split $FludControl :] 1])} { 
          putserv "NOTICE $nick :$nick You able to use $::lastbind command [lindex [split $FludControl :] 1] times in [lindex [split $FludControl :] 0] seconds!"; 
          return 0; 
       } 
       utimer [lindex [split $FludControl :] 0] [list unset -nocomplain ::HoroFludVar($TargetHost) ::HoroFludVar($nick)] 
       set HoroRequest [lindex [split [stripcodes * [string tolower $text]]] 0] 
       set ListOfHoros [dict create aries 1 taurus 2 gemini 3 cancer 4 leo 5 virgo 6 libra 7 scorpio 8 sagittarius 9 capricorn 10 aquarius 11 pisces 12] 
       if {![llength $HoroRequest]} { 
          putserv "NOTICE $nick :Usage: $::lastbind <Horoscope>"; 
          return 0 
       } elseif {$HoroRequest ni [dict keys $ListOfHoros]} { 
          putserv "NOTICE $nick :\"$HoroRequest\" is not valid!"; 
          return 
       } else { 
          set HoroWhatWeGot [::Horoscope::FetchDisHoros ${Horoscope::DailyHoroURL}?sign=[dict get $ListOfHoros $HoroRequest]] 
          if {[regexp -- $Horoscope::HoroDailyRE $HoroWhatWeGot -> TodaysHoro]} { 
             ::Horoscope::PrintHoro $chan [::Horoscope::HoroCleanUp $TodaysHoro] 
          } else { 
             putcmdlog "[file tail [info script]]: Somethings wrong with $Horoscope::HoroDailyRE"; 
          } 
          if {[regexp -- $Horoscope::HoroStarsRE $HoroWhatWeGot -> HiLightStars]} { 
             puthelp "PRIVMSG $chan :$Horoscope::MoodRatings : [::Horoscope::HoroCleanUp $HiLightStars]"; 
          } else { 
             putcmdlog "[file tail [info script]]: Somethings wrong with $Horoscope::HoroStarsRE"; 
          } 
          if {[regexp -- $Horoscope::HoroMatchesRE $HoroWhatWeGot -> Matches Love Friend Career]} { 
             puthelp "PRIVMSG $chan :[::Horoscope::HoroCleanUp [set AllMatches "\00314$Matches\003: $Love - $Friend - $Career"]]"; 
          } else { 
             putcmdlog "[file tail [info script]]: Somethings wrong with $Horoscope::HoroMatchesRE"; 
          } 
       }; 
       return 0 
    } 

    proc HorosPubProcName {nick uhost hand chan arg} { 
       if {![channel get $chan Horoscope]} { return 0 }; 
       ::Horoscope::MainHoroProcName $nick $uhost $hand $chan $arg 
    } 

    proc EggPvtHorosProcName {nick uhost hand arg} { 
       ::Horoscope::MainHoroProcName $nick $uhost $hand $nick $arg 
    } 

    proc PrintHoro {HoroTarget HoroString} { 
       lmap HoroLines [splitn $HoroString $Horoscope::HoroCharsInLineLen] { puthelp "PRIVMSG $HoroTarget :[::Horoscope::HoroCleanUp $HoroLines]" } 
    } 

    proc HoroCleanUp HoroHTMLs { 
        regsub -all -- {<i class="icon-star-filled highlight"></i>} $HoroHTMLs \00307$Horoscope::UnicodeBlackStar\003 HoroHTMLs 
        regsub -all -- {<i class="icon-star-filled"></i>} $HoroHTMLs \00314$Horoscope::UnicodeWhiteStar\003 HoroHTMLs 
        #regsub -all -- {(:?<strong>|</strong>|<b>|</b>)} $HoroHTMLs \002 HoroHTMLs 
        regsub -all -- {(:?<h4>|</h4>)} $HoroHTMLs \002 HoroHTMLs 
        regsub -all -- {<p>([^\s]*)} $HoroHTMLs \00304\\0\003  HoroHTMLs 
        regsub -all -- "<.+?>" $HoroHTMLs {} HoroHTMLs 
        regsub -all -- {\s+} $HoroHTMLs " " HoroHTMLs 
        return [string trim $HoroHTMLs] 
     } 

    proc FetchDisHoros Link4Horo { 
       try { 
          set TokenHoro [geturl $Link4Horo -timeout [expr {round(1000 * $Horoscope::TimeOutHoro)}]] 
       } on error { HoroErrorMsg } { 
          putcmdlog "[file tail [info script]]: [string map {\n " "} $HoroErrorMsg]" 
       } finally { 
          if {[status $TokenHoro] eq "ok" && [ncode $TokenHoro] == 200} { 
             set TheHoroData [data $TokenHoro] 
          } else { 
             putcmdlog "[file tail [info script]]: [status $TokenHoro] , [code $TokenHoro]" }; cleanup $TokenHoro 
          if {[info exists TheHoroData] && [string length $TheHoroData]} { 
             return [mapEscapes $TheHoroData] 
          } else { 
             putcmdlog "[file tail [info script]]: Got no any data from: $Link4Horo" 
          } 
       } 
    } 
 }

Image

And this also works with Tcl8.5:

Code: Select all

 package require http 
 package require htmlparse 
 package require tls 1.6.4 

 setudef flag Horoscope 

 namespace eval Horoscope { 

    variable HoroCMD ".horo !horo !horoscope" 

    variable HoroEggPM 1 

    variable FludControl 10:3 

    variable HoroCmdFlags -|- 

    variable HoroWordsInLineLen 36 

    variable DailyHoroURL {https://www.horoscope.com/us/horoscopes/general/horoscope-general-daily-today.aspx} 

    variable HoroStarsRE {star-ratings\">.+?</div>(.+?)</div>}

    variable HoroDailyRE {<p><strong>(.*?)</p>} 

    variable HoroMatchesRE {<h3>(.*?)</h3>.+?love.+?>(.*?)</p>.+?friend.+?>(.*?)</p>.+?career.+?>(.*?)</p>} 

    variable UnicodeBlackStar \u2605 

    variable UnicodeWhiteStar \u2606 

    variable TimeOutHoro 12 

    variable MoodRatings "\00314Today's Star Ratings - Your general mood\003" 

    foreach CmdSign [split $HoroCMD { }] { 
       bind pub $HoroCmdFlags $CmdSign [namespace current]::HorosPubProcName 
       if {$HoroEggPM >= 1 && [string length $HoroEggPM]} { 
          bind msg $HoroCmdFlags $CmdSign [namespace current]::EggPvtHorosProcName 
       } 
    }; 
    putlog "[file tail [info script]] Loaded!" 

    namespace path {::http:: ::htmlparse::} 
    register https 443 [list tls::socket -ssl2 0 -ssl3 0 -tls1 1] 

    proc MainHoroProcName {nick uhost hand chan text} { 
       variable FludControl 
       set TargetHost [lindex [split $uhost @] 1] 
       if {![info exists ::HoroFludVar($TargetHost)] && ![info exists ::HoroFludVar($nick)]} { 
          array set ::HoroFludVar [list $nick [clock seconds] $TargetHost 1] 
       } else { 
          incr ::HoroFludVar($TargetHost) 
       } 
       if {([expr {[clock seconds] - $::HoroFludVar($nick)}] < [lindex [split $FludControl :] 0]) && ($::HoroFludVar($TargetHost) > [lindex [split $FludControl :] 1])} { 
          putserv "NOTICE $nick :$nick You able to use $::lastbind command [lindex [split $FludControl :] 1] times in [lindex [split $FludControl :] 0] seconds!"; 
          return 0; 
       } 
       utimer [lindex [split $FludControl :] 0] [list unset -nocomplain ::HoroFludVar($TargetHost) ::HoroFludVar($nick)] 
       set HoroRequest [lindex [split [stripcodes abcgru [string tolower $text]]] 0] 
       array set ListOfHoros [list aries 1 taurus 2 gemini 3 cancer 4 leo 5 virgo 6 libra 7 scorpio 8 sagittarius 9 capricorn 10 aquarius 11 pisces 12] 
       if {![llength $HoroRequest]} { 
          putserv "NOTICE $nick :Usage: $::lastbind <Horoscope>"; 
          return 0 
       } elseif {$HoroRequest ni [array names ListOfHoros]} { 
          putserv "NOTICE $nick :\"$HoroRequest\" is not valid!"; 
          return 
       } else { 
          set HoroWhatWeGot [::Horoscope::FetchDisHoros ${Horoscope::DailyHoroURL}?sign=$ListOfHoros($HoroRequest)] 
          if {[regexp -- $Horoscope::HoroDailyRE $HoroWhatWeGot -> TodaysHoro]} { 
             ::Horoscope::PrintHoro $chan [::Horoscope::HoroCleanUp $TodaysHoro] 
          } else { 
             putcmdlog "[file tail [info script]]: Somethings wrong with $Horoscope::HoroDailyRE"; 
          } 
          if {[regexp -- $Horoscope::HoroStarsRE $HoroWhatWeGot -> HiLightStars]} { 
              puthelp "PRIVMSG $chan :$Horoscope::MoodRatings : [::Horoscope::HoroCleanUp $HiLightStars]"; 
          } else { 
             putcmdlog "[file tail [info script]]: Somethings wrong with $Horoscope::HoroStarsRE"; 
          } 
          if {[regexp -- $Horoscope::HoroMatchesRE $HoroWhatWeGot -> Matches Love Friend Career]} { 
             puthelp "PRIVMSG $chan :[::Horoscope::HoroCleanUp [set AllMatches "\00314$Matches\003: $Love - $Friend - $Career"]]"; 
          } else { 
             putcmdlog "[file tail [info script]]: Somethings wrong with $Horoscope::HoroMatchesRE"; 
          } 
       }; 
       return 0 
    } 

    proc HorosPubProcName {nick uhost hand chan arg} { 
       if {![channel get $chan Horoscope]} { return 0 }; 
       ::Horoscope::MainHoroProcName $nick $uhost $hand $chan $arg 
    } 

    proc EggPvtHorosProcName {nick uhost hand arg} { 
       ::Horoscope::MainHoroProcName $nick $uhost $hand $nick $arg 
    } 

    proc PrintHoro {HoroTarget HoroString} { 
       if {[set HoroLineLen [llength [set HoroLenght [split $HoroString]]]] > $Horoscope::HoroWordsInLineLen} { 
          for { set i 0 } { $i < $HoroLineLen } { incr i $Horoscope::HoroWordsInLineLen } { 
             if {$i == 0} { 
                puthelp "PRIVMSG $HoroTarget :[join [lrange $HoroLenght $i [expr {$i + ($Horoscope::HoroWordsInLineLen - 1)}]]]" 
             } { 
                puthelp "PRIVMSG $HoroTarget :[join [lrange $HoroLenght $i [expr {$i + ($Horoscope::HoroWordsInLineLen - 1)}]]]" 
             } 
          } 
       } 
    } 

    proc HoroCleanUp HoroHTMLs { 
        regsub -all -- {<i class="icon-star-filled highlight"></i>} $HoroHTMLs \00307$Horoscope::UnicodeBlackStar\003 HoroHTMLs 
        regsub -all -- {<i class="icon-star-filled"></i>} $HoroHTMLs \00314$Horoscope::UnicodeWhiteStar\003 HoroHTMLs 
        #regsub -all -- {(:?<strong>|</strong>|<b>|</b>)} $HoroHTMLs \002 HoroHTMLs 
        regsub -all -- {(:?<h4>|</h4>)} $HoroHTMLs \002 HoroHTMLs 
        regsub -all -- {<p>([^\s]*)} $HoroHTMLs \00304\\0\003  HoroHTMLs 
        regsub -all -- "<.+?>" $HoroHTMLs {} HoroHTMLs 
        regsub -all -- {\s+} $HoroHTMLs " " HoroHTMLs 
        return [string trim $HoroHTMLs] 
     } 

    proc FetchDisHoros Link4Horo { 
       if {[catch { set TokenHoro [geturl $Link4Horo -timeout [expr {round(1000 * $Horoscope::TimeOutHoro)}]] } HoroErrorMsg]} { 
          putcmdlog "[file tail [info script]]: [string map {\n " "} $HoroErrorMsg]" 
       } 
       if {[string equal -nocase [status $TokenHoro] ok] && [ncode $TokenHoro] == 200} { 
          set TheHoroData [data $TokenHoro] 
       } else { 
          putcmdlog "[file tail [info script]]: [status $TokenHoro] , [code $TokenHoro]" 
       }; 
       cleanup $TokenHoro 
       if {[info exists TheHoroData] && [string length $TheHoroData]} { 
          return [mapEscapes $TheHoroData] 
       } else { 
          putcmdlog "[file tail [info script]]: Got no any data from: $Link4Horo" 
       } 
    } 
 }
Last edited by heartbroken on Tue Apr 20, 2021 11:48 pm, edited 1 time in total.
Life iS Just a dReaM oN tHE wAy to DeaTh
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 »

it doesn't work on windrop 6.21 tcl 8.5
I load the tcl from htmlparse
and it generates error...

htmlparse 1.0
https://opensource.apple.com/source/tcl ... .auto.html
or
htmlparse 1.2.2
https://github.com/tcltk/tcllib/blob/ma ... lparse.tcl

which of the two tcl would you use for windrop 6.21 and tcl 8.5
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
User avatar
heartbroken
Op
Posts: 110
Joined: Thu Jun 23, 2011 11:15 pm
Location: somewhere out there

Post by heartbroken »

htmlparse using struct::stack and cmdline packages from tcllib .

try to source it like this : http://paste.tclhelp.net/?id=6g75
Life iS Just a dReaM oN tHE wAy to DeaTh
User avatar
Dominatez
Halfop
Posts: 50
Joined: Mon Jan 14, 2019 5:08 pm
Location: United Kingdom

Post by Dominatez »

Thanks Heartbroken,

Confirming that this works like a charm now on the latest eggdrop.
B
Brut
Voice
Posts: 7
Joined: Fri Sep 20, 2019 1:10 am

TLS & HTTP Package Require

Post by Brut »

How to install these tls or http packages in eggdrop ??
w
willyw
Revered One
Posts: 1205
Joined: Thu Jan 15, 2009 12:55 am

Re: TLS & HTTP Package Require

Post by willyw »

Brut wrote:How to install these tls or http packages in eggdrop ??
I think that both are now included in tcllib. It might be libtcl ... I can never remember which.

Are you using Debian or Ubuntu?
If so, try :
dpkg -l *tcl* | grep ii
to see a list of everything tcl that is currently installed on the system.

I've just now tried it myself on a shell of mine, and got lucky.
Here's one line I see:

Code: Select all

ii  libtcl8.6:amd64  8.6.9+dfsg-2 amd64        Tcl (the Tool Command Language) v8.6 - run-time library files
Lucky, because I don't see a line that look like it would be
tcllib
and ! ... the bot on this shell has both tls and http available to it.
So, in regards to my first statement above - it appears that libtcl is the one you want.

However, something else came to mind. I think that may cover only the http package.
The more I think about it, I think that TLS comes with openssl.
So, do:
dpkg -l *ssl* | grep ii
to see what is installed regarding ssl, on your shell.

I usually find that root access is not necessary to simply view these things.


You can check to see what is available to your bot, without having to load a script that will need one of those, and perhaps crashing your bot if either is not available.

First, be sure that the use of the
.tcl
command is available for your (owner's) use, in the partyline. This is done in eggdrop.conf .
Then do:
.tcl package names
to get a list of packages loaded. ( reference: http://www.tcl.tk/man/tcl8.6/TclCmd/package.htm#M7 )

To try to load a package, for example, do:
.tcl package require http
and see what happens.
Just do another:
.tcl package names
to see if http is now in the list.
You can do:
.tcl package forget http
to unload it, if you wish.

Same for tls .

That command:
package require
is the literal answer to your original question. That command will load a package - if available - into eggdrop. You'll find that command in tcl scripts that use the http package.



If you find that either libtcl or openssl are not installed on your shell's system, that will likely require root access to be able to install either.
Both are available via apt get and take just seconds to install.
If you can't do it, you'll have to ask the system administrator to do it for you.

There *IS* an http.tcl script out there, somewhere. I think it was necessary, in the past, before the http package was available as I've tried to describe above.
In the past, I've used it, too. It is probably mentioned somewhere in this forum, or perhaps google would find it.
I cannot say which is "best", though I suspect it would be to install via apt get, with libtcl.


I hope this helps.
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
K
Klamatiel
Voice
Posts: 1
Joined: Wed Jan 13, 2021 8:54 pm

Post by Klamatiel »

Hi! Can someone update/modify it for CentOS7? I'm a noob at Linux but i have tcltls 1.7.20 and tcl 8.5.13. Thanks.

Tcl error in file 'eggdrop.conf':

Code: Select all

couldn't load file "/usr/lib64/tcl8.5/tcltls1.7.20/tcltls.so": /usr/lib64/tcl8.5/tcltls1.7.20/tcltls.so: undefined symbol: DH_set0_pqg
    while executing
"load [file join $dir tcltls.so] Tls"
    (lambda term "{dir} {
                if {{shared} eq "static"} {
                        load {} Tls
                } els..." line 5)
    invoked from within
"apply {{dir} {
                if {{shared} eq "static"} {
                        load {} Tls
                } else {
                        load [file join $dir tcltls.so] Tls
                }

                set tlsTclInitScript [file join $..."
    ("package ifneeded tls 1.7.20" script)
    invoked from within
"package require tls 1.6.7"
    (file "scripts/h.tcl" line 4)
User avatar
CrazyCat
Revered One
Posts: 1304
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

I think it's a trouble with update of tcllib, but I don't know CentOS so I can't give you the commands to upgrade your system.
a
albozz
Voice
Posts: 8
Joined: Tue Jul 12, 2016 1:40 pm
Location: Albania
Contact:

Post by albozz »

Help me please to make this link https://top-channel.tv/horoskopi/ for horoscope
Thnx..
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

anyway to have this edited to use like

!aries

!taurus

and so on

instead of the default :

!horoscope taurus

!horoscope aries

and so on
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

simo: maybe something like this, 12 times:)

Code: Select all

bind pub $HoroCmdFlags !aries [namespace current]::HorosPubProcAries
proc HorosPubProcAries {nick uhost hand chan arg} {
  HorosPubProcName $nick $uhost $hand $chan aries
}

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thanks spike^^ that seems to do it
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

or this:)

Post by SpiKe^^ »

or try this somewhat shorter method...

Code: Select all

variable HoroList [list aries taurus gemini cancer leo virgo libra scorpio sagittarius capricorn aquarius pisces]

bind pubm $HoroCmdFlags "#% !%" [namespace current]::HorosPubProcAny

proc HorosPubProcAny {nick uhost hand chan arg} {
  set arg [string tolower [string trim $arg "!"]]

  if {$arg ni $Horoscope::HoroList} { return 0 }
  HorosPubProcName $nick $uhost $hand $chan $arg
}

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
s
simo
Revered One
Posts: 1107
Joined: Sun Mar 22, 2015 2:41 pm

Post by simo »

thats even better thanks SpiKe^^ that works well
Post Reply