Page MenuHomeDevCentral

D1325.diff
No OneTemporary

D1325.diff

diff --git a/Core.tcl b/Core.tcl
--- a/Core.tcl
+++ b/Core.tcl
@@ -1,5 +1,6 @@
package require http
package require tls
+package require json::write
#
# HTTP support
@@ -93,6 +94,18 @@
}
#
+# Date and time procs
+#
+
+proc iso8601date {{clockval ""}} {
+ if {$clockval == {}} {
+ set clockval [clock seconds]
+ }
+
+ clock format $clockval -format %Y-%m-%dT%H:%M:%S%z
+}
+
+#
# Trivial procs
#
@@ -166,6 +179,12 @@
}
}
+proc dict2json {dictToEncode} {
+ ::json::write object {*}[dict map {k v} $dictToEncode {
+ set v [::json::write string $v]
+ }]
+}
+
#
# Strings
#
@@ -880,3 +899,40 @@
return $host
}
+
+###
+### Send messages
+###
+### This system allows to offer more easily dual commands available in partyline
+### and on a channel. An example implementation is in Wearg/ServersLog.tcl.
+###
+
+proc putbymode {callback message} {
+ if {[llength $callback] != 2} {
+ error "Callback must be a list of two elements: the mode and the target."
+ }
+
+ foreach "mode target" $callback {}
+ switch -- $mode {
+ "dcc" {
+ putdcc $target $message
+ }
+
+ "chan" {
+ if {[llength $target] != 2} {
+ error "Target for chan mode must be a list of two elements: the channel and the nick."
+ }
+
+ foreach "chan nick" $target {}
+ putserv "PRIVMSG $chan :$nick, $message"
+ }
+
+ default {
+ error "Unknown mode: $mode"
+ }
+ }
+}
+
+proc get_putbymode_chan_callback {chan nick} {
+ list chan [list $chan $nick]
+}
diff --git a/Wearg/Notifications.tcl b/Wearg/Notifications.tcl
--- a/Wearg/Notifications.tcl
+++ b/Wearg/Notifications.tcl
@@ -162,7 +162,7 @@
set message $text
if {$link != ""} {
- append message " — $link"
+ append message " - $link"
}
putquick "PRIVMSG $channel :$message"
diff --git a/Wearg/ServersLog.tcl b/Wearg/ServersLog.tcl
new file mode 100644
--- /dev/null
+++ b/Wearg/ServersLog.tcl
@@ -0,0 +1,43 @@
+package require rest
+
+bind pub - .+log pub:log
+bind dcc - +log dcc:log
+
+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
+}
+
+proc dcc:log {handle idx arg} {
+ global username
+ handle_send_to_servers_log $handle $username $arg "dcc $idx"
+}
+
+proc handle_send_to_servers_log {emitter source arg callback} {
+ global network
+
+ #Parse [component] entry
+ if {[regexp "\\\[(.*)\\\] (.*)" $arg match component entry]} {
+ add_to_servers_log $emitter "$network $source" $component $entry
+ return 1
+ } {
+ putbymode $callback "use the format \[component\] message"
+ return 0
+ }
+}
+
+proc add_to_servers_log {emitter source component entry} {
+ set request [dict2json "
+ date [iso8601date]
+ emitter $emitter
+ source {$source}
+ component $component
+ entry {$entry}
+ "]
+
+ rest::simple https://api.nasqueron.org/servers-log/ {} {
+ method PUT
+ content-type application/json
+ format json
+ } $request
+}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 00:46 (19 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259288
Default Alt Text
D1325.diff (3 KB)

Event Timeline