reddit.lua: Stelle auf HTML um & Link zum Reddit hinzugefügt

Der Code ist wie ich: Dreckig ( ͡° ͜ʖ ͡°)
This commit is contained in:
Akamaru 2017-02-19 21:25:23 +01:00
parent cf2a7ca85b
commit ef96dd1969

View File

@ -15,14 +15,14 @@ local format_results = function(posts)
local title = post.title:gsub('%[', '('):gsub('%]', ')'):gsub('&', '&') local title = post.title:gsub('%[', '('):gsub('%]', ')'):gsub('&', '&')
if title:len() > 256 then if title:len() > 256 then
title = title:sub(1, 253) title = title:sub(1, 253)
title = utilities.trim(title) .. '...' title = utilities.trim(title)..'...'
end end
local short_url = 'https://redd.it/' .. post.id local short_url = 'https://redd.it/'..post.id
local s = '[' .. unescape(title) .. '](' .. short_url .. ')' local s = '<a href="'..short_url..'">'..unescape(title)..'</a>'
if post.domain and not post.is_self and not post.over_18 then if post.domain and not post.is_self and not post.over_18 then
s = '`[`[' .. post.domain .. '](' .. post.url:gsub('%)', '\\)') .. ')`]` ' .. s s = '[<a href="'..post.url:gsub('%)', '\\)')..'">'..post.domain..'</a>] '..s
end end
output = output .. '' .. s .. '\n' output = output..''..s..'\n'
end end
return output return output
end end
@ -47,17 +47,17 @@ function reddit:action(msg, config)
if input then if input then
if input:match('^r/.') then if input:match('^r/.') then
input = utilities.get_word(input, 1) input = utilities.get_word(input, 1)
url = reddit.subreddit_url:format(input) .. limit url = reddit.subreddit_url:format(input)..limit
source = '*/' .. utilities.md_escape(input) .. '*\n' source = '<b>/'..utilities.md_escape(input)..'</b>\n'
else else
input = utilities.input(msg.text) input = utilities.input(msg.text)
source = '*Ergebnisse für* _' .. utilities.md_escape(input) .. '_ *:*\n' source = '<b>Ergebnisse für</b> <i>'..utilities.md_escape(input)..'</i> <b>:</b>\n'
input = URL.escape(input) input = URL.escape(input)
url = reddit.search_url:format(input) .. limit url = reddit.search_url:format(input)..limit
end end
else else
url = reddit.rall_url .. limit url = reddit.rall_url..limit
source = '*/r/all*\n' source = '<b>/r/all</b>\n'
end end
local jstr, res = https.request(url) local jstr, res = https.request(url)
if res ~= 200 then if res ~= 200 then
@ -68,10 +68,11 @@ function reddit:action(msg, config)
utilities.send_reply(msg, config.errors.results) utilities.send_reply(msg, config.errors.results)
else else
local output = format_results(jdat.data.children) local output = format_results(jdat.data.children)
output = source .. output local redd_link = source:gsub('</?b>', '')
utilities.send_message(msg.chat.id, output, true, nil, true) output = source..output..'<a href="https://reddit.com'..redd_link..'">Mehr auf Reddit ansehen.</a>'
utilities.send_reply(msg, output, 'HTML')
end end
end end
end end
return reddit return reddit