setudef flag FixLang setudef flag PubFixLang namespace eval ::FixLang:: { set Userlist(init:users) 1 proc Swap {text from to} { #putcmdlog "swap1 '$text' '$from' '$to'" set text [string map [list $from $to] $text] #putcmdlog "swap2 '$text' '$from' '$to'" return $text } proc Append {text append} { #putcmdlog "append1 '$text' '$append'" append text $append #putcmdlog "append2 '$text' '$append'" return $text } proc Insert {text from insert} { #putcmdlog "insert1 t'$text' f'$from' i'$insert' == string map [list "$from" "$from$insert"] $text == [string map [list "$from" "$from$insert"] $text]" set text [string map [list "$from" "$from$insert"] $text] #putcmdlog "insert2 '$text' '$from' '$insert'" return $text } proc SwapWord {text from to} { #putcmdlog "swapword1 '$text' '$from' '$to'" set list [split $text]; set nword [lsearch -exact $list $from] while {$nword!=-1} { set list [lreplace $list $nword $nword $to] set nword [lsearch -exact $list $from] } set text [join $list] #putcmdlog "swapword2 '$text' '$from' '$to'" return $text } proc AppendWord {text append} { #putcmdlog "append1 '$text' '$append'" append text " $append" #putcmdlog "append2 '$text' '$append'" return $text } proc InsertWord {text from insert} { #putcmdlog "insert1 t'$text' f'$from' i'$insert' == string map [list "$from" "$from$insert"] $text == [string map [list "$from" "$from$insert"] $text]" set text [string map [list "$from" "$from $insert"] $text] #putcmdlog "insert2 '$text' '$from' '$insert'" return $text } proc FixLang {nick uh hand chan text} { if ![channel get $chan FixLang] { return 0 } #putcmdlog "set uname" if {$hand!="*" && $hand!=""} { set uname $hand } else { set uname $nick } #putcmdlog "use savenick $uname" set usefeature 0; set text "$text" if {[info exi ::FixLang::Userlist(text:$chan:$uname)]} { set lasttext $::FixLang::Userlist(text:$chan:$uname) } { set lasttext $text } set urltext $lasttext; set urtext $text # func/source/dest #putcmdlog "fnr 0" set fnr 0; set cmd ""; set search ""; set data ""; if {[llength [split $text \/]]>1} {set usefeature 1} foreach part [split $text \/] { switch -exact -- $fnr { 3 { ##putcmdlog "param nr 3 startet - search $search - data $data " if {$cmd=="replace"} {set lasttext [Swap $lasttext $search $data]; set get "Swap $lasttext $search $data"; set fnr -1} if {$cmd=="wordreplace"} {set lasttext [SwapWord $lasttext $search $data]; set get "Swap $lasttext $search $data"; set fnr -1} if {$cmd=="append"} {if {$data!=""} {set lasttext [Insert $lasttext $search $data]; set get $lasttext; set fnr -1} {set lasttext [Append $lasttext $search]; set get $lasttext; set fnr -1} } if {$cmd=="wordappend"} {if {$data!=""} {set lasttext [InsertWord $lasttext $search $data]; set get $lasttext; set fnr -1} {set lasttext [AppendWord $lasttext $search]; set get $lasttext; set fnr -1} } } 2 { if {$cmd=="replace" || $cmd=="append" || $cmd=="wordreplace" || $cmd=="wordappend"} { set data $part; set get $part; incr fnr } } 1 { if {$cmd=="replace" || $cmd=="append" || $cmd=="wordreplace" || $cmd=="wordappend"} { set search $part; set get $part; incr fnr } } 0 { set command [lindex [split $part] end]; set get $command #putcmdlog "command $command" switch -exact -- $command { rw - sw - wr - ws { set cmd wordreplace; incr fnr } aw - wa { set cmd wordappend; incr fnr } r - s { set cmd replace; incr fnr } a { set cmd append; incr fnr } #default { putcmdlog "no match command $command" } } } -1 { set fnr 0 } default { #putcmdlog "no match fnr $fnr" incr fnr } } #putcmdlog "after switch fnr $fnr - c $cmd - g $get - p $part" } if {$fnr>1} { #putcmdlog "search $search data $data" #putcmdlog "lasttext $lasttext" if {$cmd=="replace"} {set lasttext [Swap $lasttext $search $data]; set get "Swap $lasttext $search $data"; set fnr -1} if {$cmd=="wordreplace"} {set lasttext [SwapWord $lasttext $search $data]; set get "Swap $lasttext $search $data"; set fnr -1} if {$cmd=="append"} {if {$data!=""} {set lasttext [Insert $lasttext $search $data]; set get $lasttext; set fnr -1} {set lasttext [Append $lasttext $search]; set get $lasttext; set fnr -1} } if {$cmd=="wordappend"} {if {$data!=""} {set lasttext [InsertWord $lasttext $search $data]; set get $lasttext; set fnr -1} {set lasttext [AppendWord $lasttext $search]; set get $lasttext; set fnr -1} } #putcmdlog "lasttext2 $lasttext" } #putcmdlog "use $usefeature" if !$usefeature { if {[string trim $text]!=""} { if {[info exi ::FixLang::Userlist(text:$chan:$uname)] && $::FixLang::Userlist(text:$chan:$uname)!=$text || ![info exi ::FixLang::Userlist(text:$chan:$uname)] } { set found 0 set found [regexp {\s\s} $text] #putcmdlog "pre [regexp {\s\s} $text] $text" while {$found!=0} { regsub -all {\s\s} $text { } text set found [regexp {\s\s} $text] #putcmdlog "run [regexp {\s\s} $text] $text" } #putcmdlog "post [regexp {\s\s} $text] $text" #putcmdlog "saveto $uname ([string trim $text])" set ::FixLang::Userlist(text:$chan:$uname) [string trim $text] } { #putcmdlog "dont save text" } } { #putcmdlog "string is empty" } } { #putcmdlog "[string trim $lasttext]!='' && [string trim $lasttext]!=[string trim $urltext]" if {[string trim $lasttext]!="" && [string trim $lasttext]!=[string trim $urltext]} { #putcmdlog "pre [regexp {\s\s} $lasttext] $lasttext" set found [regexp {\s\s} $lasttext] while {$found!=0} { regsub -all {\s\s} $lasttext { } lasttext set found [regexp {\s\s} $lasttext] #putcmdlog "run [regexp {\s\s} $lasttext] $lasttext" } #putcmdlog "post [regexp {\s\s} $lasttext] $lasttext" #putcmdlog "Fix text from $nick in $chan to '$lasttext'" if {[channel get $chan PubFixLang]} { putmsg $chan "$nick correct to '$lasttext'." } set ::FixLang::Userlist(text:$chan:$uname) [string trim $lasttext] } } } } bind pubm - * ::FixLang::FixLang return "[info scr] loaded"