View previous topic :: View next topic |
Author |
Message |
Dominatez Halfop

Joined: 14 Jan 2019 Posts: 46 Location: United Kingdom
|
Posted: Tue Jul 23, 2019 1:21 pm Post subject: |
|
|
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 |
|
 |
heartbroken Op

Joined: 23 Jun 2011 Posts: 104 Location: somewhere out there
|
Posted: Wed Jul 24, 2019 9:09 am Post subject: |
|
|
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 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 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
Last edited by heartbroken on Tue Apr 20, 2021 11:48 pm; edited 1 time in total |
|
Back to top |
|
 |
Arnold_X-P Master

Joined: 30 Oct 2006 Posts: 220 Location: DALnet - Trinidad - Beni - Bolivia
|
|
Back to top |
|
 |
heartbroken Op

Joined: 23 Jun 2011 Posts: 104 Location: somewhere out there
|
Posted: Fri Jul 26, 2019 2:02 am Post subject: |
|
|
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 |
|
 |
Dominatez Halfop

Joined: 14 Jan 2019 Posts: 46 Location: United Kingdom
|
Posted: Mon Aug 05, 2019 12:02 am Post subject: |
|
|
Thanks Heartbroken,
Confirming that this works like a charm now on the latest eggdrop. |
|
Back to top |
|
 |
Brut Voice
Joined: 20 Sep 2019 Posts: 7
|
Posted: Fri Sep 20, 2019 1:14 am Post subject: TLS & HTTP Package Require |
|
|
How to install these tls or http packages in eggdrop ?? |
|
Back to top |
|
 |
willyw Revered One
Joined: 15 Jan 2009 Posts: 1168
|
Posted: Fri Sep 20, 2019 12:27 pm Post subject: Re: TLS & HTTP Package Require |
|
|
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 |
|
 |
Klamatiel Voice
Joined: 13 Jan 2021 Posts: 1
|
Posted: Wed Jan 13, 2021 8:56 pm Post subject: |
|
|
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: |
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)
|
|
|
Back to top |
|
 |
CrazyCat Owner

Joined: 13 Jan 2002 Posts: 972 Location: France
|
Posted: Thu Jan 14, 2021 7:08 pm Post subject: |
|
|
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. _________________ https://www.eggdrop.fr
Offer me a coffee - Do not ask me help in PM, we are a community. |
|
Back to top |
|
 |
albozz Voice
Joined: 12 Jul 2016 Posts: 8 Location: Albania
|
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 859
|
Posted: Mon Apr 19, 2021 5:33 pm Post subject: |
|
|
anyway to have this edited to use like
!aries
!taurus
and so on
instead of the default :
!horoscope taurus
!horoscope aries
and so on |
|
Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 769 Location: Tennessee, USA
|
Posted: Mon Apr 19, 2021 7:28 pm Post subject: |
|
|
simo: maybe something like this, 12 times:)
Code: |
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
. |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 859
|
Posted: Mon Apr 19, 2021 8:11 pm Post subject: |
|
|
thanks spike^^ that seems to do it |
|
Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 769 Location: Tennessee, USA
|
Posted: Mon Apr 19, 2021 11:25 pm Post subject: or this:) |
|
|
or try this somewhat shorter method...
Code: |
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
. |
|
Back to top |
|
 |
simo Owner
Joined: 22 Mar 2015 Posts: 859
|
Posted: Tue Apr 20, 2021 1:15 pm Post subject: |
|
|
thats even better thanks SpiKe^^ that works well |
|
Back to top |
|
 |
|