Advertisement
Ford

RottenTomatoes eggdrop script

Jun 2nd, 2012
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 11.65 KB | None | 0 0
  1. ##############################################################################################
  2. ##  ##     rottentomato.tcl for eggdrop by Ford_Lawnmower irc.geekshed.net #Script-Help ##  ##
  3. ##############################################################################################
  4. ## To use this script you must set channel flag +rotten (ie .chanset #chan +rotten)         ##
  5. ##############################################################################################
  6. ##############################################################################################
  7. ##  ##                             Start Setup.                                         ##  ##
  8. ##############################################################################################
  9. ## Change rotten_cmdchar to the character you want to use.                                  ##
  10. set rotten_cmdchar "!"
  11. ## Change rotten_lang to the 2 digit language code you want to use                          ##
  12. set rotten_lang "en"
  13. proc rotten {nick host hand chan rottensite rottenurl rottensearch} {
  14.   if {[lsearch -exact [channel info $chan] +rotten] != -1} {
  15. ## Change the characters between the "" below to change the logo shown with each result.    ##
  16.     set rottenlogo "\002\00308,03RT\017"
  17. ## Change the format codes between the "" below to change the color/state of the text.      ##
  18.     set rottentext "\00304"
  19. ## Change the format codes between the "" below to change the color/state of the tags.      ##
  20.     set rottentags "\017\002"
  21. ## Change the format codes between the "" below to change the color/state of the links.     ##
  22.     set rottenlinks "\037"
  23. ## You may adjust how the results are printed by changing line1, line2 and line3            ##
  24. ## Valid items are as follows: cast genre director link imdblink title audiencescore        ##
  25. ## audiencerating criticrating criticconsensus criticscore synopsis date mpaarating         ##
  26.     set line1 "title date genre mpaarating director cast synopsis"
  27.     set line2 "criticrating criticscore criticconsensus audiencescore audiencerating link imdblink"
  28.     set line3 ""
  29. ##############################################################################################
  30. ##  ##                           End Setup.                                              ## ##
  31. ##############################################################################################
  32.     if {[catch {set rottenSock [socket -async $rottensite 80]} sockerr]} {
  33.       putserv "PRIVMSG $chan :$rottensite $rottenurl $sockerr error"
  34.       return 0
  35.       } else {
  36.       puts $rottenSock "GET $rottenurl HTTP/1.0"
  37.       puts $rottenSock "Host: $rottensite"
  38.       puts $rottenSock "User-Agent: Opera 9.6"
  39.       puts $rottenSock ""
  40.       flush $rottenSock
  41.       set rottenimdblink ""
  42.       set rottentitle ""
  43.       set rottencast ""
  44.       set rottensynopsis ""
  45.       set rottengenre ""
  46.       set rottendirector ""
  47.       set rottencriticrating ""
  48.       set rottenlink ""
  49.       set rottentitle ""
  50.       set rottenmpaarating ""
  51.       set rottencriticscore ""
  52.       set rottendate ""
  53.       set rottenaudiencerating ""
  54.       set rottenaudiencescore ""
  55.       set rottencriticconsensus ""
  56.       while {![eof $rottenSock]} {
  57.         set rottenvar " [gets $rottenSock] "
  58.         if {[regexp {may refer to:} $rottenvar] || [regexp {HTTP\/1\.0 403} $rottenvar]} {
  59.            putserv "PRIVMSG $chan :\002Nothing found on rotten! Please refine your search and check your spelling."
  60.            close $rottenSock
  61.        return 0
  62.         }
  63.         if {[string match "*\"total\":0*" $rottenvar]} {
  64.           putlog "Nothing found"
  65.         }
  66.         if {[string match "*\"error\":\"Could not find a movie with the specified id\"*" $rottenvar]} {
  67.           set rottenurl "/api/public/v1.0/movies.json?apikey=rtchpv52u3vmrs497ux275an&q=${rottensearch}&page_limit=1&page=1"
  68.           close $rottenSock
  69.           rotten $nick $host $hand $chan $rottensite $rottenurl $rottensearch
  70.           return 0
  71.         }
  72.         if {[regexp {"synopsis":"(.*?)"\x2c"} $rottenvar match rottensynopsis]} {
  73.          if {$rottensynopsis != ""} {
  74.            set rottensynopsis "${rottentags}Synopsis:\017 ${rottentext}${rottensynopsis}\017"
  75.          }
  76.        }
  77.        if {[regexp {"critics_rating":"(.*?)"\x2c"} $rottenvar match rottencriticrating]} {
  78.           set rottencriticrating "${rottentags}Critics Rating:\017 ${rottentext}${rottencriticrating}\017"
  79.         }
  80.         if {[regexp {"mpaa_rating":"(.*?)"\x2c"} $rottenvar match rottenmpaarating]} {
  81.          set rottenmpaarating "${rottentags}MPAA Rating:\017 ${rottentext}${rottenmpaarating}\017"
  82.        }
  83.        if {[regexp {"genres":\x5b(.*?)\x5d\x2c"} $rottenvar match rottengenre]} {
  84.           set rottengenre "${rottentags}Genre:\017 ${rottentext}${rottengenre}\017"
  85.         }
  86.         if {[regexp {"critics_consensus":"(.*?)"\x2c"} $rottenvar match rottencriticconsensus]} {
  87.          set rottencriticconsensus "${rottentags}Critics Consensus:\017 ${rottentext}${rottencriticconsensus}\017"
  88.        }
  89.        if {[regexp {"release_dates":\x7b(.*?)\x7d\x2c} $rottenvar match rottendate]} {
  90.          set rottendate "${rottentags}Release Date:\017 ${rottentext}${rottendate}\017"
  91.        }
  92.        if {[regexp {\{"id":(\d*)\x2c} $rottenvar match rottenlink]} {
  93.          set rottenlink "${rottentags}Link:\017 ${rottentext}${rottenlinks}http://rottentomatoes.com/m/${rottenlink}/\017"
  94.        }
  95.        if {[regexp {\{"id":"(\d*)"\x2c} $rottenvar match rottenlink]} {
  96.          set rottenlink "${rottentags}Link:\017 ${rottentext}${rottenlinks}http://rottentomatoes.com/m/${rottenlink}/\017"
  97.        }
  98.        if {[regexp {"title":(.*?)\x2c} $rottenvar match rottentitle]} {
  99.          set rottentitle "${rottentags}Title:\017 ${rottentext}${rottentitle}\017"
  100.        }
  101.        if {[regexp {"year":(.*?)\x2c} $rottenvar match rottenyear]} {
  102.          set rottenyear "${rottentags}Year:\017 ${rottentext}${rottenyear}\017"
  103.        }
  104.        if {[regexp {"runtime":(.*?)\x2c} $rottenvar match rottenruntime]} {
  105.          set rottenruntime "${rottentags}Runtime:\017 ${rottentext}${rottenruntime}\017"
  106.        }
  107.        if {[regexp {"critics_score":(.*?)\x2c} $rottenvar match rottencriticscore]} {
  108.          set rottencriticscore "${rottentags}Critic Score:\017 ${rottentext}${rottencriticscore}\017"
  109.        }
  110.        if {[regexp {"audience_rating":(.*?)\x2c} $rottenvar match rottenaudiencerating]} {
  111.          set rottenaudiencerating "${rottentags}Audience Rating:\017 ${rottentext}${rottenaudiencerating}\017"
  112.        }
  113.        if {[regexp {"audience_score":(.*?)\x7d\x2c} $rottenvar match rottenaudiencescore]} {
  114.          set rottenaudiencescore "${rottentags}Audience Score:\017 ${rottentext}${rottenaudiencescore}\017"
  115.        }
  116.        if {[regexp {"name":"(.*?)"} $rottenvar match rottencast]} {
  117.          set rottencast [regexp -all -inline {"name":(".*?")} $rottenvar]
  118.          set rottencast "Cast: $rottencast"
  119.          set counter 0
  120.          set rottentemp ""
  121.          foreach i $rottencast {
  122.            if {$counter && ![expr $counter % 2]} {
  123.              set rottentemp "${rottentemp}[rotteniif $rottentemp "\, "]${i}"
  124.            }
  125.            incr counter
  126.          }
  127.          set rottencast "${rottentags}Cast:\017 ${rottentext}${rottentemp}\017"
  128.        }
  129.        if {[regexp {"abridged_directors":\x5b\x7b(.*?)\x7d\x5d} $rottenvar match rottendirector]} {
  130.          set rottendirector "${rottentags}Director:\017 ${rottentext}[string map {\"name\": " " \} "" \{ ""} $rottendirector]\017"
  131.         }
  132.         if {[regexp {"imdb":"(.*?)"} $rottenvar match rottenimdblink]} {
  133.           set rottenimdblink "${rottentags}IMDb:\017 ${rottentext}${rottenlinks}http://www.imdb.com/title/tt${rottenimdblink}/\017"
  134.         }
  135.         if {[string match "*\"id\":*" $rottenvar]} {
  136.           if {$line1 != ""} {
  137.             rottenmsg $chan $rottenlogo $rottentext [subst [regsub -all -nocase {(\S+)} $line1 {$rotten\1}]]
  138.           }
  139.           if {$line2 != ""} {
  140.             rottenmsg $chan $rottenlogo $rottentext [subst [regsub -all -nocase {(\S+)} $line2 {$rotten\1}]]
  141.           }
  142.           if {$line3 != ""} {
  143.             rottenmsg $chan $rottenlogo $rottentext [subst [regsub -all -nocase {(\S+)} $line3 {$rotten\1}]]
  144.           }
  145.         }
  146.       }
  147.     }
  148.       close $rottenSock
  149.       return 0
  150.   }
  151. }
  152. proc rottenround {num} {
  153.   return [expr {round($num)}]
  154. }
  155. proc rottenmsg {chan logo textf text} {
  156.   set text [rottentextsplit $text 50]
  157.   set counter 0
  158.   while {$counter <= [llength $text]} {
  159.     if {[lindex $text $counter] != ""} {
  160.       putserv "PRIVMSG $chan :${logo} ${textf}[string map {\\\" \"} [lindex $text $counter]]"
  161.     }
  162.     incr counter
  163.   }
  164. }
  165. proc googlerottensearch {nick host hand chan search} {
  166.   global rotten_lang
  167.   if {[lsearch -exact [channel info $chan] +rotten] != -1} {
  168.     set googlerottensite "www.google.com"
  169.     set googlerottensearch [string map {{ } \%20} "${search}"]
  170.     set googlerottenurl "/search?q=${googlerottensearch}+site:imdb.com&rls=${rotten_lang}&hl=${rotten_lang}"
  171.     if {[catch {set googlerottenSock [socket -async $googlerottensite 80]} sockerr]} {
  172.       putserv "PRIVMSG $chan :$googlerottensite $googlerottenurl $sockerr error"
  173.       return 0
  174.     } else {
  175.       puts $googlerottenSock "GET $googlerottenurl HTTP/1.0"
  176.       puts $googlerottenSock "Host: $googlerottensite"
  177.       puts $googlerottenSock "User-Agent: Opera 9.6"
  178.       puts $googlerottenSock ""
  179.       flush $googlerottenSock
  180.       while {![eof $googlerottenSock]} {
  181.         set googlerottenvar " [gets $googlerottenSock] "
  182.     if {[regexp {<cite>.*?imdb\.com\/title\/tt(.*?)\/} $googlerottenvar match googlerottenurl]} {
  183.           set rottensite "api.rottentomatoes.com"
  184.           set rottenurl "/api/public/v1.0/movie_alias.json?apikey=rtchpv52u3vmrs497ux275an&type=imdb&id=${googlerottenurl}"
  185.           rotten $nick $host $hand $chan $rottensite $rottenurl $googlerottensearch
  186.           close $googlerottenSock
  187.       return 0
  188.     }
  189.       }
  190.       putserv "PRIVMSG $chan :\002Nothing found on rotten! Please refine your search and check your spelling."
  191.       close $googlerottenSock
  192.       return 0
  193.     }
  194.   }
  195. }
  196. proc rotteniif {test do} {
  197.    if {$test != 0 && $test != ""} {
  198.      return $do
  199.    } else {
  200.      return ""
  201.    }
  202. }
  203. proc rottentextsplit {text limit} {
  204.   set text [split $text " "]
  205.   set tokens [llength $text]
  206.   set start 0
  207.   set return ""
  208.   while {[llength [lrange $text $start $tokens]] > $limit} {
  209.     incr tokens -1
  210.     if {[llength [lrange $text $start $tokens]] <= $limit} {
  211.       lappend return [join [lrange $text $start $tokens]]
  212.       set start [expr $tokens + 1]
  213.       set tokens [llength $text]
  214.     }
  215.   }
  216.   lappend return [join [lrange $text $start $tokens]]
  217.   return $return
  218. }
  219. proc rottenhex {decimal} { return [format %x $decimal] }
  220. proc rottendecimal {hex} { return [expr 0x$hex] }
  221. proc rottendehex {string} {
  222.   regsub -all {^\{|\}$} $string "" string
  223.   set string [subst [regsub -nocase -all {\&#x([0-9a-f]{1,3});} $string {[format %c [rottendecimal \1]]}]]
  224.   set string [subst [regsub -nocase -all {\&#([0-9]{1,3});} $string {[format %c \1]}]]
  225.   set string [string map {&quot; \" &middot; · &amp; & <b> \002 </b> \002} $string]
  226.  return $string
  227. }
  228. proc rottenstrip {string} {
  229.  regsub -all {<[^<>]+>} $string "" string
  230.  regsub -all {\[\d+\]} $string "" string
  231.  return $string
  232. }
  233. bind pub - [string trimleft $rotten_cmdchar]rotten googlerottensearch
  234. bind pub - [string trimleft $rotten_cmdchar]rt googlerottensearch
  235. bind pub - [string trimleft $rotten_cmdchar]tomato googlerottensearch
  236. setudef flag rotten
  237. putlog "\002*Loaded* \002\00308,03RottenTomatoes\002\003 \002by Ford_Lawnmower irc.GeekShed.net #Script-Help"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement