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"
}
}
}
}
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"
}
}
}
I think that both are now included in tcllib. It might be libtcl ... I can never remember which.Brut wrote:How to install these tls or http packages in eggdrop ??
Code: Select all
ii libtcl8.6:amd64 8.6.9+dfsg-2 amd64 Tcl (the Tool Command Language) v8.6 - run-time library files
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)
Code: Select all
bind pub $HoroCmdFlags !aries [namespace current]::HorosPubProcAries
proc HorosPubProcAries {nick uhost hand chan arg} {
HorosPubProcName $nick $uhost $hand $chan aries
}
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
}