Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####################################################
- # #
- # news for bots v1.00 #
- # cycomate <phil@cycdolphin.net> #
- # get latest version at #
- # http://www.cycdolphin.net/news.tcl #
- # #
- ####################################################
- ####################################################
- # SYNTAX: #
- # #
- # !news [notice|pm|chan|help] [<n>] #
- # #
- # where notice == private notice #
- # pm == private message #
- # chan == message to channel #
- # n == last n lines are being sent #
- # !flushnews #
- # deletes all news at once #
- # !delnews <n> [<x>] [<y>] [<z>] ... #
- # deletes news line number n [x] [y] [z] ... #
- # !addnews <news> #
- # adds news #
- # !countnews #
- # counts num. of news #
- ####################################################
- # ie #
- # #
- # !news (show all news as $npc to $nps) #
- # !news 3 (show latest 3 news as $npc to $nps) #
- # !news notice 3 (notice $nick the last 3 news) #
- # !news chan (send all news to $chan ) #
- # !news chan 3 (send latest 3 news to $chan) #
- # !news help (displays help file for news) #
- # ... and so on #
- ####################################################
- ####################################################
- # set how news and confirmations are being reported
- #
- set npc "NOTICE"
- #set npc "PRIVMSG"
- #set nps "chan"
- set nps "nick"
- ####################################################
- # default num. of lines that are sent when no
- # argument given
- set defnews 15
- ####################################################
- # set machine type (linux|solaris)
- set machine "linux"
- set machtype "linux"
- ####################################################
- # output news to html file?
- set newshtml "no"
- #set newshtml "yes"
- #set htmlpath "/home/llamer/.public_html"
- ####################################################
- # sort news (latest first) (html only) ?
- # [ tac MUST be installed ]
- set sort "no"
- #set sort "yes"
- ####################################################
- # shall the bot notice new users for news they
- # haven't read? you _must_ create a directory
- # specified below
- #set notice_on_join "no"
- set notice_on_join "yes"
- set news_cookie_path "/home/o_be_one/feez/news"
- ####################################################
- ####################################################
- ####################################################
- bind pub - !news show_news
- bind pub o|o !flushnews flush_news
- bind pub v|v !delnews del_news
- bind pub v|v !addnews add_news
- bind pub o|o !update_html update_news
- bind pub o|o !countnews cnt_news
- bind join * * checknewscript
- set news_version "1.00"
- proc update_news { nick uhost hand chan text } {
- upd_html $chan
- }
- proc news_help { nick } {
- global npc nps news_version;
- putserv "$npc $nick :\0039,0 ______________________________ "
- putserv "$npc $nick :\0039,0{ \00311,0cyc's news script version $news_version \0039,0}"
- putserv "$npc $nick :\0039,0 "
- putserv "$npc $nick :\0039 _______"
- putserv "$npc $nick :\00311,0 Syntax:"
- putserv "$npc $nick : \002!news\002 \[notice|pm|chan\] \[<n>\]"
- putserv "$npc $nick : where notice == private notice"
- putserv "$npc $nick : pm == private message"
- putserv "$npc $nick : chan == message to channel"
- putserv "$npc $nick : n == last n lines are being sent"
- putserv "$npc $nick : \002!flushnews"
- putserv "$npc $nick : deletes all news at once"
- putserv "$npc $nick : \002!delnews\002 <n> \[<x>\] \[<y>\] \[<z>\] ..."
- putserv "$npc $nick : deletes news line number n \[x\] \[y\] \[z\] ..."
- putserv "$npc $nick : \002!addnews\002 <news>"
- putserv "$npc $nick : adds news"
- putserv "$npc $nick : \002!countnews\002"
- putserv "$npc $nick : counts news"
- putserv "$npc $nick :\0039 _________"
- putserv "$npc $nick :\00311,0 examples:"
- putserv "$npc $nick : !news (show all news as $npc to $nps)"
- putserv "$npc $nick : !news 3 (show latest 3 news as $npc to $nps)"
- putserv "$npc $nick : !news notice 3 (notice you the last 3 news)"
- putserv "$npc $nick : !news chan (send all news to channel)"
- putserv "$npc $nick : !news chan 3 (send latest 3 news to channel)"
- putserv "$npc $nick : ... and so on"
- }
- proc getnhand { nick chan } {
- if { [validuser $nick] } {
- return $nick
- } else {
- if { [validuser [nick2hand $nick $chan]] } {
- return [nick2hand $nick $chan]
- } else { return $nick }
- }
- }
- proc checknewscript { nick host handle chan } {
- global news_cookie_path notice_on_join
- set chkuser [getnhand $nick $chan]
- if {$notice_on_join == "no" } { return 1 }
- set thereis [file exists "$news_cookie_path/$chkuser"]
- if {$thereis == 0} {
- set usercookie [open "$news_cookie_path/$chkuser" "w+"]
- puts $usercookie "000000000000"
- close $usercookie
- }
- set usercookie [open "$news_cookie_path/$chkuser" "r+"]
- set cookie [gets $usercookie]
- close $usercookie
- set thereis [file exists "./news_$chan.txt"]
- if {$thereis == 0} { return 1 }
- set newsfile [open "./news_$chan.txt" "r+"]
- set numonews 0
- while {[eof $newsfile] == 0} {
- set line [gets $newsfile]
- set delimn [string last "(+++" $line]
- set delimt [string last "(+-+" $line]
- set stlen [string length $line]
- set adtim [string range $line [expr $delimt + 4] [expr $stlen - 2]]
- if { $line != "" } {
- 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]"
- if {$timestamp > $cookie} {
- incr numonews
- }
- }
- }
- close $newsfile
- 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" }
- eval "exec rm -f $news_cookie_path/$chkuser"
- set newstamp [strftime "%Y%m%d%H%M"]
- set usercookie [open "$news_cookie_path/$chkuser" "w+"]
- puts $usercookie "$newstamp"
- close $usercookie
- }
- proc upd_html { chan } {
- global newshtml htmlpath sort
- if {$newshtml == "no"} { return 1 }
- eval "exec rm -f $htmlpath/news_$chan.html ./temp_$chan.txt"
- set thereis [file exists "./news_$chan.txt"]
- if ($thereis!=0) {
- if { $sort == "yes" } {
- set newsfile [open "| tac ./news_$chan.txt" "r+"]
- } else {
- set newsfile [open "./news_$chan.txt" "r+"]
- }
- }
- set chnorau [string range $chan 1 [string length $chan]]
- set htmlfile [open "$htmlpath/news_$chnorau.html" "w+"]
- puts $htmlfile "<HTML><HEAD><TITLE>$chan news</TITLE></HEAD>"
- puts $htmlfile "<BODY text=\"#33CCFF\" bgcolor=\"#000066\" link=\"#66FFFF\" vlink=\"#66FFFF\" alink=\"#CCFFFF\""
- puts $htmlfile "<blockquote> "
- puts $htmlfile "<br><b><font size=+2>$chan news</font></b></blockquote>"
- puts $htmlfile "<hr WIDTH=\"100%\"><ul>"
- if {$thereis != 0} {
- while {[eof $newsfile] == 0} {
- set line [gets $newsfile]
- set delimn [string last "(+++" $line]
- set delimt [string last "(+-+" $line]
- set msg [string range $line 2 [expr $delimn - 2]]
- set stlen [string length $line]
- set setter [string range $line [expr $delimn + 4] [expr $delimt - 3]]
- set adtim [string range $line [expr $delimt + 4] [expr $stlen - 2]]
- if { $msg != "" } {
- puts $htmlfile "<ul><li><b>$adtim</b>: $msg <i>(set by <font color=\"#FF0000\">$setter</font>)</i></li></ul>"
- }
- }
- close $newsfile
- } else { puts $htmlfile "<i> no news at the moment ... </i>" }
- puts $htmlfile "</ul><hr WIDTH=\"100%\"><br><br><a href=\"http://www.cycdolphin.net\">(c) cycomate</a></BODY></HTML>"
- close $htmlfile
- eval "exec rm -f ./temp_$chan.txt"
- return 1
- }
- proc flush_news { nick uhost hand chan text } {
- global npc
- global nps
- if {$nps == "nick"} {
- set np "$npc $nick"
- } else {
- set np "$npc $chan"
- }
- putserv "$np :cleaned up news for $chan"
- eval "exec rm -f ./news_$chan.txt"
- upd_html $chan
- return 1
- }
- proc del_news { nick uhost hand chan text } {
- global npc
- global nps
- if {$nps == "nick"} {
- set np "$npc $nick"
- } else {
- set np "$npc $chan"
- }
- putserv "$np :\0034deleting line(s) <\00312$text\0034>"
- set thereis [file exists "./temp_$chan.txt"]
- if ($thereis!=0) {
- eval "exec rm -f ./temp_$chan.txt"
- }
- set tempfile [open "./temp_$chan.txt" "w+"]
- set newsfile [open "./news_$chan.txt" "r+"]
- if {[eof $newsfile]} {
- putserv "$np :No news."
- close $newsfile
- close $tempfile
- } else {
- set ln 1
- while {[eof $newsfile] == 0} {
- set line [gets $newsfile]
- set msg $line
- set dele 0
- foreach prm $text {
- if {$ln == $prm} {
- set dele 1
- }
- }
- if {$dele == 0} {
- if {$msg != ""} {
- puts $tempfile "$msg"
- }
- }
- set dele 0
- set ln [expr $ln +1]
- }
- close $tempfile
- close $newsfile
- eval "exec mv -f ./temp_$chan.txt ./news_$chan.txt"
- }
- upd_html $chan
- return 1
- }
- proc add_news { nick uhost hand chan text } {
- global npc nps news_cookie_path
- set chkuser [getnhand $nick $chan]
- if {$nps == "nick"} {
- set np "$npc $nick"
- } else {
- set np "$npc $chan"
- }
- set msg $text
- set thereis [file exists "./news_$chan.txt"]
- set cmp [expr $thereis == 1]
- if ($cmp) {
- set newsfile [open "./news_$chan.txt" "a"]
- } else {
- set newsfile [open "./news_$chan.txt" "w+"]
- }
- puts $newsfile "+ $msg (+++$chkuser) (+-+[strftime "%H:%M %d.%m.%Y"])"
- putserv "$npc $nick :\00312- news have been stored -"
- close $newsfile
- upd_html $chan
- eval "exec rm -f $news_cookie_path/$chkuser"
- set newstamp [strftime "%Y%m%d%H%M"]
- set usercookie [open "$news_cookie_path/$chkuser" "w+"]
- puts $usercookie "$newstamp"
- close $usercookie
- return 1
- }
- proc cnt_news { nick uhost hand chan text } {
- set thereis [file exists "./news_$chan.txt"]
- set cmp [expr $thereis == 1]
- set cnt 0
- if ($cmp) {
- set newsfile [open "./news_$chan.txt" "r+"]
- while {[eof $newsfile] == 0} {
- set line [gets $newsfile]
- if { $line != "" } {
- incr cnt
- }
- }
- close $newsfile
- putserv "NOTICE $nick :\00312- I have $cnt news stored -"
- } else {
- putserv "NOTICE $nick :\00312- no news available -"
- }
- }
- proc show_news { nick uhost hand chan text } {
- global npc nps defnews machtype news_cookie_path
- if {$nps == "nick"} {
- set np "$npc $nick"
- } else {
- set np "$npc $chan"
- }
- set chkuser [getnhand $nick $chan]
- set npcl $defnews
- if {[llength $text] == 1} {
- set npct [string tolower [lindex $text 0]]
- set npcm "obsolete"
- if { [string length $npct ] < 2 } {
- set nptt $npct
- } else {
- set nptt [string index $npct 1]
- }
- if {[string first $nptt "0 1 2 3 4 5 6 7 8 9"] > -1} {
- set npcl $npct
- } else {
- set npcm $npct
- }
- switch $npcm {
- "notice" { set np "NOTICE $nick" }
- "pm" { set np "PRIVMSG $nick" }
- #"chan" { set np "PRIVMSG $chan" }
- "help" { news_help $nick
- return 1
- }
- }
- }
- if {[llength $text] == 2} {
- set npcm [string tolower [lindex $text 0]]
- switch $npcm {
- "notice" { set np "NOTICE $nick" }
- "pm" { set np "PRIVMSG $nick" }
- "chan" { set np "PRIVMSG $chan" }
- "help" { news_help $nick
- return 1
- }
- }
- set npct [string tolower [lindex $text 1]]
- if { [string length $npct ] < 2 } {
- set nptt $npct
- } else {
- set nptt [string index $npct 1]
- }
- if {[string first $npct "0 1 2 3 4 5 6 7 8 9"] > -1} {
- set npcl $npct
- }
- }
- if {[llength $text] > 2 } {
- putserv "NOTICE $nick :whuz up?"
- return 1
- }
- eval "exec rm -f $news_cookie_path/$chkuser"
- set newstamp [strftime "%Y%m%d%H%M"]
- set usercookie [open "$news_cookie_path/$chkuser" "w+"]
- puts $usercookie "$newstamp"
- close $usercookie
- set thereis [file exists "./news_$chan.txt"]
- if ($thereis==0) {
- putserv "$np :No news for $chan at the moment."
- return 1
- }
- switch $machtype {
- "linux" { set newsfile [open "| tail -n $npcl news_$chan.txt" "r+"] }
- "solaris" { set newsfile [open "| tail -$npcl news_$chan.txt" "r+"] }
- }
- if {[eof $newsfile]} {
- putserv "$np :No news available."
- close $newsfile
- } else {
- set yes 0
- while {[eof $newsfile] == 0} {
- set line [gets $newsfile]
- set delimn [string last "(+++" $line]
- set delimt [string last "(+-+" $line]
- set msg [string range $line 2 [expr $delimn - 2]]
- set stlen [string length $line]
- set adder [string range $line [expr $delimn + 4] [expr $delimt - 3]]
- set adtim [string range $line [expr $delimt + 4] [expr $stlen - 2]]
- if { $msg != "" } {
- putserv "$np :(\0039$adtim\017): \00312$msg \017(\0034$adder\017)"
- }
- set yes 1
- }
- if { $yes==0 } {
- putserv "$np :No news."
- }
- close $newsfile
- }
- return 1
- }
- ##############################
- # Show load statement #
- ##############################
- putlog "News $news_version by cycomate loaded..."
Add Comment
Please, Sign In to add comment