# CETK epic Topic Management script 0.0 # unload cetk.topicmgmt package cetk.topicmgmt load cetk.functions # Configurator. # alias.t topic.cfg (args) { $getopts(:args cetk.topic. "hs:f:" $args) if (cetk.topic.h) { @ cetk.topic.h = [] echo -s sep Specify a topic separator for joined topics. echo -f file Specify a file for storing topics. } elsif (isdisplaying()) { foreach cetk.topic var { echo -$tolower($var) $cetk[topic][$var] } } } # Save all topics so the other functions can work. # fe (332 topic) foo { on #-$foo 202 * { @ :utime = unsplit(_ $utime()) @ :echan = [$encodel($1)] @ topic[$echan] = topic[$echan][$utime] = [$2-] fe ($cetk.topic.f) file { ^assign.esave $file topic.${echan}.${utime} } } } # Add/del/insert topics. # alias.t topic.replace (topic) { @ :sep = cetk[topic][s] ? cetk[topic][s] : [||] @ :chan = ischannel($topic) ? shift(topic) : C @ :oldtopic = topic[$encodel($chan)] if (!#topic) { echo ${t}: [chan] deletion-points [insertion-point] [topic-to-insert] } elsif (strlen($oldtopic)) { @ :del = shift(topic) @ :del = split(, $del) fe del del {@ del = del =~ [*.*] ? jot($split(. $del)) : del} @ :ins = isnumber(b10 $topic) ? shift(topic) : 0 @ :newtopic = [] for (@ :foo = 0, strlen($oldtopic), @ ++foo) { if (foo == ins && topic) { push newtopic $sep $topic } if (!match($foo $del)) { push newtopic $sep $beforrw($sep $oldtopic) } @ oldtopic = afterw($sep $oldtopic) } if (foo <= ins && topic) { push newtopic $sep $topic } shift newtopic topic $chan $newtopic } else { topic $chan echo Fetching topic (try again). } } # Set a previous topic. # alias.t topic.last (args) { if (args) { @ :chan = ischannel($args) ? shift(args) : C @ :foo = aliasctl(assign match topic.$encodel($chan).) @ :num = isnumber(b10 $args) ? shift(args) : 0 @ :num += 0 > num ? numwords($foo) : 0 @ :var = word($num $foo) if (functioncall()) { return $($var) } elsif (ischanop($servernick() $chan)) { topic $chan $($var) purge $var } } else { echo ${t}: [chan] [number] } } # Search and display saved topics. # alias.t topic.list (mask) { @ :num = isnumber(b10 $mask) ? shift(mask) : 0 @ :chans = shift(mask) foreach topic foo { if (rmatch($decode($foo) $chans)) { @ :count = 0 @ :this = 0 foreach topic.$foo bar { @ count++ } foreach topic.$foo bar { if (topic[$foo][$bar] !~ mask) { } elsif (0 > num && num > bar - time()) { } elsif (0 < num && num < count - this) { } else { echo $stime($bar) [$decode($foo)] [$this]$chr(9)$topic[$foo][$bar] } @ this++ } } } if (!chans) { echo ${t}: [num] chanmask topicmasks } } # Saved topic stats. # alias.t topic.stat (chans) { @ :min = isnumber(b10 $chans) ? shift(chans) : 0 @ :max = isnumber(b10 $chans) ? shift(chans) : 0 foreach topic foo { if (rmatch($decode($foo) $chans)) { @ :count = :mint = :maxt = 0 foreach topic.$foo bar { @ :count++ @ mint ? (maxt = bar) : (maxt = mint = bar) } if (min && count < min) { } elsif (max && count > max) { } else { echo $stime($mint) - $stime($maxt) - $[-18]tdiff2(${maxt-mint}) $[-5]count $decode($foo) } } } if (!chans) { echo ${t}: [min] [max] chanmask } } # Purge saved topics by count. # alias.t topic.reap (args) { @ :count = :total = 0 @ :num = isnumber(b10 $args) ? shift(args) : 1 @ :time = isnumber(b10 $args) ? shift(args) : -86400 @ :time = time < 0 ? time() + time : time foreach topic chan { @ :list = aliasctl(assign match topic.${chan}.) @ :list = revw($list) @ :total += numwords($list) @ :chan = decode($chan) @ splice(list 0 $num) fe list list { @ list = after(2 . $list) < time && [$chan $($list)] =~ args ? list : [] } @ :count += numwords($list) purge $list } if (args) { echo $count / $total = ${(100*count)/total}% topics purged. } else { echo ${t}: [count] [time|-age] mask } } # Purge duplicate saved topics. # alias.t topic.uniq (args) { @ :max = isnumber(b10 $args) ? shift(args) : 4 foreach topic chan { if (rmatch($decode($chan) $args)) { unshift :chans $chan } } fe ($chans) chan { @ :not = 0 @ delarray(${t}) foreach topic[$chan] ctime { if (0 > finditem(${t} $topic[$chan][$ctime])) { @ setitem(${t} ${not++%max} $topic[$chan][$ctime]) @ ++:kept } else { purge topic[$chan][$ctime] @ ++:purged } } @ delarray(${t}) } if (args) { echo $purged : $kept = ${(100*purged)/(purged+kept)}% topics purged. } else { echo ${t}: [num] chanmask } }