Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3786994
D1325.id3400.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D1325.id3400.diff
View Options
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
@@ -92,6 +93,18 @@
return $max
}
+#
+# 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
#
diff --git a/Wearg/ServersLog.tcl b/Wearg/ServersLog.tcl
new file mode 100644
--- /dev/null
+++ b/Wearg/ServersLog.tcl
@@ -0,0 +1,90 @@
+package require rest
+
+bind pub - .+log pub:log
+bind dcc - +log dcc:log
+
+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]
+}
+
+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 dcc:log {handle idx arg} {
+ global username network
+
+ #Parse [component] entry
+ if {[regexp "\\\[(.*)\\\] (.*)" $arg match component entry]} {
+ add_to_servers_log $handle "$network $username" $component $entry
+ putdcc $idx Added.
+ return 1
+ } {
+ putdcc $idx "Use the format \[component\] message"
+ return 0
+ }
+}
+
+proc add_to_servers_log {emitter source component entry} {
+ set params "
+ date [iso8601date]
+ emitter $emitter
+ source {$source}
+ component $component
+ entry {$entry}
+ "
+ putdebug $params
+ set request [dict2json $params]
+ putdebug $request
+
+ rest::simple https://api.nasqueron.org/servers-log/ {} {
+ method PUT
+ content-type application/json
+ format json
+ } $request
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 17:29 (18 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2267361
Default Alt Text
D1325.id3400.diff (3 KB)
Attached To
Mode
D1325: Send entries to servers log
Attached
Detach File
Event Timeline
Log In to Comment