tcl Horoscope for Eggdrop

Moderator: GeekShed.Net Staff

tcl Horoscope for Eggdrop

Postby Ford » Thu Sep 02, 2010 12:24 am

A little tcl script.
Basic Horoscope script for Eggdrop.
Thanks to mentok for testing :)

Trigger: !horo sign
Chanset: +horo

The colors, commandchar and logo can be changed in the setup.
This script will accept the first 3 letters of your sign so you don't have to type the whole sign.

Example Output::

18:49:01 <!Ford_Lawnmower> !horo sco
18:49:03 <QuadraZuadra> Horoscope It will be a stimulating day for you Scorpio! You'll be feeling great and you'll have no trouble channeling all your energy into your activities. But don't be surprised if you encounter some resistance. Creative as your ideas are they may not suit everyone. In fact you may be confronted
18:49:04 <QuadraZuadra> Horoscope with some rebelliousness. Be persuasive and you'll get your way today...
Code: Select all
##############################################################################################
##  ## Horoscope.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help        ##  ##
##############################################################################################
##      To use this script you must set channel flag +horo (ie .chanset #chan +horo)        ##
##############################################################################################
##############################################################################################
##  ##                             Start Setup.                                         ##  ##
##############################################################################################
## Change the character between the "" below to change the command character/trigger.       ##
set horoscopecmdchar "!"
proc horoscope {nick host hand chan search} {
  if {[lsearch -exact [channel info $chan] +horo] != -1} {
## Change the characters between the "" below to change the logo shown with each result.    ##
    set horoscopelogo "\002\00314H\0034o\0038r\00314o\0039s\0034c\00314o\0038p\0039e\002\003"
## Change the format codes between the "" below to change the color/state of the text.      ##
    set textf "\0034"
##############################################################################################
##  ##                           End Setup.                                              ## ##
##############################################################################################
    set horoscopesite uk.horoscopes.lifestyle.yahoo.net
   set horoscopesign [getsign $search]
   if {$horoscopesign == "error"} {
     putserv "PRIVMSG $chan :$horoscopelogo Valid signs are: Aquarius, Pisces, Aries, Taurus, Gemini, Cancer, Leo, Virgo, Libra, Scorpio, Sagittarius, Capricorn."
   } else {
     set horoscopeurl /yahoouk2/${horoscopesign}/?Af=-9000
     set horoscopefound ""
      if {[catch {set horoscopesock [socket -async $horoscopesite 80]} sockerr]} {
        putlog "$horoscopesite $horoscopeurl $sockerr error"
        return 0
        } else {
        puts $horoscopesock "GET $horoscopeurl HTTP/1.0"
        puts $horoscopesock "Host: $horoscopesite"
        puts $horoscopesock "User-Agent: Opera 9.6"
        puts $horoscopesock ""
        flush $horoscopesock
        while {![eof $horoscopesock]} {
          set horoscopevar " [gets $horoscopesock] "
          set horoscopeready [regexp -all -nocase -inline {<b>Your free daily horoscope(.*)} $horoscopevar]
           if {$horoscopeready != ""} { set horoscopefound 1 }
        if {$horoscopefound != "" && [regexp {<br>(.*)} $horoscopevar match horoscoperesult]} {
          set horoscoperesult [textsplit $horoscoperesult 50]
          set counter 0
          while {$counter <= [llength $horoscoperesult]} {
            if {[lindex $horoscoperesult $counter] != ""} {
              putserv "PRIVMSG $chan :$horoscopelogo $textf[lindex $horoscoperesult $counter]"
           }
           incr counter
           }
          close $horoscopesock
            return 0
        }
        }
      }
    }
  }
}
proc textsplit {text limit} {
  set text [split $text " "]
  set tokens [llength $text]
  set start 0
  set return ""
  while {[llength [lrange $text $start $tokens]] > $limit} {
    incr tokens -1
    if {[llength [lrange $text $start $tokens]] <= $limit} {
      lappend return [join [lrange $text $start $tokens]]
      set start [expr $tokens + 1]
      set tokens [llength $text]
    }
  }
  lappend return [join [lrange $text $start $tokens]]
  return $return
}
proc getsign {text} {
  if {[regexp {^aqu} $text]} { return aquarius
  } elseif {[regexp -nocase {^pis} $text]} { return Pisces
  } elseif {[regexp -nocase {^ari} $text]} { return Aries
  } elseif {[regexp -nocase {^tau} $text]} { return Taurus
  } elseif {[regexp -nocase {^gem} $text]} { return Gemini
  } elseif {[regexp -nocase {^can} $text]} { return Cancer
  } elseif {[regexp -nocase {^leo} $text]} { return Leo
  } elseif {[regexp -nocase {^vir} $text]} { return Virgo
  } elseif {[regexp -nocase {^lib} $text]} { return Libra
  } elseif {[regexp -nocase {^sco} $text]} { return Scorpio
  } elseif {[regexp -nocase {^sag} $text]} { return Sagittarius
  } elseif {[regexp -nocase {^cap} $text]} { return Capricorn
  } else { return "error" }
}
bind pub - ${horoscopecmdchar}horo horoscope
setudef flag horo
putlog "Horoscope Script by Ford_Lawnmower successfully loaded!"
Ford
 
Posts: 48
Joined: Wed Oct 28, 2009 1:01 am

Re: tcl Horoscope for Eggdrop

Postby GrimReaper » Thu Sep 02, 2010 12:50 am

Looking good Ford.. Excellent work as usual.. I'll have to load this to my eggdrop and check it out. :)
GrimReaper
 
Posts: 73
Joined: Wed Oct 28, 2009 4:34 pm
Location: In your router, Resetting your connection.


Return to Script help

Who is online

Users browsing this forum: No registered users and 11 guests

cron