Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3764952
D829.id2101.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
D829.id2101.diff
View Options
diff --git a/Daeghrefn/Communication.tcl b/Daeghrefn/Communication.tcl
--- a/Daeghrefn/Communication.tcl
+++ b/Daeghrefn/Communication.tcl
@@ -13,6 +13,8 @@
bind pub - !idéert pub:ideert
bind pub - !idee-rt pub:ideert
bind pub - !idée-rt pub:ideert
+bind pub - !styleencyclo pub:styleencylo
+bind pub - !style pub:styleencylo
#
# SMS
@@ -209,6 +211,11 @@
}
}
+ "reconfigure" {
+ twitter_update_short_url_length
+ return 1
+ }
+
default { putdcc $idx "Unknown Twitter command: $arg"}
}
}
@@ -243,15 +250,23 @@
}
-#!idee
+# Publishes to special accounts
proc pub:idee {nick uhost handle chan text} {
+ twitter_pub_publish_to_account ideedarticles $nick $text
+}
+
+proc pub:styleencyclo {nick uhost handle chan text} {
+ twitter_pub_publish_to_account styleencyclo $nick $text
+}
+
+proc twitter_pub_publish_to_account {account nick text}
set who [whois $nick]
if {$who == ""} {
append text " – via IRC."
} {
append text " – $who, via IRC."
}
- twitterpublish ideedarticles $nick $text
+ twitterpublish $account $nick $text
}
#!ideert
@@ -336,9 +351,9 @@
putquick "NOTICE $nick :Syntaxe : !pub <texte à publier sur identi.ca et Twitter>"
return
}
- set len [string length $text]
+ set len [twitter_compute_len $text]
if {$len > 140} {
- putquick "NOTICE $nick :140 caractères max, là il y en a $len."
+ putquick "NOTICE $nick :140 caractères max, là il y en a $len ([twitter_get_short_url_length] par lien)."
return
}
if [twitterpost $account $text] {
@@ -376,6 +391,36 @@
twitter_query $url $account "" POST
}
+# @param param The parameter to fetch in the API reply
+# return The value from configuration the JSON document, or a dict if it contains several parameters
+proc twitter_get_configuration_parameter {param} {
+ set account [registry get twitter.default_account]
+ set url https://api.twitter.com/1.1/help/configuration.json
+ set config [twitter_query $url $account]
+ dict get $config $param
+}
+
+proc twitter_update_short_url_length {} {
+ set len [twitter_get_configuration_parameter short_url_length]
+ registry set twitter.short_url_length $len
+}
+
+proc twitter_get_short_url_length {} {
+ registry get twitter.short_url_length
+}
+
+# Computes len of a tweet, taking in consideration t.co URL length
+# See https://dev.twitter.com/basics/tco
+proc twitter_compute_len {text} {
+ set short_url_length [twitter_get_short_url_length]
+
+ set len [strlen $text]
+ foreach url [geturls $text] {
+ incr len [expr $short_url_length - [strlen $url]]
+ }
+ return $len
+}
+
#
# Mail
#
diff --git a/tests/Communication.test b/tests/Communication.test
new file mode 100644
--- /dev/null
+++ b/tests/Communication.test
@@ -0,0 +1,40 @@
+package require tcltest
+namespace import ::tcltest::*
+
+###
+### Init
+###
+
+# Tested code
+source init.tcl
+source $dir/Daeghrefn/Communication.tcl
+
+###
+### Mocks
+###
+
+# This value is normally given by a cached value in the registry
+# and updated through an API call to /help/configuration.json.
+proc twitter_get_short_url_length {} { return 23 }
+
+###
+### Tests
+###
+
+test twitter_compute_len_empty {} -body {
+ twitter_compute_len ""
+} -result 0
+
+test twitter_compute_len_regular_string {} -body {
+ twitter_compute_len "quux"
+} -result 4
+
+test twitter_compute_len_links {} -body {
+ twitter_compute_len "Je vais sur http://www.perdu.com pour y lire https://fr.wikipedia.org/w/index.php?title=Les_B%C3%A2tards_du_Nord&type=revision&diff=133589772&oldid=133589631"
+} -result 71
+
+###
+### Cleanup
+###
+
+cleanupTests
diff --git a/tests/init.tcl b/tests/init.tcl
--- a/tests/init.tcl
+++ b/tests/init.tcl
@@ -13,3 +13,8 @@
# Standard procedures
source $dir/Core.tcl
+
+# Eggdrop procedures
+proc strlen {text} {
+ string length $text
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 09:29 (13 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2257657
Default Alt Text
D829.id2101.diff (3 KB)
Attached To
Mode
D829: Compute Twitter text of status update length with t.co link wrapping
Attached
Detach File
Event Timeline
Log In to Comment