- # By user@host, when the host doesn't contain any digit
- if {[regexp {^[^0-9]*$} $host]} {
- return "$nickname!$uhost"
- }
-
- # Can't identify
- return ""
-}
-
#!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