Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3715875
D1325.id3401.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.id3401.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
#
@@ -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/ServersLog.tcl b/Wearg/ServersLog.tcl
new file mode 100644
--- /dev/null
+++ b/Wearg/ServersLog.tcl
@@ -0,0 +1,60 @@
+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 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 6, 10:36 (22 h, 34 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2231649
Default Alt Text
D1325.id3401.diff (3 KB)
Attached To
Mode
D1325: Send entries to servers log
Attached
Detach File
Event Timeline
Log In to Comment