namespace eval ::ResyncTopic:: { # # Dieses Script funktioniert erst ab einem Eggdrop 1.6.15 # #first edit: 18.Aug.2003 ### config set ConfigFile "ResyncTopic.conf" set PubTrigger ! set Commands { CMDHelp pub,msg,dcc -|- topichelp CMDStatus pub,msg,dcc o|v topicstatus CMDProtect pub,msg,dcc n|m topicprotect CMDResync pub,msg,dcc o|v topicresync CMDAutoResync pub,msg,dcc n|m topicautoresync CMDGet pub,msg,dcc o|v topicget CMDLock pub,msg,dcc n|m topiclock } # Protect: Switch ResyncTopic for this channel on/off # Resync: do a manuel resync # Autoresync: switch on/off to resync after netsplit # Lock: Nobody can change the topic # Get: Read the actually topic # Status: Get the actually settings ### vars if ![info exist ResyncNow] { set ResyncNow 0 } setudef flag ResyncTopic if ![array exist Topic] {array set Topic {}} ### helper set Procs { CMDTopicChange topc - * CMDNetsplit splt - * CMDNetjoin rejn - * CMDTime time - * } set PubTrigger [string trim $PubTrigger]; if ![info exists ::ResyncTopic::OldTrigger] {set ::ResyncTopic::OldTrigger $::ResyncTopic::PubTrigger} set tCMD [list]; foreach {cmd type flags trigger} $Commands { lappend tCMD "$cmd [string tolower $type] $flags [string tolower $trigger]" }; set Commands $tCMD set tCMD [list]; foreach {cmd type flags trigger} $Procs { lappend tCMD "$cmd [string tolower $type] $flags [string tolower $trigger]" }; set Procs $tCMD unset tCMD ### help procs proc Load {} { if [file exist $::ResyncTopic::ConfigFile] { source $::ResyncTopic::ConfigFile } { putcmdlog "Configfile for ResyncTopic not found" } } proc Save {} { set fh [open $::ResyncTopic::ConfigFile w] puts $fh "set ::ResyncTopic::PubTrigger $::ResyncTopic::PubTrigger" puts $fh "array set ::ResyncTopic::Topic \[list [array get ::ResyncTopic::Topic]]" close $fh } proc putnote {dest text {triggertype "priv"}} { if {$triggertype=="dcc"} { putidx $dest $text } { putnotc $dest $text } } ### command procs proc Help {username dest triggertype {channels ""}} { proc Show {proc cmd dest type {append ""}} { if {$type=="pub"} {set insert $::ResyncTopic::PubTrigger} {set insert ""} #putcmdlog "proc $proc type $type cmd $cmd" switch -exact -- $proc { CMDHelp { putnote $dest "$insert$cmd \[chan] - This help" $type } CMDStatus { putnote $dest "$insert$cmd \[chan] - Show the settings from one or more channels $append" $type } CMDProtect { putnote $dest "$insert$cmd - Switch ResyncTopic for a channel on/off $append" $type } CMDGet { putnote $dest "$insert$cmd - Get the topic from a chan $append" $type } CMDResync { putnote $dest "$insert$cmd - Update topic manual $append" $type } CMDAutoResync { putnote $dest "$insert$cmd - Switch auto resync on/off $append" $type } CMDLock { putnote $dest "$insert$cmd - Lock the topic for everyone $append" $type } default { putlog "Wrong Help with ::ResyncTopic::Help::Show $proc $cmd $dest $triggertype $channels $append" } } } #putcmdlog "Help channels $channels" if {$channels==""} { putnote $dest "General help for ResyncTopic" $triggertype foreach item $::ResyncTopic::Commands { foreach {proc types flags cmd} $item { Show $proc $cmd $dest $triggertype } } } { putnote $dest "Help for ResyncTopic in the channels $channels" $triggertype foreach item $::ResyncTopic::Commands { foreach {proc types flags cmd} $item { set allow [list] foreach chan $channels { #putcmdlog "check $chan - $proc==CMDHelp || $proc==CMDStatus || $proc==CMDProtect || [channel get $chan ResyncTopic]" if {$proc=="CMDHelp" || $proc=="CMDStatus" || $proc=="CMDProtect" || [channel get $chan ResyncTopic]} { #putcmdlog "cmd $cmd (proc $proc) is valid in $chan" } { #putcmdlog "cmd $cmd (proc $proc) is not valid in $chan - break" break } if [matchattr $username $flags $chan] { lappend allow $chan } } if {$allow!=[list]} { if {$allow!=$channels} { set append "- allow in [join $allow ", "]" } { set append "" } Show $proc $cmd $dest $triggertype $append } } } } } proc Status {username dest triggertype {channels ""}} { #putcmdlog "Status username $username dest $dest triggertype $triggertype channels $channels" set offchan [list] foreach chan $channels { if [validchan $chan] { if [channel get $chan ResyncTopic] { #putcmdlog "X1" set text "Topic Protect is \002on\002 for $chan" if [info exists ::ResyncTopic::Topic(lock${chan})] { if $::ResyncTopic::Topic(lock${chan}) { append text ", lock is \002on\002" } { append text ", lock is \002off\002" } } { append text ", lock is \002off\002" } #putcmdlog "X2" if [info exists ::ResyncTopic::Topic(auto${chan})] { if $::ResyncTopic::Topic(auto${chan}) { append text ", auto resync is \002on\002" } { append text ", auto resync is \002off\002" } } { append text ", auto resync is \002off\002" } #putcmdlog "X3" putnote $dest $text $triggertype #putcmdlog "info exist ::ResyncTopic::Topic(last${chan}) == [info exist ::ResyncTopic::Topic(last${chan})]" if [info exist ::ResyncTopic::Topic(last${chan})] { #putcmdlog "CMD: Last known topic: $::ResyncTopic::Topic(last${chan})" if [info exist ::ResyncTopic::Topic(lastnick${chan})] { set by "from $::ResyncTopic::Topic(lastnick${chan})" } { set by "" } putnote $dest "Last known topic: '$::ResyncTopic::Topic(last${chan})' $by" $triggertype } { putnote $dest "Never saved a topic" $triggertype } } { lappend offchan $chan } } } if {$offchan!=[list]} { putnote $dest "Topic Protect is \002off\002 for [join $offchan ", "]" $triggertype } } proc Get {username dest triggertype channels} { foreach ircchannel $channels { if [validchan $ircchannel] { if [channel get $ircchannel ResyncTopic] { if {[topic $ircchannel]!=""} { putcmdlog "Get Topic in $ircchannel: [topic $ircchannel]" topc CMDTopicChange [hand2nick $username] [getchanhost [hand2nick $username]] $username $ircchannel [topic $ircchannel] } { putcmdlog "Topic is clean in $ircchannel" } } { putcmdlog "Dont Resync in $ircchannel" } } { putcmdlog "Get: $ircchannel is not valid!" } } Save } proc Resync {channels {Retry 0} {manual 0}} { #putcmdlog "Resync channels $channels Retry $Retry manual $manual" proc ResyncSet {ircchannel topic {from ""} {manual 0}} { #putcmdlog "ResyncSet ircchannel $ircchannel topic $topic from $from manual $manual" if {$topic==""} {return} if [string match *t* [getchanmode $ircchannel]] { if [botisop $ircchannel] { putcmdlog "Resync Topic $ircchannel" if $manual { puthelp "TOPIC $ircchannel :Resyncing: $topic" } if {$from==""} { puthelp "TOPIC $ircchannel :$topic" } { puthelp "TOPIC $ircchannel :$topic from $from" } } { putcmdlog "Cant resync, i dont have op in $ircchannel" if {$Retry<2} { putcmdlog "Retry in 5 minutes" incr Retry timer 5 [list ::ResyncTopic::Resync $ircchannel $Retry] } } } { putcmdlog "Resync Topic $ircchannel" if $manual { puthelp "TOPIC $ircchannel :Resyncing: $topic" } if {$from==""} { puthelp "TOPIC $ircchannel :$topic" } { puthelp "TOPIC $ircchannel :$topic from $from" } } } if $::ResyncTopic::ResyncNow { putcmdlog "Topic resync in progress, no more resync required" return } set ::ResyncTopic::ResyncNow 1 after 5000 foreach ircchannel $channels { if [validchan $ircchannel] { if [channel get $ircchannel ResyncTopic] { if [info exist ::ResyncTopic::Topic(last${ircchannel})] { if {$manual && [info exist ::ResyncTopic::Topic(lastnick${ircchannel})] } { set from $::ResyncTopic::Topic(lastnick${ircchannel}) } {set from "" } ResyncSet $ircchannel $::ResyncTopic::Topic(last${ircchannel}) $from $manual } { putcmdlog "Topic not saved for $ircchannel" } } { putcmdlog "Dont Resync in $ircchannel" } } { putcmdlog "Rejoin: $ircchannel is not valid!" } } timer 4 [list set ::ResyncTopic::ResyncNow 0] } proc AutoResync {username dest triggertype channels {switch ""}} { foreach chan $channels { if [validchan $chan] { if [channel get $chan ResyncTopic] { if {$switch==""} { if [info exists ::ResyncTopic::Topic(auto${chan})] { set ::ResyncTopic::Topic(auto${chan}) [expr $::ResyncTopic::Topic(auto${chan}) ^ 1] } { set ::ResyncTopic::Topic(auto${chan}) 1 } } elseif {$switch=="1"} { set ::ResyncTopic::Topic(auto${chan}) 1 } elseif {$switch=="0"} { set ::ResyncTopic::Topic(auto${chan}) 0 } if $::ResyncTopic::Topic(auto${chan}) { putnote $dest "Auto sync is now \002on\002 for $chan" $triggertype } { putnote $dest "Auto sync is now \002off\002 for $chan" $triggertype } } } } } proc Protect {username dest triggertype channels {switch ""}} { #putcmdlog "Protect username $username dest $dest triggertype $triggertype channels $channels switch $switch" foreach chan $channels { #putcmdlog "check chan $chan" if [validchan $chan] { #putcmdlog "$chan is valid" if {$switch==""} { if [channel get $chan ResyncTopic] {channel set $chan -ResyncTopic} {channel set $chan +ResyncTopic} } elseif {$switch=="1"} { channel set $chan +ResyncTopic } elseif {$switch=="0"} { channel set $chan -ResyncTopic } #putcmdlog "send [channel get $chan ResyncTopic]" if [channel get $chan ResyncTopic] { putnote $dest "Topic Protect is now \002on\002 for $chan" $triggertype } { putnote $dest "Topic Protect is now \002off\002 for $chan" $triggertype } } } } proc Lock {username dest triggertype channels {switch ""}} { foreach chan $channels { if [validchan $chan] { if [channel get $chan ResyncTopic] { if {$switch==""} { if [info exists ::ResyncTopic::Topic(lock${chan})] { set ::ResyncTopic::Topic(lock${chan}) [expr $::ResyncTopic::Topic(lock${chan}) ^ 1] } { set ::ResyncTopic::Topic(lock${chan}) 1 } } elseif {$switch=="1"} { set ::ResyncTopic::Topic(lock${chan}) 1 } elseif {$switch=="0"} { set ::ResyncTopic::Topic(lock${chan}) 0 } if $::ResyncTopic::Topic(lock${chan}) { putnote $dest "Topic lock is now \002on\002 for $chan" $triggertype } { putnote $dest "Topic lock is now \002off\002 for $chan" $triggertype } } } } } ### trigger procs proc topc {command ircnick irchost username ircchannel text} { switch -exact -- $command { CMDTopicChange { if $::ResyncTopic::ResyncNow { #putcmdlog "Topic resync in progress, ignore topic change" return } if [channel get $ircchannel ResyncTopic] { if {![onchan $ircnick $ircchannel] && $text==""} { putcmdlog "Topic is not from a User, ignore" return } foreach num "4 3 2 1" { set num2 [expr ${num}-1]; if {$num2=="0"} {set num2 ""} if [info exists ::ResyncTopic::Topic(last${num2}${ircchannel})] { set ::ResyncTopic::Topic(last${num}${ircchannel}) $::ResyncTopic::Topic(last${num2}${ircchannel}) set ::ResyncTopic::Topic(lastnick${num}${ircchannel}) $::ResyncTopic::Topic(lastnick${num2}${ircchannel}) set ::ResyncTopic::Topic(lastuser${num}${ircchannel}) $::ResyncTopic::Topic(lastuser${num2}${ircchannel}) } } set ::ResyncTopic::Topic(last${ircchannel}) $text set ::ResyncTopic::Topic(lastnick${ircchannel}) $ircnick set ::ResyncTopic::Topic(lastuser${ircchannel}) $username putcmdlog "Newtopic in $ircchannel: $text" } { #putcmdlog "Ignore Topic in $ircchannel: $text" } } default { putlog "Wrong Command with ::ResyncTopic::topc $command $ircnick $irchost $username $ircchannel $text" } } Save } proc splt {command ircnick irchost username ircchannel} { switch -exact -- $command { CMDNetsplit {} default { putlog "Wrong Command with ::ResyncTopic::splt $command $ircnick $irchost $username $ircchannel" } } } proc rejn {command ircnick irchost username ircchannel} { switch -exact -- $command { CMDNetjoin { if $::ResyncTopic::ResyncNow { #putcmdlog "Topic resync in progress, no more resync required" return } set list [list] foreach chan [channels] { if {[validchan $chan] && [channel get $chan ResyncTopic]} { if [info exist ::ResyncTopic::Topic(auto${chan})] { if {$::ResyncTopic::Topic(auto${chan})} { lappend list $chan } } } } set chan $list Resync $chan } default { putlog "Wrong Command with ::ResyncTopic::rejn $command $ircnick $irchost $username $ircchannel" } } } proc time {command args} { switch -exact -- $command { CMDTime {} default { putlog "Wrong Command with ::ResyncTopic::splt $command $ircnick $irchost $username $ircchannel" } } } proc command {command ircnick irchost username dest triggertype {chan ""} {arg2 ""}} { #putcmdlog "command $command ircnick $ircnick irchost $irchost username $username dest $dest triggertype $triggertype chan $chan arg2 $arg2" if {$arg2!=""} { if {$arg2=="on" || $arg2=="1"} { set arg2 1 } elseif {$arg2=="off" || $arg2=="0"} { set arg2 0 } else { putnote $dest "No valid switch, must be \"on\", \"1\", \"off\" or \"0\"" $triggertype return 0 } } if {$chan==""} { if {$command!="CMDHelp" && $command!="CMDStatus"} { putnote $dest "Channel is required!" $triggertype return 0 } if {$command=="CMDStatus"} { set list [list] foreach chan [channels] { if {[validchan $chan] && ![channel get $chan inactive]} { lappend list $chan } } set chan $list if {[lindex $chan 0]==""} { putnote $dest "No valid chan found!" $triggertype return 0 } { putnote $dest "Using [join $chan ", "] channel(s)." $triggertype } } } elseif {$chan=="*" || $chan=="all"} { set list [list] if {$command=="CMDStatus"} { foreach chan [channels] { if {[validchan $chan] && ![channel get $chan inactive]} { lappend list $chan } } } { foreach chan [channels] { if {[validchan $chan] && [channel get $chan ResyncTopic]} { lappend list $chan } } } set chan $list if {[lindex $chan 0]==""} { putnote $dest "No valid chan found!" $triggertype return 0 } { putnote $dest "Using [join $chan ", "] channel(s)." $triggertype } } { if {[llength [split $chan ,]]>1} { set channels [split $chan ,]; set list [list] foreach chan $channels { if {[validchan $chan] && [channel get $chan ResyncTopic]} { lappend list $chan } } set chan $list } { if {(![validchan $chan] || ![channel get $chan ResyncTopic]) && $command!="CMDHelp" && $command!="CMDStatus" && $command!="CMDProtect"} { putnote $dest "$chan is not a valid channel with $command!" $triggertype return 1 } } } #putcmdlog "command $command hand $username nick $ircnick chan $chan dest $dest" switch -exact -- $command { CMDHelp { Help $username $dest $triggertype $chan } CMDStatus { Status $username $dest $triggertype $chan } CMDGet { Get $username $dest $triggertype $chan } CMDResync { if $::ResyncTopic::ResyncNow { putnote $dest "Topic resync in progress" $triggertype } { putcmdlog "Resync $chan"; Resync $chan 0 1 } } CMDAutoResync { AutoResync $username $dest $triggertype $chan $arg2 } CMDProtect { Protect $username $dest $triggertype $chan $arg2 } CMDLock { Lock $username $dest $triggertype $chan $arg2 } default { putlog "Wrong Command with ::ResyncTopic::command $command hand $username nick $ircnick chan $chan dest $dest" } } } proc pub {command ircnick irchost username ircchannel text} { set list [split $text] #putcmdlog "pub command $command text $text [llength $list]" if {[llength $list]==1} { set chan $ircchannel set arg2 [lindex $list 0] if {$arg2=="*" || $arg2=="all" || [string index $arg2 0]=="#"} { set chan $arg2; set arg2 "" } } elseif {[llength $list]==2} { set chan [lindex $list 0] set arg2 [lindex $list 1] } { set chan $ircchannel set arg2 "" } command $command $ircnick $irchost $username $ircchannel pub $chan $arg2 } proc msg {command ircnick irchost username text} { set list [split $text] set chan [lindex $list 0] set arg2 [lindex $list 1] #putcmdlog "ResyncTopic: msg chan $chan arg2 $arg2 - [hand2nick $username] - [getchanhost [hand2nick $username]] - [lindex [split [getchanhost [hand2nick $username]] !] 1]" command $command $ircnick $irchost $username $ircnick msg $chan $arg2 } proc dcc {command username idx text} { set list [split $text] set chan [lindex $list 0] set arg2 [lindex $list 1] #putcmdlog "ResyncTopic: dcc chan $chan arg2 $arg2 - [hand2nick $username] - [getchanhost [hand2nick $username]] - [lindex [split [getchanhost [hand2nick $username]] !] 1]" command $command [hand2nick $username] [getchanhost [hand2nick $username]] $username $idx dcc $chan $arg2 } proc init {{args [list]}} { proc on {trigger} { foreach item $::ResyncTopic::Commands { foreach {proc types flags cmd} $item { foreach type [split $types ,] { if {$type=="pub"} { bind ${type} ${flags} ${trigger}${cmd} "[namespace current]::${type} ${proc}" } { bind ${type} ${flags} ${cmd} "[namespace current]::${type} ${proc}" } } } } foreach item $::ResyncTopic::Procs { foreach {proc types flags cmd} $item { foreach type [split $types ,] { bind ${type} ${flags} ${cmd} "[namespace current]::${type} ${proc}" } } } } proc off {trigger} { #putcmdlog "unbind commands" foreach item $::ResyncTopic::Commands { foreach {proc types flags cmd} $item { foreach type [split $types ,] { #putcmdlog "unbind $type $flags ${cmd} ${proc}" set result [catch { if {$type=="pub"} { unbind ${type} ${flags} ${trigger}${cmd} "[namespace current]::${type} ${proc}" } { unbind ${type} ${flags} ${cmd} "[namespace current]::${type} ${proc}" } } msg]; # set result catch #putcmdlog "unbind result: $result - $msg - unbind ${type} ${flags} ${cmd} ${proc}" } } } #putcmdlog "unbind procs" foreach item $::ResyncTopic::Procs { foreach {proc types flags cmd} $item { foreach type [split $types ,] { #putcmdlog "unbind $type $flags ${cmd} ${proc}" set result [catch { unbind ${type} ${flags} ${cmd} "[namespace current]::${type} ${proc}" } msg]; # set result catch #putcmdlog "unbind result: $result - $msg - unbind ${type} ${flags} ${cmd} ${proc}" } } } } switch -- [lindex $args 0] { init { Load; init on } changetrigger { putlog "Change ResyncTopic Trigger from $::ResyncTopic::PubTrigger to [string trim [lindex $args 1]]" off [string trim $::ResyncTopic::PubTrigger] on [string trim [lindex $args 1]] set ::ResyncTopic::PubTrigger [string trim [lindex $args 1]] set ::ResyncTopic::OldTrigger $::ResyncTopic::PubTrigger } off {off [string trim $::ResyncTopic::PubTrigger]} on { if {$::ResyncTopic::PubTrigger!=$::ResyncTopic::OldTrigger} { off [string trim $::ResyncTopic::OldTrigger] } on [string trim $::ResyncTopic::PubTrigger] } default {putlog "Wrong Command with ::ResyncTopic::init $args"} } } init init putlog "ResyncTopic 0.3 loaded" }