From 8ad9b2aa7880826421e703c050d275194de27de1 Mon Sep 17 00:00:00 2001 From: topkecleon Date: Sun, 4 Sep 2016 14:49:43 -0400 Subject: [PATCH 1/3] final script changes --- README.md | 2 +- install-dependencies.sh | 11 +++++++---- tg-install.sh | 4 +++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 3067d48..29af4a6 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ This section includes an exhaustive list of possible configuration values for ot | `log_chat` | nil | Telegram ID of the recipient for error messages. | | `cmd_pat` | `"/"` | Character (or string) to be used for bot commands. | | `lang` | `"en"` | Two-letter ISO 639-1 language code. | -| `about_text` | ... | Informational text to be returned by /about. | +| `about_text` | ... | Informational text to be returned by /about. | #### Error messages These are the generic error messages used by most plugins. These belong in a table named `errors`. diff --git a/install-dependencies.sh b/install-dependencies.sh index a8d4e50..4c6924d 100755 --- a/install-dependencies.sh +++ b/install-dependencies.sh @@ -4,16 +4,18 @@ #!/bin/sh -echo "This script is intended for Ubuntu 16.04 and later. It will not work in 14.04 or earlier." +echo "This script is intended for Ubuntu 16.04 and later. It will not work in" +echo "14.04 or earlier." echo "This script will request root privileges to install the following packages:" -echo "lua5.3 liblua5.3-dev git libssl-dev fortune-mod fortunes" -echo "It will also request root privileges to install Luarocks to to /usr/local/ along with the following rocks:" +echo "lua5.3 liblua5.3-dev git libssl-dev fortune-mod fortunes unzip" +echo "It will also request root privileges to install Luarocks to to /usr/local/" +echo "along with the following rocks:" echo "luasocket luasec multipart-post lpeg dkjson" echo "Press enter to continue. Use Ctrl-C to exit." read sudo apt-get update -sudo apt-get install -y lua5.3 liblua5.3-dev git libssl-dev fortune-mod fortunes +sudo apt-get install -y lua5.3 liblua5.3-dev git libssl-dev fortune-mod fortunes unzip git clone http://github.com/keplerproject/luarocks cd luarocks ./configure --lua-version=5.3 --versioned-rocks-dir --lua-suffix=5.3 @@ -24,6 +26,7 @@ sudo luarocks-5.3 install luasec sudo luarocks-5.3 install multipart-post sudo luarocks-5.3 install lpeg sudo luarocks-5.3 install dkjson +sudo -k cd .. echo "Finished. Use ./launch to start otouto." diff --git a/tg-install.sh b/tg-install.sh index c53c328..1b6ea6c 100755 --- a/tg-install.sh +++ b/tg-install.sh @@ -2,7 +2,8 @@ #!/bin/sh -echo "This script is intended for Ubuntu 16.04 and later. It will probably work on 14.04 or 12.04 as well as Debian, but this is not guaranteed." +echo "This script is intended for Ubuntu 16.04 and later. It will probably work on" +echo "14.04 or 12.04 as well as Debian, but this is not guaranteed." echo "This script will request root privileges to install the following packages:" echo "git libreadline-dev libssl-dev libevent-dev make" echo "Press enter to continue. Use Ctrl-C to exit." @@ -10,6 +11,7 @@ read sudo apt-get update sudo apt-get install -y git libreadline-dev libssl-dev libevent-dev make +sudo -k git clone http://github.com/vysheng/tg --recursive -b test cd tg ./configure --disable-libconfig --disable-liblua --disable-json From e4f42bacc3b6b5180679cdb44f3efcd881c8a2fd Mon Sep 17 00:00:00 2001 From: EyeZiS Date: Sun, 4 Sep 2016 21:04:45 +0200 Subject: [PATCH 2/3] Actual fix for unicode not showing up correctly from xkcd --- otouto/plugins/xkcd.lua | 4 ++-- otouto/utilities.lua | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/otouto/plugins/xkcd.lua b/otouto/plugins/xkcd.lua index 4e54572..b75ba78 100644 --- a/otouto/plugins/xkcd.lua +++ b/otouto/plugins/xkcd.lua @@ -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 diff --git a/otouto/utilities.lua b/otouto/utilities.lua index 47e6def..1e89a9c 100644 --- a/otouto/utilities.lua +++ b/otouto/utilities.lua @@ -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 From fa3e6d449f3a4f34c74583996ac1c124d1a6507b Mon Sep 17 00:00:00 2001 From: topkecleon Date: Sun, 4 Sep 2016 17:11:43 -0400 Subject: [PATCH 3/3] final changes to xkcd --- otouto/plugins/xkcd.lua | 11 ++++++----- otouto/utilities.lua | 12 ++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/otouto/plugins/xkcd.lua b/otouto/plugins/xkcd.lua index b75ba78..e5d27e5 100644 --- a/otouto/plugins/xkcd.lua +++ b/otouto/plugins/xkcd.lua @@ -39,13 +39,14 @@ function xkcd:action(msg, config) utilities.send_reply(msg, config.errors.connection) else local data = JSON.decode(jstr) - local output = string.format('*%s (*[%s](%s)*)*\n_%s_', - utilities.fix_UTF8(data.safe_title):gsub('*', '*\\**'), + local output = string.format( + '%s (%s)\n%s', + utilities.html_escape(utilities.fix_utf8(data.safe_title)), + utilities.html_escape(data.img), data.num, - data.img, - utilities.fix_UTF8(data.alt):gsub('_', '_\\__') + utilities.html_escape(utilities.fix_utf8(data.alt)) ) - utilities.send_message(msg.chat.id, output, false, nil, true) + utilities.send_message(msg.chat.id, output, false, nil, 'html') end end diff --git a/otouto/utilities.lua b/otouto/utilities.lua index 1e89a9c..8461ffc 100644 --- a/otouto/utilities.lua +++ b/otouto/utilities.lua @@ -321,14 +321,10 @@ 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) + -- Converts a gross string back into proper UTF-8. + -- Useful for fixing improper encoding caused by bad JSON escaping. +function utilities.fix_utf8(str) + return string.char(utf8.codepoint(str, 1, -1)) end