Guest User

...

a guest
Sep 21st, 2020
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 13.70 KB | None | 0 0
  1. ####################################################
  2. #                                                  #
  3. # news for bots v1.00                              #
  4. #  cycomate <phil@cycdolphin.net>                  #
  5. #  get latest version at                           #
  6. #      http://www.cycdolphin.net/news.tcl          #
  7. #                                                  #
  8. ####################################################
  9.  
  10. ####################################################
  11. # SYNTAX:                                          #
  12. #                                                  #
  13. # !news [notice|pm|chan|help] [<n>]                #
  14. #                                                  #
  15. # where notice == private notice                   #
  16. #       pm == private message                      #
  17. #       chan == message to channel                 #
  18. #       n == last n lines are being sent           #
  19. # !flushnews                                       #
  20. #       deletes all news at once                   #
  21. # !delnews <n> [<x>] [<y>] [<z>] ...               #
  22. #       deletes news line number n [x] [y] [z] ... #
  23. # !addnews <news>                                  #
  24. #       adds news                                  #
  25. # !countnews                                       #
  26. #       counts num. of news                        #
  27. ####################################################
  28. # ie                                               #
  29. #                                                  #
  30. # !news            (show all news as $npc to $nps) #
  31. # !news 3     (show latest 3 news as $npc to $nps) #
  32. # !news notice 3    (notice $nick the last 3 news) #
  33. # !news chan             (send all news to $chan ) #
  34. # !news chan 3       (send latest 3 news to $chan) #
  35. # !news help         (displays help file for news) #
  36. # ... and so on                                    #
  37. ####################################################
  38.  
  39. ####################################################
  40. # set how news and confirmations are being reported
  41. #
  42.  
  43. set npc "NOTICE"
  44. #set npc "PRIVMSG"
  45.  
  46. #set nps "chan"
  47. set nps "nick"
  48.  
  49. ####################################################
  50. # default num. of lines that are sent when no
  51. # argument given
  52. set defnews 15
  53.  
  54. ####################################################
  55. # set machine type (linux|solaris)
  56. set machine "linux"
  57. set machtype "linux"
  58.  
  59. ####################################################
  60. # output news to html file?
  61. set newshtml "no"
  62. #set newshtml "yes"
  63. #set htmlpath "/home/llamer/.public_html"
  64.  
  65. ####################################################
  66. # sort news (latest first) (html only) ?
  67. # [ tac MUST be installed ]
  68. set sort "no"
  69. #set sort "yes"
  70.  
  71. ####################################################
  72. # shall the bot notice new users for news they
  73. # haven't read? you _must_ create a directory
  74. # specified below
  75. #set notice_on_join "no"
  76. set notice_on_join "yes"
  77. set news_cookie_path "/home/o_be_one/feez/news"
  78.  
  79. ####################################################
  80. ####################################################
  81. ####################################################
  82.  
  83. bind pub - !news show_news
  84. bind pub o|o !flushnews flush_news
  85. bind pub v|v !delnews del_news
  86. bind pub v|v !addnews add_news
  87. bind pub o|o !update_html update_news
  88. bind pub o|o !countnews cnt_news
  89. bind join * * checknewscript
  90.  
  91. set news_version "1.00"
  92.  
  93. proc update_news { nick uhost hand chan text } {
  94.  upd_html $chan
  95. }
  96.  
  97. proc news_help { nick } {
  98.  global npc nps news_version;
  99.  putserv "$npc $nick :\0039,0  ______________________________  "
  100.  putserv "$npc $nick :\0039,0{ \00311,0cyc's news script version $news_version \0039,0}"
  101.  putserv "$npc $nick :\0039,0                                  "
  102.  putserv "$npc $nick :\0039 _______"
  103.  putserv "$npc $nick :\00311,0 Syntax:"
  104.  putserv "$npc $nick :  \002!news\002 \[notice|pm|chan\] \[<n>\]"
  105.  putserv "$npc $nick :  where notice == private notice"
  106.  putserv "$npc $nick :      pm == private message"
  107.  putserv "$npc $nick :      chan == message to channel"
  108.  putserv "$npc $nick :      n == last n lines are being sent"
  109.  putserv "$npc $nick :  \002!flushnews"
  110.  putserv "$npc $nick :      deletes all news at once"
  111.  putserv "$npc $nick :  \002!delnews\002 <n> \[<x>\] \[<y>\] \[<z>\] ..."
  112.  putserv "$npc $nick :      deletes news line number n \[x\] \[y\] \[z\] ..."
  113.  putserv "$npc $nick :  \002!addnews\002 <news>"
  114.  putserv "$npc $nick :      adds news"
  115.  putserv "$npc $nick :  \002!countnews\002"
  116.  putserv "$npc $nick :      counts news"
  117.  putserv "$npc $nick :\0039 _________"
  118.  putserv "$npc $nick :\00311,0 examples:"
  119.  putserv "$npc $nick :  !news            (show all news as $npc to $nps)"
  120.  putserv "$npc $nick :  !news 3          (show latest 3 news as $npc to $nps)"
  121.  putserv "$npc $nick :  !news notice 3   (notice you the last 3 news)"
  122.  putserv "$npc $nick :  !news chan       (send all news to channel)"
  123.  putserv "$npc $nick :  !news chan 3     (send latest 3 news to channel)"
  124.  putserv "$npc $nick : ... and so on"
  125. }
  126.  
  127. proc getnhand { nick chan } {
  128.  if { [validuser $nick] } {
  129.   return $nick
  130.  } else {
  131.    if { [validuser [nick2hand $nick $chan]] } {
  132.      return [nick2hand $nick $chan]
  133.    } else { return $nick }
  134.  }      
  135. }
  136.  
  137. proc checknewscript { nick host handle chan } {
  138.  global news_cookie_path notice_on_join
  139.  set chkuser [getnhand $nick $chan]
  140.  if {$notice_on_join == "no" } { return 1 }
  141.  set thereis [file exists "$news_cookie_path/$chkuser"]
  142.  if {$thereis == 0} {
  143.   set usercookie [open "$news_cookie_path/$chkuser" "w+"]
  144.   puts $usercookie "000000000000"
  145.   close $usercookie
  146.  }
  147.  set usercookie [open "$news_cookie_path/$chkuser" "r+"]
  148.  set cookie [gets $usercookie]
  149.  close $usercookie
  150.  set thereis [file exists "./news_$chan.txt"]
  151.  if {$thereis == 0} { return 1 }
  152.  set newsfile [open "./news_$chan.txt" "r+"]
  153.  set numonews 0
  154.  while {[eof $newsfile] == 0} {
  155.   set line [gets $newsfile]
  156.   set delimn [string last "(+++" $line]
  157.   set delimt [string last "(+-+" $line]
  158.   set stlen [string length $line]
  159.   set adtim [string range $line [expr $delimt + 4] [expr $stlen - 2]]
  160.   if { $line != "" } {
  161.    set timestamp "[string range $adtim 12 15][string range $adtim 9 10][string range $adtim 6 7][string range $adtim 0 1][string range $adtim 3 4]"
  162.    if {$timestamp > $cookie} {
  163.     incr numonews
  164.    }
  165.   }
  166.  }
  167.  close $newsfile
  168.  if {$numonews > 0} { putserv "NOTICE $nick :there has/have been added $numonews news for $chan since your last visit. use \"!news $numonews\" to read it/them" }
  169.  eval "exec rm -f $news_cookie_path/$chkuser"
  170.  set newstamp [strftime "%Y%m%d%H%M"]
  171.  set usercookie [open "$news_cookie_path/$chkuser" "w+"]
  172.  puts $usercookie "$newstamp"
  173.  close $usercookie
  174. }
  175.  
  176. proc upd_html { chan } {
  177.  global newshtml htmlpath sort
  178.  if {$newshtml == "no"} { return 1 }
  179.  eval "exec rm -f $htmlpath/news_$chan.html ./temp_$chan.txt"
  180.  
  181.  set thereis [file exists "./news_$chan.txt"]
  182.  if ($thereis!=0) {
  183.   if { $sort == "yes" } {
  184.    set newsfile [open "| tac ./news_$chan.txt" "r+"]
  185.   } else {
  186.    set newsfile [open "./news_$chan.txt" "r+"]
  187.   }
  188.  }
  189.  set chnorau [string range $chan 1 [string length $chan]]
  190.  set htmlfile [open "$htmlpath/news_$chnorau.html" "w+"]
  191.  puts $htmlfile "<HTML><HEAD><TITLE>$chan news</TITLE></HEAD>"
  192.  puts $htmlfile "<BODY text=\"#33CCFF\" bgcolor=\"#000066\" link=\"#66FFFF\" vlink=\"#66FFFF\" alink=\"#CCFFFF\""
  193.  puts $htmlfile "<blockquote>&nbsp;"
  194.  puts $htmlfile "<br><b><font size=+2>$chan news</font></b></blockquote>"
  195.  puts $htmlfile "<hr WIDTH=\"100%\"><ul>"
  196.  if {$thereis != 0} {
  197.   while {[eof $newsfile] == 0} {
  198.    set line [gets $newsfile]
  199.    set delimn [string last "(+++" $line]
  200.    set delimt [string last "(+-+" $line]
  201.    set msg [string range $line 2 [expr $delimn - 2]]
  202.    set stlen [string length $line]
  203.    set setter [string range $line [expr $delimn + 4] [expr $delimt - 3]]
  204.    set adtim [string range $line [expr $delimt + 4] [expr $stlen - 2]]
  205.    if { $msg != "" } {
  206.     puts $htmlfile "<ul><li><b>$adtim</b>:&nbsp;&nbsp; $msg &nbsp;&nbsp;&nbsp;<i>(set by <font color=\"#FF0000\">$setter</font>)</i></li></ul>"
  207.    }
  208.   }
  209.   close $newsfile
  210.  } else { puts $htmlfile "<i> no news at the moment ... </i>" }
  211.  puts $htmlfile "</ul><hr WIDTH=\"100%\"><br><br><a href=\"http://www.cycdolphin.net\">(c) cycomate</a></BODY></HTML>"
  212.  close $htmlfile
  213.  eval "exec rm -f ./temp_$chan.txt"
  214.  return 1
  215. }
  216.  
  217. proc flush_news { nick uhost hand chan text } {
  218.   global npc
  219.   global nps
  220.   if {$nps == "nick"} {
  221.    set np "$npc $nick"
  222.   } else {
  223.    set np "$npc $chan"
  224.   }
  225.   putserv "$np :cleaned up news for $chan"
  226.   eval "exec rm -f ./news_$chan.txt"
  227.   upd_html $chan
  228.   return 1
  229. }
  230.  
  231. proc del_news { nick uhost hand chan text } {
  232.   global npc
  233.   global nps
  234.   if {$nps == "nick"} {
  235.    set np "$npc $nick"
  236.   } else {
  237.    set np "$npc $chan"
  238.   }
  239.   putserv "$np :\0034deleting line(s) <\00312$text\0034>"
  240.   set thereis [file exists "./temp_$chan.txt"]
  241.   if ($thereis!=0) {
  242.     eval "exec rm -f ./temp_$chan.txt"
  243.   }
  244.   set tempfile [open "./temp_$chan.txt" "w+"]
  245.   set newsfile [open "./news_$chan.txt" "r+"]
  246.   if {[eof $newsfile]} {
  247.     putserv "$np :No news."
  248.     close $newsfile
  249.     close $tempfile
  250.   } else {
  251.     set ln 1
  252.     while {[eof $newsfile] == 0} {
  253.       set line [gets $newsfile]
  254.       set msg $line
  255.       set dele 0
  256.       foreach prm $text {
  257.        if {$ln == $prm} {
  258.         set dele 1
  259.        }
  260.       }
  261.       if {$dele == 0} {
  262.         if {$msg != ""} {
  263.           puts $tempfile "$msg"
  264.         }
  265.       }
  266.       set dele 0
  267.       set ln [expr $ln +1]
  268.     }
  269.     close $tempfile
  270.     close $newsfile
  271.     eval "exec mv -f ./temp_$chan.txt ./news_$chan.txt"
  272.   }
  273.   upd_html $chan
  274.   return 1
  275. }
  276.  
  277. proc add_news { nick uhost hand chan text } {
  278.   global npc nps news_cookie_path
  279.   set chkuser [getnhand $nick $chan]
  280.   if {$nps == "nick"} {
  281.    set np "$npc $nick"
  282.   } else {
  283.    set np "$npc $chan"
  284.   }
  285.   set msg $text
  286.   set thereis [file exists "./news_$chan.txt"]
  287.   set cmp [expr $thereis == 1]
  288.   if ($cmp) {
  289.     set newsfile [open "./news_$chan.txt" "a"]
  290.   } else {
  291.     set newsfile [open "./news_$chan.txt" "w+"]
  292.   }
  293.   puts $newsfile "+ $msg (+++$chkuser) (+-+[strftime "%H:%M %d.%m.%Y"])"
  294.   putserv "$npc $nick :\00312- news have been stored -"
  295.   close $newsfile
  296.   upd_html $chan
  297.   eval "exec rm -f $news_cookie_path/$chkuser"
  298.   set newstamp [strftime "%Y%m%d%H%M"]
  299.   set usercookie [open "$news_cookie_path/$chkuser" "w+"]
  300.   puts $usercookie "$newstamp"
  301.   close $usercookie
  302.   return 1
  303. }
  304.  
  305. proc cnt_news { nick uhost hand chan text } {
  306.   set thereis [file exists "./news_$chan.txt"]
  307.   set cmp [expr $thereis == 1]
  308.   set cnt 0
  309.   if ($cmp) {
  310.    set newsfile [open "./news_$chan.txt" "r+"]
  311.    while {[eof $newsfile] == 0} {
  312.      set line [gets $newsfile]
  313.      if { $line != "" } {
  314.       incr cnt
  315.      }
  316.    }
  317.    close $newsfile
  318.    putserv "NOTICE $nick :\00312- I have $cnt news stored -"
  319.   } else {
  320.    putserv "NOTICE $nick :\00312- no news available -"
  321.   }
  322. }
  323.  
  324. proc show_news { nick uhost hand chan text } {
  325.   global npc nps defnews machtype news_cookie_path
  326.   if {$nps == "nick"} {
  327.    set np "$npc $nick"
  328.   } else {
  329.    set np "$npc $chan"
  330.   }
  331.   set chkuser [getnhand $nick $chan]
  332.   set npcl $defnews
  333.   if {[llength $text] == 1} {
  334.    set npct [string tolower [lindex $text 0]]
  335.    set npcm "obsolete"
  336.    if { [string length $npct ] < 2 } {
  337.     set nptt $npct
  338.    } else {
  339.     set nptt [string index $npct 1]
  340.    }
  341.    if {[string first $nptt "0 1 2 3 4 5 6 7 8 9"] > -1} {
  342.      set npcl $npct
  343.    } else {
  344.      set npcm $npct
  345.    }
  346.    switch $npcm {
  347.      "notice" { set np "NOTICE $nick" }
  348.      "pm"     { set np "PRIVMSG $nick" }
  349.      #"chan"   { set np "PRIVMSG $chan" }
  350.      "help"   { news_help $nick
  351.                 return 1
  352.               }
  353.    }
  354.   }
  355.  
  356.   if {[llength $text] == 2} {
  357.    set npcm [string tolower [lindex $text 0]]
  358.    switch $npcm {
  359.      "notice" { set np "NOTICE $nick" }
  360.      "pm"     { set np "PRIVMSG $nick" }
  361.      "chan"   { set np "PRIVMSG $chan" }
  362.      "help"   { news_help $nick
  363.                 return 1
  364.               }
  365.    }
  366.    set npct [string tolower [lindex $text 1]]
  367.    if { [string length $npct ] < 2 } {
  368.     set nptt $npct
  369.    } else {
  370.     set nptt [string index $npct 1]
  371.    }
  372.    if {[string first $npct "0 1 2 3 4 5 6 7 8 9"] > -1} {
  373.     set npcl $npct
  374.    }
  375.   }
  376.   if {[llength $text] > 2 } {
  377.    putserv "NOTICE $nick :whuz up?"
  378.    return 1
  379.   }
  380.  
  381.   eval "exec rm -f $news_cookie_path/$chkuser"
  382.   set newstamp [strftime "%Y%m%d%H%M"]
  383.   set usercookie [open "$news_cookie_path/$chkuser" "w+"]
  384.   puts $usercookie "$newstamp"
  385.   close $usercookie
  386.  
  387.   set thereis [file exists "./news_$chan.txt"]
  388.   if ($thereis==0) {
  389.     putserv "$np :No news for $chan at the moment."
  390.     return 1
  391.   }
  392.   switch $machtype {
  393.     "linux"   { set newsfile [open "| tail -n $npcl news_$chan.txt" "r+"] }
  394.     "solaris" { set newsfile [open "| tail -$npcl news_$chan.txt" "r+"] }
  395.   }
  396.   if {[eof $newsfile]} {
  397.      putserv "$np :No news available."
  398.     close $newsfile
  399.   } else {
  400.     set yes 0
  401.     while {[eof $newsfile] == 0} {
  402.       set line [gets $newsfile]
  403.       set delimn [string last "(+++" $line]
  404.       set delimt [string last "(+-+" $line]
  405.       set msg [string range $line 2 [expr $delimn - 2]]
  406.       set stlen [string length $line]
  407.       set adder [string range $line [expr $delimn + 4] [expr $delimt - 3]]
  408.       set adtim [string range $line [expr $delimt + 4] [expr $stlen - 2]]
  409.       if { $msg != "" } {
  410.        putserv "$np :(\0039$adtim\017): \00312$msg \017(\0034$adder\017)"
  411.       }
  412.       set yes 1
  413.     }
  414.     if { $yes==0 } {
  415.       putserv "$np :No news."
  416.     }
  417.     close $newsfile
  418.   }
  419.   return 1
  420. }
  421.  
  422. ##############################
  423. # Show load statement        #
  424. ##############################
  425. putlog "News $news_version by cycomate loaded..."
  426.  
Add Comment
Please, Sign In to add comment