Actual fix for unicode not showing up correctly from xkcd
This commit is contained in:
		| @@ -40,10 +40,10 @@ function xkcd:action(msg, config) | ||||
|     else | ||||
|         local data = JSON.decode(jstr) | ||||
|         local output = string.format('*%s (*[%s](%s)*)*\n_%s_', | ||||
|             data.safe_title:gsub('*', '*\\**'), | ||||
|             utilities.fix_UTF8(data.safe_title):gsub('*', '*\\**'), | ||||
|             data.num, | ||||
|             data.img, | ||||
|             data.alt:gsub('_', '_\\__') | ||||
|             utilities.fix_UTF8(data.alt):gsub('_', '_\\__') | ||||
|         ) | ||||
|         utilities.send_message(msg.chat.id, output, false, nil, true) | ||||
|     end | ||||
|   | ||||
| @@ -321,4 +321,15 @@ utilities.style.enquote = function(title, body) | ||||
|     return '*' .. title:gsub('*', '\\*') .. ':*\n"' .. utilities.md_escape(body) .. '"' | ||||
| end | ||||
|  | ||||
| -- Converts a string back into "proper" utf-8 from an ascii representation of utf-8 | ||||
| -- it is only useful for fixing improper encoding caused by bad JSON escaping | ||||
| function utilities.fix_UTF8(str) | ||||
| 	local t = {} | ||||
| 	for p, c in utf8.codes(str) do | ||||
| 		table.insert(t, string.char(c)) | ||||
| 	end | ||||
| 	return table.concat(t) | ||||
| end | ||||
|  | ||||
|  | ||||
| return utilities | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 EyeZiS
					EyeZiS