| Current Path : /home/mudbot/eggdrop/ |
| Current File : //home/mudbot/eggdrop/topicrecover2112.v5.tcl-keep |
# Updated by Rosc2112 at yahoo.com Feb.2006
# http://members.dandy.net/~fbn/topicrecover2112.tcl.txt
#
# Stores chantopics into a file, allowing search and recall, and resetting channel topic when it's blank.
#
# Originally based on: Meltdowns Topic-Recover V0.2 08-03-2004
#
# Rosc's changes:
# - Fixed various errors.
# - Added a help file.
# - Made all commands work by /msg (No sense spamming in channels.)
# - Added a timer to check if the topic is empty, and reset it to the last saved.
# - Added a topicdel function to allow deleting topics individually from the save file.
# - Modified rolltopic to work based on Epoch time/index number which allows rolling back to any saved topic.
# - Added an topicundo function, mainly for testing, but it's there for whatever may be useful.
#
# Jul 15 2006 - More revisions. Removed the silly cleanup function, as the script checks for duplicate topics
# and does not add them to the saved file. Various fixes, etc..
# Aug 29 2006 - Changed .topicsearch to show newest to oldest topics. Fixed a typo "catc" shoulda been "catch".
# Fixed help output to show correct synxtax (duh).
#
#
# Commands:
# .topic - typed in channel, show the current topic (in msg), and if user is +o, show the op commands.
# /msg $botnick topic #chan - show the current topic, and if user is +o, show the op commands.
# /msg $botnick topicsearch #chan - show the saved topics and their Index numbers.
# Op Commands:
# /msg $botnick topicroll #chan - roll back topic with the one specified by Index number.
# /msg $botnick topicdel #chan - delete topic with Index number.
# /msg $botnick topicrec #chan - recover the last saved topic.
# /msg $botnick topicredo #chan - this UNSETS topic first, then recovers last topic set.
# /msg $botnick topicundo #chan - simply unsets the topic, making it blank.
#
#################################################################
# Check the topic every ?? minutes..
set topictimer 15
# Channels to run this script in..Space-seperated list like "#chan1 #chan2 #etc"
set tchan "#minecity #MineCity"
# File, where topics wil be stored
set melttop(file) "/home/minetestfan/eggdrop/scripts/topicrecover.dat"
# Max lines to show when searching for a specific topic
set melttop(max) 40
######################################################################
bind TOPC - * proc:rectopic
bind pub - .topic proc:topichelp
bind msg - topic proc:msgtopichelp
bind msg - .topic proc:msgtopichelp
bind msg o|o topicrec proc:forcerecover
bind msg o|o topicroll proc:msgrollbacktopic
bind msg o|o topicredo proc:redotopic
bind msg o|o topicundo proc:undotopic
bind msg n|n topicdel proc:deltopic
bind msg -|- topicsearch proc:msgsearchtopic
bind msg o|o .topicrec proc:forcerecover
bind msg o|o .topicroll proc:msgrollbacktopic
bind msg o|o .topicredo proc:redotopic
bind msg o|o .topicundo proc:undotopic
bind msg n|n .topicdel proc:deltopic
bind msg -|- .topicsearch proc:msgsearchtopic
set tchan [string tolower [split $tchan]]
proc proc:msgrollbacktopic {nick uhost hand text} {
global tchan
set text [split $text]
set chan [string tolower [lindex $text 0]]
set text [lrange $text 1 end]
if {$chan == ""} {
puthelp "PRIVMSG $nick :Please specify a channel name, like, #foo"
return
}
if {$text == ""} {
puthelp "PRIVMSG $nick :Please specify a topic index number (Use \002.topicsearch #channel\002 to find one.)"
return
}
if {[lsearch -exact $tchan $chan] == -1} {
puthelp "PRIVMSG $nick :I'm not doing topics on channel \002[join $chan]\002.. Sorry :P"
return
} else {
proc:rollbacktopic $nick $uhost $hand $chan "$text"
}
}
proc proc:msgsearchtopic {nick uhost hand text} {
global tchan
set text [string tolower [split $text]]
if {$text == ""} {
if {![onchan $nick]} {
return
} else {
puthelp "PRIVMSG $nick :Please specify a channel name, like, #foo"
return
}
}
if {[lsearch -exact $tchan $text] == -1} {
if {![onchan $nick]} {
return
} else {
puthelp "PRIVMSG $nick :I'm not doing topics on channel \002[join $text]\002.. Sorry :P"
return
}
} else {
proc:searchtopic $nick $uhost $hand $text ""
}
}
proc proc:forcerecover {nick uhost hand text} {
global tchan
set text [string tolower [split $text]]
if {$text == ""} {puthelp "PRIVMSG $nick :Please specify a channel name, like, #foo";return}
if {[lsearch -exact $tchan $text] == -1} {
puthelp "PRIVMSG $nick :I'm not doing topics on channel \002[join $text]\002.. Sorry :P"
return
} else {
proc:rectopic $nick $uhost checktopic $text ""
}
}
proc proc:redotopic {nick uhost hand text} {
global tchan
set text [string tolower [split $text]]
if {$text == ""} {puthelp "PRIVMSG $nick :Please specify a channel name, like, #foo";return}
if {[lsearch -exact $tchan $text] == -1} {
puthelp "PRIVMSG $nick :I'm not doing topics on channel \002[join $text]\002.. Sorry :P"
return
} else {
putserv "TOPIC $text :"
proc:rectopic $nick $uhost checktopic $text ""
}
}
proc proc:msgtopichelp {nick uhost hand text} {
global tchan
if {![onchan $nick]} {return}
set text [string tolower [split $text]]
if {$text == ""} {puthelp "PRIVMSG $nick :Please specify a channel name, like, #foo";return}
if {[lsearch -exact $tchan $text] == -1} {
puthelp "PRIVMSG $nick :I'm not doing topics on channel \002[join $text]\002.. Sorry :P"
return
} else {
proc:topichelp $nick $uhost $hand $text ""
}
}
proc proc:undotopic {nick uhost hand text} {
global tchan
set text [string tolower [split $text]]
if {$text == ""} {puthelp "PRIVMSG $nick :Please specify a channel name, like, #foo";return}
if {[lsearch -exact $tchan $text] == -1} {
puthelp "PRIVMSG $nick :I'm not doing topics on channel \002[join $text]\002.. Sorry :P"
return
} else {
putserv "TOPIC $text :"
return
}
}
proc proc:topichelp {nick uhost hand chan text} {
global botnick
set curtop \002[topic $chan]\002
puthelp "PRIVMSG $nick : Current topic on channel $chan: $curtop"
puthelp "PRIVMSG $nick : These are the available commands for topicrecover:"
puthelp "PRIVMSG $nick : \002/msg $botnick topicsearch #channel\002 - Show list of saved topics/index numbers for #channel."
if {![matchattr $hand o|o $chan]} {
puthelp "PRIVMSG $nick :\[end topic help\]"
return
} else {
puthelp "PRIVMSG $nick : \002/msg $botnick topicroll #channel\002 - Roll back to a different topic by index number."
puthelp "PRIVMSG $nick : \002/msg $botnick topicrec #channel\002 - Recover the last topic that was saved."
puthelp "PRIVMSG $nick : \002/msg $botnick topicredo #channel\002 - Unset topic then recover last topic."
puthelp "PRIVMSG $nick : \002/msg $botnick topicundo #channel\002 - Sets the topic blank."
puthelp "PRIVMSG $nick : \002/msg $botnick topicdel #channel\002 - Delete saved topic with index number."
puthelp "PRIVMSG $nick :\[end topic cmds\]"
return
}
}
proc proc:rectopic {nick uhost hand chan topic} {
global melttop botnick
set topic [string trim $topic]
set topic [split $topic]
set topicv ""
set topicdate [unixtime]
set topnick ""
if {($topic != "") && ($hand != "checktopic")} {
set topicfile [open $melttop(file) r]
while {![eof $topicfile]} {
set input [split [gets $topicfile] �]
if {[string equal -nocase [lindex $input 3] $topic]} {
# duplicate topics..don't save
#putcmdlog "duplicate topics, not saving..."
catch {close $topicfile}
return
}
}
catch {close $topicfile}
if {$nick != $botnick} {
set topicfile [open $melttop(file) a]
putcmdlog "Saved topic for $chan by $nick :[join $topic]"
puts $topicfile "[clock seconds]�$chan�$nick�[join $topic]"
catch {close $topicfile}
}
} elseif {$hand == "checktopic"} {
set topicfile [open $melttop(file) r]
while {![eof $topicfile]} {
set input [split [gets $topicfile] �]
if {[string equal -nocase [string trim [lindex $input 1]] $chan]} {
set topicv [string trim [lindex $input 3]]
set topicdate [string trim [lindex $input 0]]
set topnick [string trim [lindex $input 2]]
}
}
catch {close $topicfile}
if {$topicv != ""} {
putserv "TOPIC $chan :$topicv"
puthelp "PRIVMSG $nick :Recovering last topic. Topic was set by $topnick on [clock format $topicdate -format %D]"
} else {
puthelp "PRIVMSG $nick :Error: topicv was empty.."
}
}
}
proc proc:searchtopic { nick uhost hand chan text } {
global melttop
set ctops "";set ctopslength 0;set i 0
set topicfile [open $melttop(file) r]
while {![eof $topicfile]} {
set input [split [gets $topicfile] �]
if {[string trim [lindex $input 1]] == $chan} {
# stuff the topics into a var/list so we can show them newest to oldest
lappend ctops $input
}
}
catch {close $topicfile}
if {$ctops != ""} {
set ctops [lsort -integer -decreasing -index 0 $ctops]
foreach line $ctops {
set thistopic [lindex $line 3]
if {$i >= $melttop(max)} {
puthelp "PRIVMSG $nick :Further topics found, but maximum output ($melttop(max) lines) reached."
return
}
incr i
puthelp "PRIVMSG $nick :[lindex $line 1] Index#:\002[clock format [lindex $line 0] -format %s]\002 Set by:\002[lindex $line 2]\002 [clock format [lindex $line 0] -format %b.%d.%y]: $thistopic"
}
} else {
puthelp "PRIVMSG $nick :No saved topics found for $chan"
return
}
puthelp "PRIVMSG $nick :\[end topics\]"
}
proc proc:rollbacktopic { nick uhost hand chan text } {
global melttop
set topicfile [open $melttop(file) r]
set i 0
set found 0
while {![eof $topicfile]} {
set input [split [gets $topicfile] �]
if {[lindex $input 0] !=""} {
set topictime [clock format [string trim [lindex $input 0]] -format %s]
if {([string equal $topictime $text]) && ([string equal -nocase $chan [string trim [lindex $input 1]]])} {
putserv "TOPIC $chan :[join [lindex $input 3]]"
puthelp "PRIVMSG $nick :Topic \#$text found and set for channel $chan"
catch {close $topicfile}
return
}
}
}
catch {close $topicfile}
puthelp "PRIVMSG $nick :I didn't find topic number $text on $chan."
puthelp "PRIVMSG $nick :Use \002.topicroll #channel indexnumber\002 - Use \002.topicsearch #channel\002 for a list of topics/index numbers."
}
proc proc:deltopic {nick uhost hand text} {
global melttop tchan
if {![matchattr $hand n]} {
puthelp "PRIVMSG $nick :You are not worthy! SCHWING!"
return
}
if {$text == ""} {puthelp "PRIVMSG $nick :Please specify a channel name, like, #foo";return}
set text [string trim $text]
set chan [string tolower [lindex [split $text] 0]]
set topicnumber [lindex [split $text] 1]
if {[lsearch -exact $tchan $chan] == -1} {
puthelp "PRIVMSG $nick :I'm not doing topics on channel \002[join $chan]\002.. Sorry :P"
return
}
if {$topicnumber == ""} {
puthelp "PRIVMSG $nick :Please specify an index number to delete..Use \002.topicsearch #channel\002 to find index numbers."
return
}
set data2 ""
set topicfile [open $melttop(file) r]
set data [read -nonewline $topicfile]
catch {close $topicfile}
set lines [split $data "\n"]
set pattern "$topicnumber�$chan�*"
set delme [lsearch $lines $pattern]
if {$delme != -1} {
set data2 [lreplace $lines $delme $delme ]
set topicfile [open $melttop(file) w]
puts $topicfile [join $data2 "\n"]
puthelp "PRIVMSG $nick :Deleted $chan topic index #$topicnumber"
catch {close $topicfile}
} else {
puthelp "PRIVMSG $nick :Index number \'$text\' not found!"
}
}
##CHECK_TOPIC_TIME
proc check_topic_time {} {
global topictimer tchan botnick
# check all channels we're configured for
foreach chan [split $tchan] {
set curtopic [topic $chan]
# if the bot is not op and if the channel is mode +t, return, since it can't set topics
if {![botisop $chan] && [regexp {t} [lindex [getchanmode $chan] 0]]} {
putcmdlog "topicrecover timer: Cant guard the topic in $tchan if I dont have op there.."
return
}
if {$curtopic == ""} {
proc:rectopic $botnick uhost checktopic $chan ""
putcmdlog "topicrecover timer: setting topic in $chan because it was empty..."
} else {
#putcmdlog "topicrecover timer: Topic is already set in $chan"
}
}
if {![string match "*check_topic_time*" [timers]]} { timer $topictimer check_topic_time }
}
if {![string match "*check_topic_time*" [timers]]} { timer $topictimer check_topic_time }
putlog "Topicrecover loaded... 0.5rosc"