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 

Updated horoscope pls
Goto page Previous  1, 2
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Dominatez
Voice


Joined: 14 Jan 2019
Posts: 28
Location: United Kingdom

PostPosted: Tue Jul 23, 2019 1:21 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
heartbroken
Halfop


Joined: 23 Jun 2011
Posts: 96
Location: somewhere out there

PostPosted: Wed Jul 24, 2019 9:09 am    Post subject: Reply with quote

Updated, Thank you!



This one for Tcl8.6:

Code:
# 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 chan 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"
          }
       }
    }
 }





And this also works with Tcl8.5:

Code:
 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 chan 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"
       }
    }
 }

_________________
Life iS Just a dReaM oN tHE wAy to DeaTh
Back to top
View user's profile Send private message
Arnold_X-P
Op


Joined: 30 Oct 2006
Posts: 191
Location: DALnet - Trinidad - Beni - Bolivia

PostPosted: Fri Jul 26, 2019 12:02 am    Post subject: Reply with quote

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/tcl-20/tcl_ext/tcllib/tcllib/modules/htmlparse/htmlparse.tcl.auto.html
or
htmlparse 1.2.2
https://github.com/tcltk/tcllib/blob/master/modules/htmlparse/htmlparse.tcl

which of the two tcl would you use for windrop 6.21 and tcl 8.5
_________________
Very Happy thanks to that they help, that others learn Very Happy
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
heartbroken
Halfop


Joined: 23 Jun 2011
Posts: 96
Location: somewhere out there

PostPosted: Fri Jul 26, 2019 2:02 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Dominatez
Voice


Joined: 14 Jan 2019
Posts: 28
Location: United Kingdom

PostPosted: Mon Aug 05, 2019 12:02 am    Post subject: Reply with quote

Thanks Heartbroken,

Confirming that this works like a charm now on the latest eggdrop.
Back to top
View user's profile Send private message
Brut
Voice


Joined: 20 Sep 2019
Posts: 5

PostPosted: Fri Sep 20, 2019 1:14 am    Post subject: TLS & HTTP Package Require Reply with quote

How to install these tls or http packages in eggdrop ??
Back to top
View user's profile Send private message
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1046

PostPosted: Fri Sep 20, 2019 12:27 pm    Post subject: Re: TLS & HTTP Package Require Reply with quote

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:

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 !
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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