Changeset View
Changeset View
Standalone View
Standalone View
Daeghrefn/Communication.tcl
Show First 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | "setup" { | ||||
registry set twitter.oauth.tokens.$account "[dict get $data oauth_token] [dict get $data oauth_token_secret]" | 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]." | putdcc $idx "Ok, I've now access to account [dict get $data screen_name]." | ||||
putcmdlog "#$handle# twitter setup $account ..." | putcmdlog "#$handle# twitter setup $account ..." | ||||
return 0 | return 0 | ||||
} | } | ||||
} | } | ||||
} | } | ||||
"reconfigure" { | |||||
twitter_update_short_url_length | |||||
return 1 | |||||
} | |||||
default { putdcc $idx "Unknown Twitter command: $arg"} | default { putdcc $idx "Unknown Twitter command: $arg"} | ||||
} | } | ||||
} | } | ||||
#Sends a query | #Sends a query | ||||
proc twitter_query {url account {query_list {}} {method {}}} { | proc twitter_query {url account {query_list {}} {method {}}} { | ||||
# Uses POST for any query | # Uses POST for any query | ||||
if {$method == ""} { | if {$method == ""} { | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | proc pub:twitter {nick uhost handle chan text} { | ||||
twitterpublish $account $nick $text | twitterpublish $account $nick $text | ||||
} | } | ||||
proc twitterpublish {account nick text} { | proc twitterpublish {account nick text} { | ||||
if {$text == ""} { | if {$text == ""} { | ||||
putquick "NOTICE $nick :Syntaxe : !pub <texte à publier sur identi.ca et Twitter>" | putquick "NOTICE $nick :Syntaxe : !pub <texte à publier sur identi.ca et Twitter>" | ||||
return | return | ||||
} | } | ||||
set len [string length $text] | set len [twitter_compute_len $text] | ||||
if {$len > 140} { | 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 | return | ||||
} | } | ||||
if [twitterpost $account $text] { | if [twitterpost $account $text] { | ||||
putquick "NOTICE $nick :Publié sur Twitter" | putquick "NOTICE $nick :Publié sur Twitter" | ||||
return 1 | return 1 | ||||
} { | } { | ||||
putquick "NOTICE $nick :Non publié, une erreur a eu lieu." | putquick "NOTICE $nick :Non publié, une erreur a eu lieu." | ||||
} | } | ||||
Show All 21 Lines | |||||
# @param account The retweeting account username | # @param account The retweeting account username | ||||
# @param status The id of the status to retweet | # @param status The id of the status to retweet | ||||
# @return The API reply, as a dictionary | # @return The API reply, as a dictionary | ||||
proc twitter_retweet {account status} { | proc twitter_retweet {account status} { | ||||
set url https://api.twitter.com/1.1/statuses/retweet/$status.json | set url https://api.twitter.com/1.1/statuses/retweet/$status.json | ||||
twitter_query $url $account "" POST | 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 | |||||
dereckson: tweet | |||||
# 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 | |||||
} | |||||
# | # | ||||
# | # | ||||
proc dcc:mail {handle idx arg} { | proc dcc:mail {handle idx arg} { | ||||
global mail special | global mail special | ||||
if {$arg == ""} { | if {$arg == ""} { | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |
Nasqueron DevCentral · If it had been much bigger the moon would have had a core of ice. · Powered by Phabricator
tweet