namespace eval ::ResyncTopic:: { # # Dieses Script funktioniert erst ab einem Eggdrop 1.6.15 # # Eggdrop 1.6.13 hat zumindest noch kein "setudef stri " #first edit: 18.Aug.2003 ### config set ConfigFile "ResyncTopic.conf" set PubTrigger ! set Commands { CMDHelp pub,msg,dcc o|v topichelp CMDGet pub,msg,dcc o|v topicget CMDResync pub,msg,dcc o|v topicresync CMDAutoResync pub,msg,dcc n|m topicautoresync CMDProtect pub,msg,dcc n|m topicprotect CMDLock pub,msg,dcc n|m topiclock } # Resync: do a manuel resync # Autoresync: switch on/off to resync after netsplit # Protect: Switch ReyncTopic for this channel on/off # Lock: Nobody can change the topic # Get: Read the actually topic ### 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 } } ### execute procs proc Help {username dest triggertype} { putnote $dest "Hilfe System zu ResyncTopic" $triggertype foreach item $::ResyncTopic::Commands { foreach {proc types flags cmd} $item { foreach type [split $types ,] { if {$type==$triggertype} { if {$type=="pub"} { #bind ${type} ${flags} ${trigger}${cmd} "[namespace current]::${type} ${proc}" } { #bind ${type} ${flags} ${cmd} "[namespace current]::${type} ${proc}" } } } } } } proc Get {channels {nick ""} {hand ""}} { foreach ircchannel $channels { if [validchan $ircchannel] { if [channel get $ircchannel ResyncTopic] { if {[topic $ircchannel]!=""} { putcmdlog "Get Topic in $ircchannel: [topic $ircchannel]" topc CMDTopicChange $nick host $hand $ircchannel [topic $ircchannel] } { putcmdlog "Topic is clean in $ircchannel" } } { putcmdlog "Dont Resync in $ircchannel" } } { putcmdlog "Get: $ircchannel is not valid!" } } Save } proc Resync {channels} { proc ResyncSet {ircchannel topic} { if {$topic==""} {return} if [string match *t* [getchanmode $ircchannel]] { if [botisop $ircchannel] { putcmdlog "Resync Topic $ircchannel" puthelp "TOPIC $ircchannel :Resyncing: $topic" puthelp "TOPIC $ircchannel :$topic" } { putcmdlog "Cant resync, i dont have op in $ircchannel" } } { putcmdlog "Resync Topic $ircchannel" puthelp "TOPIC $ircchannel :Resyncing: $topic" puthelp "TOPIC $ircchannel :$topic" } } 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})] { ResyncSet $ircchannel $::ResyncTopic::Topic(last${ircchannel}) } { putcmdlog "Topic not saved for $ircchannel" } } { putcmdlog "Dont Resync in $ircchannel" } } { putcmdlog "Rejoin: $ircchannel is not valid!" } } utimer 60 [list set ::ResyncTopic::ResyncNow 0] } proc AutoResync {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 } } } } } proc Protect {channels {switch ""}} { foreach chan $channels { if [validchan $chan] { 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 } } } } proc Lock {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 } } } } } ### bind 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})==1} { 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 pub {command ircnick irchost username ircchannel text} { switch -exact -- $command { default { putlog "Wrong Command with ::ResyncTopic::pub $command $ircnick $irchost $username $ircchannel $text" } } } proc msg {command ircnick irchost username text} { set list [split $text] set chan [lindex $list 0] set arg2 [lindex $list 1] if {$arg2!=""} { if {$arg2=="on" || $arg2=="1"} { set arg2 1 } elseif {$arg2=="off" || $arg2=="0"} { set arg2 0 } else { putnote $ircnick "No valid switch, must be \"on\", \"1\", \"off\" or \"0\"" return 0 } } if {$chan=="" && $command!="CMDHelp"} { putnote $ircnick "Channel is required!" return 0 } elseif {$chan=="*" || $chan=="all"} { set list [list] foreach chan [channels] { if {[validchan $chan] && [channel get $chan ResyncTopic]} { lappend list $chan } } set chan $list if {[lindex $chan 0]==""} { putnote $ircnick "No valid chan found!" return 0 } { putnote $ircnick "Using [join $chan ,] channels." } } elseif {$command!="CMDHelp"} { 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] { putnote $ircnick "$chan is not a valid channel!" return 1 } } } switch -exact -- $command { CMDHelp { Help $username $ircnick msg } CMDGet { putcmdlog "Get $chan"; Get $chan $ircnick $username } CMDResync { putcmdlog "Resync $chan"; Resync $chan } CMDAutoResync { putcmdlog "AutoResync $chan $arg2"; AutoResync $chan $arg2 } CMDProtect { putcmdlog "Protect $chan $arg2"; Protect $chan $arg2 } CMDLock { putcmdlog "Lock $chan $arg2"; Lock $chan $arg2 } default { putlog "Wrong Command with ::ResyncTopic::msg $command $ircnick $irchost $username $text" } } } proc dcc {command username idx text} { switch -exact -- $command { CMDHelp { Help $username $idx dcc } default { putlog "Wrong Command with ::ResyncTopic::dcc $command $username $idx $text" } } } 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 }