DoctorD90

News2Html.tcl 2.1

Apr 25th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 1.98 KB | None | 0 0
  1. # Script: News 2 HTML
  2. # Author: Wingman <[email protected]>
  3. #         http://www.WINGDesign.de/
  4. # Update: Fixed r/w mode By DoctorD90
  5.  
  6. # Path and name of news'files.
  7. set n2h(file) "news"
  8.  
  9. # Name of news' html Title.
  10. set n2h(title) "NEWS"
  11.  
  12. # What command should be used for adding news?
  13. set n2h(cmd) "AddNews"
  14.  
  15. # How date should be used for adding news? (ex. Mon 01 99 at 09:00)
  16. set n2h(date) "%d %b %Y at %H:%M"
  17.  
  18. # How news line should be? Use %date to insert date layout setted in previous setting; Use %user to write name; Use %news to write news' text that you add (ex. Wingman (Mon 01 99 at 01:01): this script roxx)
  19. set n2h(news) "%user (%date): %news"
  20.  
  21. # What flags are authorized for using News 2 HTML? [global_flag|chan_flag]
  22. set n2h(cmd_flags) "o|o"
  23.  
  24. set n2h(ver) "2.1"
  25.  
  26. bind pub $n2h(cmd_flags) $n2h(cmd) pub:n2h
  27.  
  28. proc n2h:addnews {hand news} {
  29.   global n2h
  30.   if {[file exists "${n2h(file)}.txt"]} {
  31.     set fs [open "${n2h(file)}.txt"]
  32.     set lines [split [read -nonewline $fs] "\n"]
  33.     close $fs
  34.   }
  35.   set text [string map [list %user $hand %date [strftime $n2h(date)] %news $news] $n2h(news)]
  36.   lappend lines $text
  37.   set fs [open "${n2h(file)}.txt" w]
  38.   puts $fs [join $lines "\n"]
  39.   close $fs
  40.   set fs [open "${n2h(file)}.html" w]
  41.   puts $fs "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"><HTML>"
  42.   puts $fs "  <HEAD>"
  43.   puts $fs "    <META CONTENT=\"text/html; charset=ISO-8859-1\" http-equiv=\"content-type\">"
  44.   puts $fs "      <TITLE>$n2h(title)</TITLE>"
  45.   puts $fs "  </HEAD>"
  46.   puts $fs "  <BODY>"
  47.   puts $fs [join $lines "<br>\n"]
  48.   puts $fs "  </BODY>"
  49.   puts $fs "</HTML>"
  50.   close $fs
  51. }
  52.      
  53. proc pub:n2h { nick uhost hand chan text } {
  54.   global n2h
  55.   if {![llength [split $text]]} {
  56.     putserv "PRIVMSG $nick :Usage: $n2h(cmd) <news>"
  57.     return
  58.   }
  59.   n2h:addnews $hand $text
  60.   putserv "PRIVMSG $nick :Updated news: \"$text\"."
  61. }
  62.  
  63. putlog "News2Html $n2h(ver) by Wingman loaded."
Advertisement