maketiny.tcl 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # cheap tinyurl script to convert ling urls into short urls
  2. # using http://tinyurl.com´s service
  3. proc tinyurl_convert {nick host hand chan argv} {
  4. # set variables
  5. set url [lindex $argv 0]
  6. set command "|wget --quiet --output-document=- http://tinyurl.com/create.php?url=$url"
  7. # check if there are enough arguments
  8. if { [llength $argv] == 0 } {
  9. puthelp "PRIVMSG $nick :Usage: !tinyurl <url> || Example: !tinyurl http://www.google.com"
  10. } else {
  11. # open command to create tinyurl and retrieve the html document returned by tinyurl
  12. if ![catch {open $command r} input] {
  13. while {[gets $input line] >= 0} {
  14. # regexp to extract the right part of the html file and the get the tiny url
  15. # output tiny url
  16. if [regexp {<input type=hidden name=tinyurl value=\"(.*)\">} $line match tinyurl] {
  17. puthelp "PRIVMSG $chan :$tinyurl"
  18. }
  19. }
  20. close $input
  21. }
  22. }
  23. }
  24. proc tinyurl_tinylast {nick host hand chan argv} {
  25. set urlhistory "url_history_$chan"
  26. if ![catch {open $urlhistory r} input] {
  27. while {[gets $input line] >= 0} {
  28. set url $line
  29. }
  30. close $input
  31. tinyurl_convert $nick $host $hand $chan $url
  32. }
  33. }
  34. proc tinyurl_urlhistory {nick host hand chan argv} {
  35. set urlhistory "url_history_$chan"
  36. if {[regexp {(http://\S*)} $argv match url] != 0} {
  37. if ![catch {open $urlhistory w} output] {
  38. puts $output $url
  39. close $output
  40. }
  41. }
  42. }
  43. # bind channel command
  44. bind pub - !tinyurl tinyurl_convert
  45. bind pub - !tinylast tinyurl_tinylast
  46. bind pubm - * tinyurl_urlhistory