twitter.lua: Sende Tweetlink mit (für twet.lua eig)

tweet.lua: Übersetzung
rss.lua: cleanRSS
This commit is contained in:
Akamaru 2016-10-12 19:26:05 +02:00
parent d43232777e
commit a04abbcc50
3 changed files with 18 additions and 16 deletions

View File

@ -68,6 +68,7 @@ function cleanRSS(str)
str = string.gsub(str, '%[swr%]', '') str = string.gsub(str, '%[swr%]', '')
str = string.gsub(str, '%[ndr%]', '') str = string.gsub(str, '%[ndr%]', '')
str = string.gsub(str, '%[mdr%]', '') str = string.gsub(str, '%[mdr%]', '')
str = string.gsub(str, '%[rbb%]', '')
str = string.gsub(str, '%[wdr%]', '') str = string.gsub(str, '%[wdr%]', '')
str = string.gsub(str, '%[hr%]', '') str = string.gsub(str, '%[hr%]', '')
str = string.gsub(str, '%[br%]', '') str = string.gsub(str, '%[br%]', '')

View File

@ -6,26 +6,26 @@ tweet.command = 'tweet <Name>'
function tweet:init(config) function tweet:init(config)
if not cred_data.tw_consumer_key then if not cred_data.tw_consumer_key then
print('Missing config value: tw_consumer_key.') print('Fehlender Key: tw_consumer_key.')
print('tweet.lua will not be enabled.') print('tweet.lua wird nicht aktiviert.')
return return
elseif not cred_data.tw_consumer_secret then elseif not cred_data.tw_consumer_secret then
print('Missing config value: tw_consumer_secret.') print('Fehlender Key: tw_consumer_secret.')
print('tweet.lua will not be enabled.') print('tweet.lua wird nicht aktiviert.')
return return
elseif not cred_data.tw_access_token then elseif not cred_data.tw_access_token then
print('Missing config value: tw_access_token.') print('Fehlender Key: tw_access_token.')
print('tweet.lua will not be enabled.') print('tweet.lua wird nicht aktiviert.')
return return
elseif not cred_data.tw_access_token_secret then elseif not cred_data.tw_access_token_secret then
print('Missing config value: tw_access_token_secret.') print('Fehlender Key: tw_access_token_secret.')
print('tweet.lua will not be enabled.') print('tweet.lua wird nicht aktiviert.')
return return
end end
tweet.triggers = { tweet.triggers = {
"^/tweet ([%w_%.%-]+)$", "^/[Tt][Ww][Ee][Ee][Tt] ([%w_%.%-]+)$",
"^/tweet ([%w_%.%-]+) (last)$" "^/[Tt][Ww][Ee][Ee][Tt] ([%w_%.%-]+) (last)$"
} }
tweet.doc = [[* tweet.doc = [[*
]]..config.cmd_pat..[[tweet* _<Name>_: Zufälliger Tweet vom User mit diesem Namen ]]..config.cmd_pat..[[tweet* _<Name>_: Zufälliger Tweet vom User mit diesem Namen
@ -51,12 +51,12 @@ local client = OAuth.new(consumer_key, consumer_secret, {
function tweet:get_random_tweet(base) function tweet:get_random_tweet(base)
local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url, base) local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url, base)
if response_code ~= 200 then if response_code ~= 200 then
return "Konnte nicht verbinden, evtl. existiert der User nicht?" return "Konnte nicht verbinden. Evtl. existiert der User nicht?"
end end
local response = json.decode(response_body) local response = json.decode(response_body)
if #response == 0 then if #response == 0 then
return "Konnte keinen Tweet bekommen, sorry" return "Konnte keinen Tweet bekommen."
end end
local i = math.random(#response) local i = math.random(#response)

View File

@ -50,6 +50,7 @@ function get_tweet(response)
end end
local header = '<b>Tweet von '..full_name..'</b> (<a href="https://twitter.com/'..user_name..'">@' ..user_name..'</a>'..verified..'):' local header = '<b>Tweet von '..full_name..'</b> (<a href="https://twitter.com/'..user_name..'">@' ..user_name..'</a>'..verified..'):'
local text = response.full_text local text = response.full_text
local tweet_link = '\n<a href= "https://twitter.com/statuses/'..response.id_str..'">Tweet aufrufen</a>'
-- favorites & retweets -- favorites & retweets
if response.retweet_count == 0 then if response.retweet_count == 0 then
@ -63,11 +64,11 @@ function get_tweet(response)
favorites = response.favorite_count..'x favorisiert' favorites = response.favorite_count..'x favorisiert'
end end
if retweets == "" and favorites ~= "" then if retweets == "" and favorites ~= "" then
footer = '<i>'..favorites..'</i>' footer = '\n<i>'..favorites..'</i>'
elseif retweets ~= "" and favorites == "" then elseif retweets ~= "" and favorites == "" then
footer = '<i>'..retweets..'</i>' footer = '\n<i>'..retweets..'</i>'
elseif retweets ~= "" and favorites ~= "" then elseif retweets ~= "" and favorites ~= "" then
footer = '<i>'..retweets..' - '..favorites..'</i>' footer = '\n<i>'..retweets..' - '..favorites..'</i>'
else else
footer = "" footer = ""
end end
@ -138,7 +139,7 @@ function get_tweet(response)
text = text..'\n\n'..quote..'\n' text = text..'\n\n'..quote..'\n'
end end
return header.."\n"..utilities.trim(text).."\n"..footer, images, videos return header.."\n"..utilities.trim(text)..footer..tweet_link, images, videos
end end
function twitter:action(msg, config, matches) function twitter:action(msg, config, matches)