Code: Select all
package require http
# to activate on a #channel : .chanset #channel +horo
setudef flag horo
bind pub - .horo horo_pub
proc horo_pub {nick uhost hand chan text} {
if {![channel get $chan horo]} { return }
set q [lindex [split [string tolower $text]] 0]
set horos "Aries|Taurus|Gemini|Cancer|Leo|Virgo|Libra|Scorpio|Sagittarius|Capricorn|Aquarius|Pisces"
if {$q eq ""} {
puthelp "NOTICE $nick :\002Usage\002 : \00304$::lastbind $horos\003"
return 0
}
if {[regexp -nocase -- $q $horos]} {
set url [http::geturl "http://www.lcblack.com/horoscope?sign=$q" -timeout 4000]
set data [split [http::data $url] \n]
http::cleanup $url
regexp {<div class="horoscope">(.*?)</p>} $data "" output
regsub -all -- "<p>" $output "" output
regsub -all -- \} $output "" output
regsub -all -- \{ $output "" output
puthelp "PRIVMSG $chan :\00312$output\003"
} else {
puthelp "NOTICE $nick :\00303$horos\003"
}
return 0
}
Code: Select all
package require http
# to activate on a #channel : .chanset #channel +horo
setudef flag horo
bind pub - .horo horo_pub
proc horo_pub {nick uhost hand chan text} {
if {![channel get $chan horo]} { return 0 }
set q [lindex [split [string tolower $text]] 0]
set horos "Aries|Taurus|Gemini|Cancer|Leo|Virgo|Libra|Scorpio|Sagittarius|Capricorn|Aquarius|Pisces"
if {$q eq ""} { puthelp "NOTICE $nick :\002Usage\002 : \00304$::lastbind $horos\003"; return 0 }
if {[regexp -nocase -- $q $horos]} {
set url [http::geturl "http://www.lcblack.com/horoscope?sign=$q" -timeout 4000]
set data [split [http::data $url] \n]
http::cleanup $url
regexp {horoscope_date">(.*?)<.+horoscope_title">(.*?)<.+horoscope">(.*?)</p>} $data "" hdate htitle houtput
#regexp {aspects_title">(.*?)</h3>.+aspect_time">(.*?)<.+aspect_event">(.*?)<.+aspect_meaning">(.*?)<} $data "" atitle atime aevent ameaning
regexp {love">(.*?)<span>(.*?)<.+communication">(.*?)<span>(.*?)<.+work">(.*?)<span>(.*?)<} $data "" love lno comm cno work wno
set houtput [string map {\} "" \{ "" <p> ""} [string trim $houtput]]
#set aspects "\00302$atitle\003 - \00304$atime\003 - \00305$aevent\003 : \00314$ameaning\003"
set lcw "\00304$love\003 : \002$lno\002 - \00304$comm\003 : \002$cno\002 - \00304$work\003 : \002$wno\002"
#set aspects [string map {\} "" \{ ""} [string trim $aspects]]
set lcw [string map {\} "" \{ ""} [string trim $lcw]]
puthelp "PRIVMSG $chan :\00309$hdate\003 - \00312$htitle\003 :"
puthelp "PRIVMSG $chan :\00314$houtput\003"
#puthelp "PRIVMSG $chan :$aspects"
puthelp "PRIVMSG $chan :$lcw"
} else {
puthelp "NOTICE $nick :\00303$horos\003"
}
return 0
}
.horo aries
< bot > Wednesday, July 9 - Today's Horoscope :
< bot > Set long-range goals over the next two days. Start planning a vacation or trip. Don't quit your day job yet, but get your ducks in a row. Remember home obligations. Stick to practical actions.
< bot> Love : 9 - Communication : 9 - Work : 8
.horo cancer
< bot > Wednesday, July 9 - Today's Horoscope :
< bot > The work's intricate, but rewarding for the next two days. Ask for more and get it. Keep costs down as much as possible. Get into action. With diligence, you'll succeed. Take a deep bow.
< bot > Love : 9 - Communication : 8 - Work : 8
Code: Select all
package require http
# to activate on a #channel : .chanset #channel +horo
setudef flag horo
bind pub - .horo horo_pub
proc horo_pub {nick uhost hand chan text} {
if {![channel get $chan horo]} { return 0 }
set q [lindex [split [string tolower $text]] 0]
set horos "Aries|Taurus|Gemini|Cancer|Leo|Virgo|Libra|Scorpio|Sagittarius|Capricorn|Aquarius|Pisces"
if {[llength $q] < 1 || ![regexp -nocase -- $q $horos]} {
puthelp "NOTICE $nick :\002Usage\002 : \00304$::lastbind $horos\003"
return 0
}
set url [http::geturl "http://www.lcblack.com/horoscope?sign=$q" -timeout 4000]
set data [split [http::data $url] \n]
http::cleanup $url
regexp {horoscope_date">(.*?)<.+horoscope_title">(.*?)<.+horoscope">(.*?)</p>} $data "" hdate htitle houtput
#regexp {aspects_title">(.*?)</h3>.+aspect_time">(.*?)<.+aspect_event">(.*?)<.+aspect_meaning">(.*?)<} $data "" atitle atime aevent ameaning
regexp {love">(.*?)<span>(.*?)<.+communication">(.*?)<span>(.*?)<.+work">(.*?)<span>(.*?)<} $data "" love lno comm cno work wno
if {[info exists houtput]} {
set houtput [string map {\} "" \{ "" <p> ""} [string trim $houtput]]
#set aspects "\00302$atitle\003 - \00304$atime\003 - \00305$aevent\003 : \00314$ameaning\003"
set lcw "\00304$love\003 : \002$lno\002 - \00304$comm\003 : \002$cno\002 - \00304$work\003 : \002$wno\002"
#set aspects [string map {\} "" \{ ""} [string trim $aspects]]
set lcw [string map {\} "" \{ ""} [string trim $lcw]]
puthelp "PRIVMSG $chan :\00309$hdate\003 - \00312$htitle\003 :"
puthelp "PRIVMSG $chan :\00314$houtput\003"
#puthelp "PRIVMSG $chan :$aspects"
puthelp "PRIVMSG $chan :$lcw"
} else {
putlog "err...nothing found."
}
return 0
}
Code: Select all
package require http
package require tls
package require htmlparse
setudef flag horoscope
set horo_cmds ".horo !horos !horoscope"
set horobot_PM 1
set horo_EggFlags -|-
foreach HoroCmd [split $horo_cmds { }] {
bind pub $horo_EggFlags $HoroCmd horo_Pubs
if {$horobot_PM != "" && $horobot_PM >= 1} {
bind msg $horo_EggFlags $HoroCmd horo_BotPM
}
}
::http::register https 443 [list ::tls::socket -ssl2 0 -ssl3 0 -tls1 1]
proc horo_BotPM {nick uhost hand text} {
Horo_MainProc $nick $uhost $hand $nick $text
}
proc horo_Pubs {nick uhost hand chan text} {
if {![channel get $chan horoscope]} { return }
Horo_MainProc $nick $uhost $hand $chan $text
}
proc Horo_MainProc {nick uhost hand chan text} {
set ValidHoros [list aries taurus gemini cancer leo virgo libra scorpio sagittarius capricorn aquarius pisces]
set HoroQuery [lindex [split [string trimleft [stripcodes abcgru $text]]] 0]
if {![llength $HoroQuery]} {
puthelp "PRIVMSG $chan :Usage: $::lastbind <Horoscope>"
return
} elseif {[lsearch -nocase $ValidHoros $HoroQuery] == -1} {
puthelp "PRIVMSG $chan :\"$HoroQuery\" is not a valid query!"
return
} else {
set HoroData [fetch_Horo_HTML https://www.lcblack.com/${HoroQuery}_horoscope]
set HoroRE {_date">(.*?)<.+?title">(.*?)</.+?cope">(.*?)</p>.+?love">(.*?)</li>.+?">(.*?)</li>.+?">(.*?)</li>}
if {[regexp -- $HoroRE $HoroData -> Date Title Horoscope Love Communication Work]} {
puthelp "PRIVMSG $chan :\00312$Date\003 [Clean_HoroHTML $Title]"
puthelp "PRIVMSG $chan :[Clean_HoroHTML $Horoscope]"
puthelp "PRIVMSG $chan :\002[Clean_HoroHTML $Love] \002[Clean_HoroHTML $Communication] \002[Clean_HoroHTML $Work]"
} else {
putcmdlog "[file tail [info script]] Regexp fails to match: https://www.lcblack.com/${HoroQuery}_horoscope"
}
}
return 0
}
proc Clean_HoroHTML Horo {
regsub -all -- {(?:<b>|</b>)} $Horo \002 Horo
regsub -all -- {<span>(.*?)</span>} $Horo \002\00304\\0\003 Horo
regsub -all -- "<.+?>" $Horo { } Horo
regsub -all -- {\s+} $Horo " " Horo
return [string trim $Horo]
}
proc fetch_Horo_HTML HoroURL {
if {[catch {set HoroTok [http::geturl $HoroURL -timeout 12000]} Error]} {
putcmdlog "[file tail [info script]]: [string map {\n " "} $Error]"
return
}
if {[http::status $HoroTok] eq "ok" && [http::ncode $HoroTok] == 200} {
set HoroHTML [http::data $HoroTok]
} else {
putcmdlog "[file tail [info script]]: [http::status $HoroTok] - [http::code $HoroTok]"
}
::http::cleanup $HoroTok
if {[string length $HoroHTML] && [info exists HoroHTML]} {
return [htmlparse::mapEscapes $HoroHTML]
}
}
putlog "[file tail [info script]] loaded!"
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 {<div class="ratings">(.+?)</div>}
# daily horoscope regexp
variable HoroDailyRE {<strong class="date">(.*?)</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"
}
}
}
}
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 {<div class="ratings">(.+?)</div>}
variable HoroDailyRE {<strong class="date">(.*?)</p>}
variable HoroMatchesRE {<h3>(.*?)</h3>.+?love\">(.*?)</p>.+?friend\">(.*?)</p>.+?career\">(.*?)</p>}
variable UnicodeBlackStar \u2605
variable UnicodeWhiteStar \u2606
variable TimeOutHoro 12
variable MoodRatings "\00303Today'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"
}
}
}