Page MenuHomeDevCentral

D1366.diff
No OneTemporary

D1366.diff

diff --git a/Wearg/ServersLog.tcl b/Wearg/ServersLog.tcl
--- a/Wearg/ServersLog.tcl
+++ b/Wearg/ServersLog.tcl
@@ -3,6 +3,19 @@
bind pub - .+log pub:log
bind dcc - +log dcc:log
+bind pubm - "#* \[*\] *" pubm:log
+
+proc pubm:log {nick uhost handle chan text} {
+ regexp "\\\[(.*)\\\] (.*)" $text match component entry
+
+ if {[is_known_component $component]} {
+ add_to_servers_log $emitter "$network $source" $component $entry
+ putcmdlog "<<$nick>> !$handle! .+log $text"
+ } {
+ putserv "PRIVMSG $chan :$nick, if you wish to log that, confirm with .+log $text"
+ }
+}
+
proc pub:log {nick uhost handle chan arg} {
set callback [get_putbymode_chan_callback $chan $nick]
handle_send_to_servers_log [resolve_nick $nick] $chan $arg $callback
@@ -13,6 +26,20 @@
handle_send_to_servers_log $handle $username $arg "dcc $idx"
}
+proc is_known_component {candidate} {
+ # If "Dwellers" is a known component, are known:
+ # - Dwellers
+ # - Dwellers/DevCentral
+
+ foreach component [registry get serverslog.knowncomponents] {
+ if {[regexp ^${component}(/.+)?$ $candidate]} {
+ return 1
+ }
+ }
+
+ return 0
+}
+
proc handle_send_to_servers_log {emitter source arg callback} {
global network
diff --git a/tests/ServersLog.test b/tests/ServersLog.test
new file mode 100644
--- /dev/null
+++ b/tests/ServersLog.test
@@ -0,0 +1,48 @@
+package require tcltest
+namespace import ::tcltest::*
+
+###
+### Init
+###
+
+# Tested code
+source init.tcl
+source $dir/Wearg/ServersLog.tcl
+
+###
+### Mocks
+###
+
+proc registry {command key {value ""}} {
+ if {$command == "get" && $key == "serverslog.knowncomponents"} {
+ return "Alpha Beta"
+ }
+
+ error "Unexpected registry call: $command $key $value"
+}
+
+###
+### Tests
+###
+
+test is_known_component_when_known {} -body {
+ is_known_component Alpha
+} -result 1
+
+test is_known_component_when_known_parent {} -body {
+ is_known_component Beta/Delta
+} -result 1
+
+test is_known_component_with_trailing_slash {} -body {
+ is_known_component Beta/
+} -result 0
+
+test is_known_component_when_unknown {} -body {
+ is_known_component Gamma
+} -result 0
+
+###
+### Cleanup
+###
+
+cleanupTests

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 01:19 (20 h, 19 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259321
Default Alt Text
D1366.diff (2 KB)

Event Timeline