final changes to xkcd

This commit is contained in:
topkecleon 2016-09-04 17:11:43 -04:00
parent 6899417fb8
commit fa3e6d449f
2 changed files with 10 additions and 13 deletions

View File

@ -39,13 +39,14 @@ function xkcd:action(msg, config)
utilities.send_reply(msg, config.errors.connection) utilities.send_reply(msg, config.errors.connection)
else else
local data = JSON.decode(jstr) local data = JSON.decode(jstr)
local output = string.format('*%s (*[%s](%s)*)*\n_%s_', local output = string.format(
utilities.fix_UTF8(data.safe_title):gsub('*', '*\\**'), '<b>%s</b> (<a href="%s">%s</a>)\n<i>%s</i>',
utilities.html_escape(utilities.fix_utf8(data.safe_title)),
utilities.html_escape(data.img),
data.num, data.num,
data.img, utilities.html_escape(utilities.fix_utf8(data.alt))
utilities.fix_UTF8(data.alt):gsub('_', '_\\__')
) )
utilities.send_message(msg.chat.id, output, false, nil, true) utilities.send_message(msg.chat.id, output, false, nil, 'html')
end end
end end

View File

@ -321,14 +321,10 @@ utilities.style.enquote = function(title, body)
return '*' .. title:gsub('*', '\\*') .. ':*\n"' .. utilities.md_escape(body) .. '"' return '*' .. title:gsub('*', '\\*') .. ':*\n"' .. utilities.md_escape(body) .. '"'
end end
-- Converts a string back into "proper" utf-8 from an ascii representation of utf-8 -- Converts a gross string back into proper UTF-8.
-- it is only useful for fixing improper encoding caused by bad JSON escaping -- Useful for fixing improper encoding caused by bad JSON escaping.
function utilities.fix_UTF8(str) function utilities.fix_utf8(str)
local t = {} return string.char(utf8.codepoint(str, 1, -1))
for p, c in utf8.codes(str) do
table.insert(t, string.char(c))
end
return table.concat(t)
end end