Page MenuHomeDevCentral

D2883.id7353.diff
No OneTemporary

D2883.id7353.diff

diff --git a/Daeghrefn/Communication.tcl b/Daeghrefn/Communication.tcl
--- a/Daeghrefn/Communication.tcl
+++ b/Daeghrefn/Communication.tcl
@@ -1,20 +1,7 @@
bind dcc - sms dcc:sms
bind dcc - mail dcc:mail
-bind dcc - twitter dcc:twitter
bind pub - !sms pub:sms
bind pub - !identica pub:identica
-bind pub - !pub pub:twitter
-bind pub - !twit pub:twitter
-bind pub - !tweet pub:twitter
-bind pub - !idee pub:idee
-bind pub - !idees pub:idee
-bind pub - !idée pub:idee
-bind pub - !ideert pub:ideert
-bind pub - !idéert pub:ideert
-bind pub - !idee-rt pub:ideert
-bind pub - !idée-rt pub:ideert
-bind pub - !styleencyclo pub:styleencyclo
-bind pub - !style pub:styleencyclo
#
# SMS
@@ -137,7 +124,7 @@
}
#
-# Identi.ca and Twitter
+# Identi.ca
#
#Posts $message on the identi.ca $account account
@@ -150,242 +137,16 @@
::http::cleanup $tok
}
-#Posts $message on the Twitter $account account
-proc twitterpost {account message} {
- set status_url "https://api.twitter.com/1.1/statuses/update.json"
- if {[catch {twitter_query $status_url $account [list status $message]} error]} {
- putdebug "Twitter error: $error"
- return 0
- }
- return 1
-}
-
-#Gets the Twitter OAuth token
-proc twitter_token {account} {
- registry get twitter.oauth.tokens.$account
-}
-
-proc dcc:twitter {handle idx arg} {
- set command [lindex $arg 0]
- switch $command {
- "setup" {
- set account [lindex $arg 1]
- if {$account == ""} {
- putdcc $idx "What account to setup?"
- return 0
- }
- if {[twitter_token $account] != ""} {
- switch [lindex $arg 2] {
- "--force" { registry del twitter.oauth.tokens.$account }
- "" {
- putdcc $idx "There is already a token set for this account. Please use '.twitter setup $account --force' to erase it."
- return 0
- }
- }
- }
- set pin [lindex $arg 2]
- if {$pin == "" || $pin == "--force"} {
- #Initializes requests
- if {[catch {oauth::get_request_token {*}[registry get twitter.oauth.consumer]} data]} {
- putdebug "Can't request OAuth token for Twitter $account account: $data"
- putdcc $idx "An error occured, I can't request an OAuth token for you account."
- return 0
- } {
- registry set twitter.oauth.tokens.$account "[dict get $data oauth_token] [dict get $data oauth_token_secret]"
- putdcc $idx "Step 1 — Go to [dict get $data auth_url]"
- putdcc $idx "Step 2 — .twitter setup $account <the PIN code>"
- return 1
- }
- } {
- #Saves token
- if {[catch {oauth::get_access_token {*}[registry get twitter.oauth.consumer] {*}[twitter_token $account] $pin} data]} {
- putdebug "Can't confirm OAuth token for Twitter $account account: $data"
- putdcc $idx "An error occured, I can't confirm an OAuth token for you account."
- return 0
- } {
- registry set twitter.oauth.tokens.$account "[dict get $data oauth_token] [dict get $data oauth_token_secret]"
- putdcc $idx "Ok, I've now access to account [dict get $data screen_name]."
- putcmdlog "#$handle# twitter setup $account ..."
- return 0
- }
- }
- }
-
- "reconfigure" {
- twitter_update_short_url_length
- return 1
- }
-
- default { putdcc $idx "Unknown Twitter command: $arg"}
- }
-}
-
-#Sends a query
-proc twitter_query {url account {query_list {}} {method {}}} {
- # Uses POST for any query
- if {$method == ""} {
- if {$query_list == ""} {
- set method GET
- } {
- set method POST
- }
- }
- if {$method == "GET" && $query_list == ""} {
- append url ?
- append url [http::formatQuery {*}$query_list]
- }
-
- # Requests
- set token [twitter_token $account]
- if {$token == ""} {
- error "Unidentified Twitter account: $account"
- } {
- set reply [oauth::query_api $url {*}[registry get twitter.oauth.consumer] $method {*}$token $query_list]
- json::json2dict $reply
- }
-}
-
#.identica
proc dcc:identica {handle idx arg} {
}
-# 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 $account $nick $text
-}
-
-#!ideert
-proc pub:ideert {nick uhost handle chan text} {
- set status ""
- if {[twitter_try_extract_status $text status]} {
- twitter_retweet ideedarticles $status
- return 1
- } {
- return 0
- }
-}
-
#!identica
proc pub:identica {nick uhost handle chan text} {
putquick "NOTICE $nick :!identica is currently disabled. Is identi.ca still usable since pump.io migration? If so, please request the command."
}
-#!pub or !twit or !tweet
-#The account is channel dependant
-proc pub:twitter {nick uhost handle chan text} {
- set account [registry get twitter.channels.$chan.account]
- set is_protected [registry get twitter.channels.$chan.protected]
-
- if {$account == ""} {
- putquick "NOTICE $nick :!pub isn't n'est pas activé sur le canal $chan / !pub isn't enabled on channel $chan"
- return
- }
-
- if {$is_protected == "1"} {
- set who [whois $nick]
- if {$who == ""} {
- putquick "NOTICE $nick :Pour utiliser !pub sur $chan, vous devez disposer d'un cloak projet ou unaffiliated, être connecté depuis un host sans chiffre ou encore avoir votre user@host reconnu par mes soins."
- return 0
- } {
- append text " — $who"
- }
- }
-
- twitterpublish $account $nick $text
-}
-
-proc twitter_message_len {} { return 140 }
-
-proc twitterpublish {account nick text} {
- if {$text == ""} {
- putquick "NOTICE $nick :Syntaxe : !pub <texte à publier sur identi.ca et Twitter>"
- return
- }
- set len [twitter_compute_len $text]
- if {$len > [twitter_message_len]} {
- putquick "NOTICE $nick :[twitter_message_len] caractères max, là il y en a $len ([twitter_get_short_url_length] par lien)."
- return
- }
- if [twitterpost $account $text] {
- putquick "NOTICE $nick :Publié sur Twitter"
- return 1
- } {
- putquick "NOTICE $nick :Non publié, une erreur a eu lieu."
- }
-}
-
-# Extracts the id of the status from an URL or directly from this ID
-#
-# @param text The text containing the status ID
-# @param If successful, will be set to the id of the status to retweet
-# @return 1 if successful; otherwise, 0
-proc twitter_try_extract_status {text status} {
- upvar 1 $status value
-
- # Trivial case: value is already the status identifier
- if {[isnumber $text]} {
- set value $text
- return 1
- }
-
- regexp "twitter\.com/.*/status/(\[0-9\]+)" $text matches value
-}
-
-# Retweets a status
-#
-# @param account The retweeting account username
-# @param status The id of the status to retweet
-# @return The API reply, as a dictionary
-proc twitter_retweet {account status} {
- set url https://api.twitter.com/1.1/statuses/retweet/$status.json
- 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/Daeghrefn/Help.tcl b/Daeghrefn/Help.tcl
--- a/Daeghrefn/Help.tcl
+++ b/Daeghrefn/Help.tcl
@@ -29,7 +29,7 @@
\[ Bureautique ] antidater postdater days paypal quux +db
\[ Channel ] botnet
- \[ Communication ] sms mail twitter
+ \[ Communication ] sms mail
\[ GIS ] fantoir
\[ Server ] phpfpm
\[ Tools ] genpass strlen unixtime
diff --git a/tests/Communication.test b/tests/Communication.test
deleted file mode 100644
--- a/tests/Communication.test
+++ /dev/null
@@ -1,40 +0,0 @@
-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/vendor/oauth.tcl b/vendor/oauth.tcl
deleted file mode 100644
--- a/vendor/oauth.tcl
+++ /dev/null
@@ -1,196 +0,0 @@
-#
-# 0.2 - ???
-# - create base_url correctly for signing (remove ?params=...)
-# - improve error msg if http timeout occurs
-# - remove need to hardcode consumer key/secret by providing them as arguments
-# to the various functions
-#
-# 0.1 - May 18 2010
-# - Initial release
-#
-# by horgh (www.summercat.com)
-#
-# OAuth (1.0/1.0a) library for Twitter
-#
-# Requirements:
-# - Tcl 8.5+ and "recent" tcllib (developed with tcllib 1.12)
-#
-# Setup for users:
-# - Register for consumer key/secret at http://twitter.com/oauth_clients
-#
-# Library usage:
-# - You can store oauth_token/oauth_token_secret from get_access_token[] and
-# use it indefinitely (unless twitter starts expiring the tokens). Thus the
-# setup (below) need only be done once by storing and reusing these.
-#
-# - start with oauth::get_request_token
-# - usage: oauth::get_request_token $consumer_key $consumer_secret
-# - returns dict including oauth_token/oauth_token_secret for https://api.twitter.com/oauth/authorize?oauth_token=OAUTH_TOKEN
-# - going to this url, logging in, and allowing will give a PIN e.g. 1021393
-#
-# - then use pin as value for oauth_verifier in oauth::get_access_token
-# - Usage: oauth::get_access_token $consumer_key $consumer_token $oauth_token $oauth_token_secret $pin
-# - also use oauth_token/oauth_token_secret from get_request_token here
-# - returns dict including new oauth_token & oauth_token_secret (access token)
-#
-# - afterwards use oauth_token/oauth_token_secret from get_access_token in
-# oauth::query_api to make api calls
-# - usage: oauth::query_api $url $consumer_key $consumer_secret $http_method $oauth_token $oauth_token_secret $key:value_http_query
-# - the $key:value_http_query is such that you would pass to http::formatQuery
-# e.g. status {this is a tweet}
-# - example call: puts [oauth::query_api http://api.twitter.com/1/statuses/update.json <key> <secret> POST $oauth_token_done $oauth_token_secret_done [list status "does it work"]]
-#
-
-# tcllib packages
-package require base64
-package require sha1
-
-package provide oauth 0.1
-
-namespace eval oauth {
- variable request_token_url https://api.twitter.com/oauth/request_token
- variable authorize_url https://api.twitter.com/oauth/authorize
- variable access_token_url https://api.twitter.com/oauth/access_token
-
- # timeout for http requests (ms)
- variable timeout 60000
-}
-
-# first step
-proc oauth::get_request_token {consumer_key consumer_secret} {
- set params [list [list oauth_callback oob]]
- set data [oauth::query_call $oauth::request_token_url $consumer_key $consumer_secret GET $params]
-
- # dict has oauth_token, oauth_token_secret, ...
- set result [oauth::params_to_dict $data]
- dict append result auth_url ${oauth::authorize_url}?[http::formatQuery oauth_token [dict get $result oauth_token]]
-
- return $result
-}
-
-# second step
-# for twitter, oauth_verifier is pin
-# oauth_token & oauth_token_secret from get_request_token
-proc oauth::get_access_token {consumer_key consumer_secret oauth_token oauth_token_secret oauth_verifier} {
- set params [list [list oauth_token $oauth_token] [list oauth_verifier $oauth_verifier]]
- set result [oauth::query_call $oauth::access_token_url $consumer_key $consumer_secret POST $params]
-
- # dict has oauth_token, oauth_token_secret (different than before), ...
- return [oauth::params_to_dict $result]
-}
-
-# after first two steps succeed, we now can make api requests to twitter
-# query_dict is POST request to twitter as before, key:value pairing (dict)
-# oauth_token, oauth_token_secret from get_access_token
-proc oauth::query_api {url consumer_key consumer_secret method oauth_token oauth_token_secret query_dict} {
- set params [list [list oauth_token $oauth_token]]
- set result [oauth::query_call $url $consumer_key $consumer_secret $method $params $query_dict $oauth_token_secret]
- return $result
-}
-
-# build header & query, call http request and return result
-# params stay in oauth header
-# sign_params are only used in base string for signing (optional) - dict
-proc oauth::query_call {url consumer_key consumer_secret method params {sign_params {}} {token_secret {}}} {
- set oauth_raw [dict create oauth_nonce [oauth::nonce]]
- dict append oauth_raw oauth_signature_method HMAC-SHA1
- dict append oauth_raw oauth_timestamp [clock seconds]
- dict append oauth_raw oauth_consumer_key $consumer_key
- dict append oauth_raw oauth_version 1.0
-
- # variable number of params
- foreach param $params {
- dict append oauth_raw {*}$param
- }
-
- # second oauth_raw holds data to be signed but not placed in header
- set oauth_raw_sign $oauth_raw
- foreach key [dict keys $sign_params] {
- dict append oauth_raw_sign $key [dict get $sign_params $key]
- }
-
- set signature [oauth::signature $url $consumer_secret $method $oauth_raw_sign $token_secret]
- dict append oauth_raw oauth_signature $signature
-
- set oauth_header [oauth::oauth_header $oauth_raw]
- set oauth_query [oauth::uri_escape $sign_params]
-
- return [oauth::query $url $method $oauth_header $oauth_query]
-}
-
-# do http request with oauth header
-proc oauth::query {url method oauth_header {query {}}} {
- set header [list Authorization [concat "OAuth" $oauth_header]]
- if {$method != "GET"} {
- set token [http::geturl $url -headers $header -query $query -method $method -timeout $oauth::timeout]
- } else {
- set token [http::geturl $url -headers $header -method $method -timeout $oauth::timeout]
- }
- set data [http::data $token]
- set ncode [http::ncode $token]
- set status [http::status $token]
- http::cleanup $token
- if {$status == "reset"} {
- error "OAuth failure: HTTP timeout"
- }
- if {$ncode != 200} {
- error "OAuth failure: (code: $ncode) $data"
- }
- return $data
-}
-
-# take a dict of params and create as follows:
-# create string as: key="value",...,key2="value2"
-proc oauth::oauth_header {params} {
- set header []
- foreach key [dict keys $params] {
- set header "${header}[oauth::uri_escape $key]=\"[oauth::uri_escape [dict get $params $key]]\","
- }
- return [string trimright $header ","]
-}
-
-# take dict of params and create as follows
-# sort params by key
-# create string as key=value&key2=value2...
-# TODO: if key matches, sort by value
-proc oauth::params_signature {params} {
- set str []
- foreach key [lsort [dict keys $params]] {
- set str ${str}[oauth::uri_escape [list $key [dict get $params $key]]]&
- }
- return [string trimright $str &]
-}
-
-# build signature as in section 9 of oauth spec
-# token_secret may be empty
-proc oauth::signature {url consumer_secret method params {token_secret {}}} {
- # We want base URL for signing (remove ?params=...)
- set url [lindex [split $url "?"] 0]
- set base_string [oauth::uri_escape ${method}]&[oauth::uri_escape ${url}]&[oauth::uri_escape [oauth::params_signature $params]]
- set key [oauth::uri_escape $consumer_secret]&[oauth::uri_escape $token_secret]
- set signature [sha1::hmac -bin -key $key $base_string]
- return [base64::encode $signature]
-}
-
-proc oauth::nonce {} {
- set nonce [clock milliseconds][expr [tcl::mathfunc::rand] * 10000]
- return [sha1::sha1 $nonce]
-}
-
-# wrapper around http::formatQuery which uppercases octet characters
-proc oauth::uri_escape {str} {
- set str [http::formatQuery {*}$str]
- # uppercase all %hex where hex=2 octets
- set str [regsub -all -- {%(\w{2})} $str {%[string toupper \1]}]
- return [subst $str]
-}
-
-# convert replies from http query into dict
-# params of form key=value&key2=value2
-proc oauth::params_to_dict {params} {
- set answer []
- foreach pair [split $params &] {
- dict set answer {*}[split $pair =]
- }
- return $answer
-}

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 19, 06:01 (20 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2251870
Default Alt Text
D2883.id7353.diff (16 KB)

Event Timeline