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
return1
}{
return0
}
}
#!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."
return0
}{
append text " — $who"
}
}
twitterpublish$account$nick$text
}
proc twitter_message_len {}{return140}
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"
return1
}{
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}{
upvar1$status value
# Trivial case: value is already the status identifier
if{[isnumber$text]}{
set value $text
return1
}
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]