From 731454382c59d4f88c9f8a33cf6ecf135dddd670 Mon Sep 17 00:00:00 2001 From: Akamaru Date: Thu, 4 Aug 2016 20:37:12 +0200 Subject: [PATCH] Packe "function unescape" in encoding.lua Character encoding extreme! --- miku/encoding.lua | 343 ++++++++++++++++++++++++++++++++++ miku/plugins/app_store.lua | 4 +- miku/plugins/myanimelist.lua | 7 +- miku/plugins/reddit.lua | 4 +- miku/plugins/reddit_post.lua | 6 +- miku/plugins/rss.lua | 13 +- miku/plugins/steam.lua | 4 +- miku/plugins/tweet.lua | 6 +- miku/plugins/twitter_send.lua | 4 +- miku/plugins/twitter_user.lua | 4 +- miku/utilities.lua | 61 ------ 11 files changed, 377 insertions(+), 79 deletions(-) create mode 100644 miku/encoding.lua diff --git a/miku/encoding.lua b/miku/encoding.lua new file mode 100644 index 0000000..7be65d6 --- /dev/null +++ b/miku/encoding.lua @@ -0,0 +1,343 @@ +-- See http://www.ascii.cl/htmlcodes.htm +-- str = string.gsub(str, '', '') + +function encoding(str) + -- Symbols + str = string.gsub(str, ' ', ' ') -- space + str = string.gsub(str, '!', '!') -- exclamation point + str = string.gsub(str, '"', '"') -- double quotes + str = string.gsub(str, '"', '"') -- double quotes + str = string.gsub(str, '#', '#') -- number sign + str = string.gsub(str, '$', '$') -- dollar sign + str = string.gsub(str, '%', '%') -- percent sign + str = string.gsub(str, ''', '\'') -- single quote + str = string.gsub(str, '(', '(') -- opening parenthesis + str = string.gsub(str, ')', ')') -- closing parenthesis + str = string.gsub(str, '*', '*') -- asterisk + str = string.gsub(str, '+', '+') -- plus sign + str = string.gsub(str, ',', ',') -- comma + str = string.gsub(str, '-', '-') -- minus sign - hyphen + str = string.gsub(str, '.', '.') -- period + str = string.gsub(str, '/', '/') -- slash + str = string.gsub(str, ':', ':') -- colon + str = string.gsub(str, ';', ';') -- semicolon + str = string.gsub(str, '<', '<') -- less than sign + str = string.gsub(str, '<', '<') -- less than sign + str = string.gsub(str, '=', '=') -- equal sign + str = string.gsub(str, '>', '>') -- greater than sign + str = string.gsub(str, '>', '>') -- greater than sign + str = string.gsub(str, '?', '?') -- question mark + str = string.gsub(str, '@', '@') -- at symbol + str = string.gsub(str, '[', '[') -- opening bracket + str = string.gsub(str, '\', '\\') -- backslash + str = string.gsub(str, ']', ']') -- closing bracket + str = string.gsub(str, '^', '^') -- caret - circumflex + str = string.gsub(str, '_', '_') -- underscore + str = string.gsub(str, '`', '`') -- grave accent + str = string.gsub(str, '{', '{') -- opening brace + str = string.gsub(str, '|', '|') -- vertical bar + str = string.gsub(str, '}', '}') -- closing brace + str = string.gsub(str, '~', '~') -- equivalency sign - tilde + str = string.gsub(str, ' ', ' ') -- non-breaking space + str = string.gsub(str, ' ', ' ') -- non-breaking space + str = string.gsub(str, '¡', '¡') -- inverted exclamation mark + str = string.gsub(str, '¡', '¡') -- inverted exclamation mark + str = string.gsub(str, '¢', '¢') -- cent sign + str = string.gsub(str, '¢', '¢') -- cent sign + str = string.gsub(str, '£', '£') -- pound sign + str = string.gsub(str, '£', '£') -- pound sign + str = string.gsub(str, '¤', '¤') -- currency sign + str = string.gsub(str, '¤', '¤') -- currency sign + str = string.gsub(str, '¥', '¥') -- yen sign + str = string.gsub(str, '¥', '¥') -- yen sign + str = string.gsub(str, '¦', '¦') -- broken vertical bar + str = string.gsub(str, '¦', '¦') -- broken vertical bar + str = string.gsub(str, '§', '§') -- section sign + str = string.gsub(str, '§', '§') -- section sign + str = string.gsub(str, '¨', '¨') -- spacing diaeresis - umlaut + str = string.gsub(str, '¨', '¨') -- spacing diaeresis - umlaut + str = string.gsub(str, '©', '©') -- copyright sign + str = string.gsub(str, '©', '©') -- copyright sign + str = string.gsub(str, 'ª', 'ª') -- feminine ordinal indicator + str = string.gsub(str, 'ª', 'ª') -- feminine ordinal indicator + str = string.gsub(str, '«', '«') -- left double angle quotes + str = string.gsub(str, '«', '«') -- left double angle quotes + str = string.gsub(str, '¬', '¬') -- not sign + str = string.gsub(str, '¬', '¬') -- not sign + str = string.gsub(str, '­', '') -- soft hyphen + str = string.gsub(str, '­', '') -- soft hyphen + str = string.gsub(str, '®', '®') -- registered trade mark sign + str = string.gsub(str, '®', '®') -- registered trade mark sign + str = string.gsub(str, '¯', '¯') -- spacing macron - overline + str = string.gsub(str, '¯', '¯') -- spacing macron - overline + str = string.gsub(str, '°', '°') -- degree sign + str = string.gsub(str, '°', '°') -- degree sign + str = string.gsub(str, '±', '±') -- plus-or-minus sign + str = string.gsub(str, '±', '±') -- plus-or-minus sign + str = string.gsub(str, '²', '²') -- superscript two - squared + str = string.gsub(str, '²', '²') -- superscript two - squared + str = string.gsub(str, '³', '³') -- superscript three - cubed + str = string.gsub(str, '³', '³') -- superscript three - cubed + str = string.gsub(str, '´', '´') -- acute accent - spacing acute + str = string.gsub(str, '´', '´') -- acute accent - spacing acute + str = string.gsub(str, 'µ', 'µ') -- micro sign + str = string.gsub(str, 'µ', 'µ') -- micro sign + str = string.gsub(str, '¶', '¶') -- pilcrow sign - paragraph sign + str = string.gsub(str, '¶', '¶') -- pilcrow sign - paragraph sign + str = string.gsub(str, '·', '·') -- middle dot - Georgian comma + str = string.gsub(str, '·', '·') -- middle dot - Georgian comma + str = string.gsub(str, '¸', '¸') -- spacing cedilla + str = string.gsub(str, '¸', '¸') -- spacing cedilla + str = string.gsub(str, '¹', '¹') -- superscript one + str = string.gsub(str, '¹', '¹') -- superscript one + str = string.gsub(str, 'º', 'º') -- masculine ordinal indicator + str = string.gsub(str, 'º', 'º') -- masculine ordinal indicator + str = string.gsub(str, '»', '»') -- right double angle quotes + str = string.gsub(str, '»', '»') -- right double angle quotes + str = string.gsub(str, '¼', '¼') -- fraction one quarter + str = string.gsub(str, '¼', '¼') -- fraction one quarter + str = string.gsub(str, '½', '½') -- fraction one half + str = string.gsub(str, '½', '½') -- fraction one half + str = string.gsub(str, '¾', '¾') -- fraction three quarters + str = string.gsub(str, '¾', '¾') -- fraction three quarters + str = string.gsub(str, '¿', '¿') -- inverted question mark + str = string.gsub(str, '¿', '¿') -- inverted question mark + str = string.gsub(str, '×', '×') -- multiplication sign + str = string.gsub(str, '×', '×') -- multiplication sign + str = string.gsub(str, '÷', '÷') -- division sign + str = string.gsub(str, '÷', '÷') -- division sign + str = string.gsub(str, '–', '–') -- en dash + str = string.gsub(str, '–', '–') -- en dash + str = string.gsub(str, '—', '—') -- em dash + str = string.gsub(str, '—', '—') -- em dash + str = string.gsub(str, '‘', '‘') -- left single quotation mark + str = string.gsub(str, '‘', '‘') -- left single quotation mark + str = string.gsub(str, '’', '’') -- right single quotation mark + str = string.gsub(str, '’', '’') -- right single quotation mark + str = string.gsub(str, '‚', '‚') -- single low-9 quotation mark + str = string.gsub(str, '‚', '‚') -- single low-9 quotation mark + str = string.gsub(str, '“', '“') -- left double quotation mark + str = string.gsub(str, '“', '“') -- left double quotation mark + str = string.gsub(str, '”', '”') -- right double quotation mark + str = string.gsub(str, '„', '„') -- double low-9 quotation mark + str = string.gsub(str, '„', '„') -- double low-9 quotation mark + str = string.gsub(str, '†', '†') -- dagger + str = string.gsub(str, '‡', '‡') -- double dagger + str = string.gsub(str, '•', '•') -- bullet + str = string.gsub(str, '…', '…') -- horizontal ellipsis + str = string.gsub(str, '‰', '‰') -- per thousand sign + str = string.gsub(str, '⁈', '€') -- euro sign + str = string.gsub(str, '€', '€') -- euro sign + str = string.gsub(str, '⁚', '™') -- trade mark sign + + -- Numbers + str = string.gsub(str, '0', '0') -- zero + str = string.gsub(str, '1', '1') -- one + str = string.gsub(str, '2', '2') -- two + str = string.gsub(str, '3', '3') -- three + str = string.gsub(str, '4', '4') -- four + str = string.gsub(str, '5', '5') -- five + str = string.gsub(str, '6', '6') -- six + str = string.gsub(str, '7', '7') -- seven + str = string.gsub(str, '8', '8') -- eight + str = string.gsub(str, '9', '9') -- nine + + -- Big letters + str = string.gsub(str, 'A', 'A') + str = string.gsub(str, 'B', 'B') + str = string.gsub(str, 'C', 'C') + str = string.gsub(str, 'D', 'D') + str = string.gsub(str, 'E', 'E') + str = string.gsub(str, 'F', 'F') + str = string.gsub(str, 'G', 'G') + str = string.gsub(str, 'H', 'H') + str = string.gsub(str, 'I', 'I') + str = string.gsub(str, 'J', 'J') + str = string.gsub(str, 'K', 'K') + str = string.gsub(str, 'L', 'L') + str = string.gsub(str, 'M', 'M') + str = string.gsub(str, 'N', 'N') + str = string.gsub(str, 'O', 'O') + str = string.gsub(str, 'P', 'P') + str = string.gsub(str, 'Q', 'Q') + str = string.gsub(str, 'R', 'R') + str = string.gsub(str, 'S', 'S') + str = string.gsub(str, 'T', 'T') + str = string.gsub(str, 'U', 'U') + str = string.gsub(str, 'V', 'V') + str = string.gsub(str, 'W', 'W') + str = string.gsub(str, 'X', 'X') + str = string.gsub(str, 'Y', 'Y') + str = string.gsub(str, 'Z', 'Z') + + -- Small letters + str = string.gsub(str, 'a', 'a') + str = string.gsub(str, 'b', 'b') + str = string.gsub(str, 'c', 'c') + str = string.gsub(str, 'd', 'd') + str = string.gsub(str, 'e', 'e') + str = string.gsub(str, 'f', 'f') + str = string.gsub(str, 'g', 'g') + str = string.gsub(str, 'h', 'h') + str = string.gsub(str, 'i', 'i') + str = string.gsub(str, 'j', 'j') + str = string.gsub(str, 'k', 'k') + str = string.gsub(str, 'l', 'l') + str = string.gsub(str, 'm', 'm') + str = string.gsub(str, 'n', 'n') + str = string.gsub(str, 'o', 'o') + str = string.gsub(str, 'p', 'p') + str = string.gsub(str, 'q', 'q') + str = string.gsub(str, 'r', 'r') + str = string.gsub(str, 's', 's') + str = string.gsub(str, 't', 't') + str = string.gsub(str, 'u', 'u') + str = string.gsub(str, 'v', 'v') + str = string.gsub(str, 'w', 'w') + str = string.gsub(str, 'x', 'x') + str = string.gsub(str, 'y', 'y') + str = string.gsub(str, 'z', 'z') + + -- Latin capital letters + str = string.gsub(str, 'À', 'À') -- latin capital letter A with grave + str = string.gsub(str, 'À', 'À') -- latin capital letter A with grave + str = string.gsub(str, 'Á', 'Á') -- latin capital letter A with acute + str = string.gsub(str, 'Á', 'Á') -- latin capital letter A with acute + str = string.gsub(str, 'Â', 'Â') -- latin capital letter A with circumflex + str = string.gsub(str, 'Â', 'Â') -- latin capital letter A with circumflex + str = string.gsub(str, 'Ã', 'Ã') -- latin capital letter A with tilde + str = string.gsub(str, 'Ã', 'Ã') -- latin capital letter A with tilde + str = string.gsub(str, 'Ä', 'Ä') -- latin capital letter A with diaeresis + str = string.gsub(str, 'Ä', 'Ä') -- latin capital letter A with diaeresis + str = string.gsub(str, 'Å', 'Å') -- latin capital letter A with ring above + str = string.gsub(str, 'Å', 'Å') -- latin capital letter A with ring above + str = string.gsub(str, 'Æ', 'Æ') -- latin capital letter AE + str = string.gsub(str, 'Æ', 'Æ') -- latin capital letter AE + str = string.gsub(str, 'Ç', 'Ç') -- latin capital letter C with cedilla + str = string.gsub(str, 'Ç', 'Ç') -- latin capital letter C with cedilla + str = string.gsub(str, 'È', 'È') -- latin capital letter E with grave + str = string.gsub(str, 'È', 'È') -- latin capital letter E with grave + str = string.gsub(str, 'É', 'É') -- latin capital letter E with acute + str = string.gsub(str, 'É', 'É') -- latin capital letter E with acute + str = string.gsub(str, 'Ê', 'Ê') -- latin capital letter E with circumflex + str = string.gsub(str, 'Ê', 'Ê') -- latin capital letter E with circumflex + str = string.gsub(str, 'Ë', 'Ë') -- latin capital letter E with diaeresis + str = string.gsub(str, 'Ë', 'Ë') -- latin capital letter E with diaeresis + str = string.gsub(str, 'Ì', 'Ì') -- latin capital letter I with grave + str = string.gsub(str, 'Ì', 'Ì') -- latin capital letter I with grave + str = string.gsub(str, 'Í', 'Í') -- latin capital letter I with acute + str = string.gsub(str, 'Í', 'Í') -- latin capital letter I with acute + str = string.gsub(str, 'Î', 'Î') -- latin capital letter I with circumflex + str = string.gsub(str, 'Î', 'Î') -- latin capital letter I with circumflex + str = string.gsub(str, 'Ï', 'Ï') -- latin capital letter I with diaeresis + str = string.gsub(str, 'Ï', 'Ï') -- latin capital letter I with diaeresis + str = string.gsub(str, 'Ð', 'Ð') -- latin capital letter ETH + str = string.gsub(str, 'Ð', 'Ð') -- latin capital letter ETH + str = string.gsub(str, 'Ñ', 'Ñ') -- latin capital letter N with tilde + str = string.gsub(str, 'Ñ', 'Ñ') -- latin capital letter N with tilde + str = string.gsub(str, 'Ò', 'Ò') -- latin capital letter O with grave + str = string.gsub(str, 'Ò', 'Ò') -- latin capital letter O with grave + str = string.gsub(str, 'Ó', 'Ó') -- latin capital letter O with acute + str = string.gsub(str, 'Ó', 'Ó') -- latin capital letter O with acute + str = string.gsub(str, 'Ô', 'Ô') -- latin capital letter O with circumflex + str = string.gsub(str, '&Ocrc;', 'Ô') -- latin capital letter O with circumflex + str = string.gsub(str, 'Õ', 'Õ') -- latin capital letter O with tilde + str = string.gsub(str, 'Õ', 'Õ') -- latin capital letter O with tilde + str = string.gsub(str, 'Ö', 'Ö') -- latin capital letter O with diaeresis + str = string.gsub(str, 'Ö', 'Ö') -- latin capital letter O with diaeresis + str = string.gsub(str, 'Ø', 'Ø') -- latin capital letter O with slash + str = string.gsub(str, 'Ø', 'Ø') -- latin capital letter O with slash + str = string.gsub(str, 'Ù', 'Ù') -- latin capital letter U with grave + str = string.gsub(str, 'Ù', 'Ù') -- latin capital letter U with grave + str = string.gsub(str, 'Ú', 'Ú') -- latin capital letter U with acute + str = string.gsub(str, 'Ú', 'Ú') -- latin capital letter U with acute + str = string.gsub(str, 'Û', 'Û') -- latin capital letter U with circumflex + str = string.gsub(str, 'Û', 'Û') -- latin capital letter U with circumflex + str = string.gsub(str, 'Ü', 'Ü') -- latin capital letter U with diaeresis + str = string.gsub(str, 'Ü', 'Ü') -- latin capital letter U with diaeresis + str = string.gsub(str, 'Ý', 'Ý') -- latin capital letter Y with acute + str = string.gsub(str, 'Ý', 'Ý') -- latin capital letter Y with acute + str = string.gsub(str, 'Þ', 'Þ') -- latin capital letter THORN + str = string.gsub(str, 'Þ', 'Þ') -- latin capital letter THORN + str = string.gsub(str, 'Œ', 'Œ') -- latin capital letter OE + str = string.gsub(str, 'Š', 'Š') -- latin capital letter S with caron + str = string.gsub(str, 'Ÿ', 'Ÿ') -- latin capital letter Y with diaeresis + + -- Latin small letters + str = string.gsub(str, 'ß', 'ß') -- latin small letter sharp s - ess-zed + str = string.gsub(str, 'ß', 'ß') -- latin small letter sharp s - ess-zed + str = string.gsub(str, 'à', 'à') -- latin small letter a with grave + str = string.gsub(str, 'à', 'à') -- latin small letter a with grave + str = string.gsub(str, 'á', 'á') -- latin small letter a with acute + str = string.gsub(str, 'á', 'á') -- latin small letter a with acute + str = string.gsub(str, 'â', 'â') -- latin small letter a with circumflex + str = string.gsub(str, 'â', 'â') -- latin small letter a with circumflex + str = string.gsub(str, 'ã', 'ã') -- latin small letter a with tilde + str = string.gsub(str, 'ã', 'ã') -- latin small letter a with tilde + str = string.gsub(str, 'ä', 'ä') -- latin small letter a with diaeresis + str = string.gsub(str, 'ä', 'ä') -- latin small letter a with diaeresis + str = string.gsub(str, 'å', 'å') -- latin small letter a with ring above + str = string.gsub(str, 'å', 'å') -- latin small letter a with ring above + str = string.gsub(str, 'æ', 'æ') -- latin small letter ae + str = string.gsub(str, 'æ', 'æ') -- latin small letter ae + str = string.gsub(str, 'ç', 'ç') -- latin small letter c with cedilla + str = string.gsub(str, 'ç', 'ç') -- latin small letter c with cedilla + str = string.gsub(str, 'è', 'è') -- latin small letter e with grave + str = string.gsub(str, 'è', 'è') -- latin small letter e with grave + str = string.gsub(str, 'é', 'é') -- latin small letter e with acute + str = string.gsub(str, 'é', 'é') -- latin small letter e with acute + str = string.gsub(str, 'ê', 'ê') -- latin small letter e with circumflex + str = string.gsub(str, 'ê', 'ê') -- latin small letter e with circumflex + str = string.gsub(str, 'ë', 'ë') -- latin small letter e with diaeresis + str = string.gsub(str, 'ë', 'ë') -- latin small letter e with diaeresis + str = string.gsub(str, 'ì', 'ì') -- latin small letter i with grave + str = string.gsub(str, 'ì', 'ì') -- latin small letter i with grave + str = string.gsub(str, 'í', 'í') -- latin small letter i with acute + str = string.gsub(str, 'í', 'í') -- latin small letter i with acute + str = string.gsub(str, 'î', 'î') -- latin small letter i with circumflex + str = string.gsub(str, 'î', 'î') -- latin small letter i with circumflex + str = string.gsub(str, 'ï', 'ï') -- latin small letter i with diaeresis + str = string.gsub(str, 'ï', 'ï') -- latin small letter i with diaeresis + str = string.gsub(str, 'ð', 'ð') -- latin small letter eth + str = string.gsub(str, 'ð', 'ð') -- latin small letter eth + str = string.gsub(str, 'ñ', 'ñ') -- latin small letter n with tilde + str = string.gsub(str, 'ñ', 'ñ') -- latin small letter n with tilde + str = string.gsub(str, 'ò', 'ò') -- latin small letter o with grave + str = string.gsub(str, 'ò', 'ò') -- latin small letter o with grave + str = string.gsub(str, 'ó', 'ó') -- latin small letter o with acute + str = string.gsub(str, 'ó', 'ó') -- latin small letter o with acute + str = string.gsub(str, 'ô', 'ô') -- latin small letter o with circumflex + str = string.gsub(str, 'ô', 'ô') -- latin small letter o with circumflex + str = string.gsub(str, 'õ', 'õ') -- latin small letter o with tilde + str = string.gsub(str, 'õ', 'õ') -- latin small letter o with tilde + str = string.gsub(str, 'ö', 'ö') -- latin small letter o with diaeresis + str = string.gsub(str, 'ö', 'ö') -- latin small letter o with diaeresis + str = string.gsub(str, 'ø', 'ø') -- latin small letter o with slash + str = string.gsub(str, 'ø', 'ø') -- latin small letter o with slash + str = string.gsub(str, 'ù', 'ù') -- latin small letter u with grave + str = string.gsub(str, 'ù', 'ù') -- latin small letter u with grave + str = string.gsub(str, 'ú', 'ú') -- latin small letter u with acute + str = string.gsub(str, 'ú', 'ú') -- latin small letter u with acute + str = string.gsub(str, 'û', 'û') -- latin small letter u with circumflex + str = string.gsub(str, 'û', 'û') -- latin small letter u with circumflex + str = string.gsub(str, 'ü', 'ü') -- latin small letter u with diaeresis + str = string.gsub(str, 'ü', 'ü') -- latin small letter u with diaeresis + str = string.gsub(str, 'ý', 'ý') -- latin small letter y with acute + str = string.gsub(str, 'ý', 'ý') -- latin small letter y with acute + str = string.gsub(str, 'þ', 'þ') -- latin small letter thorn + str = string.gsub(str, 'þ', 'þ') -- latin small letter thorn + str = string.gsub(str, 'ÿ', 'ÿ') -- latin small letter y with diaeresis + str = string.gsub(str, 'ÿ', 'ÿ') -- latin small letter y with diaeresis + str = string.gsub(str, 'œ', 'œ') -- latin small letter oe + str = string.gsub(str, 'š', 'š') -- latin small letter s with caron + str = string.gsub(str, 'ƒ', 'ƒ') -- latin small f with hook - function + + -- Emoticons (more soon) + str = string.gsub(str, '⭐️', '⭐️') + + -- Be sure to do this after all others + str = string.gsub(str, '&', '&') -- amper sand + str = string.gsub(str, '&', '&') -- amper sand + + return str +end \ No newline at end of file diff --git a/miku/plugins/app_store.lua b/miku/plugins/app_store.lua index 5ef13af..e7e8b79 100644 --- a/miku/plugins/app_store.lua +++ b/miku/plugins/app_store.lua @@ -1,5 +1,7 @@ local app_store = {} +require "./miku/encoding" + app_store.triggers = { "itunes.apple.com/(.*)/app/(.*)/id(%d+)", "^/[Ii][Tt][Uu][Nn][Ee][Ss] (%d+)$", @@ -34,7 +36,7 @@ function app_store:send_appstore_data(data) local version = data.version -- Body - local description = string.sub(unescape(data.description), 1, 150) .. '...' + local description = string.sub(encoding(data.description), 1, 150) .. '...' local min_ios_ver = data.minimumOsVersion local size = string.gsub(round(data.fileSizeBytes / 1000000, 2), "%.", ",") -- wtf Apple, it's 1024, not 1000! local release = makeOurDate(data.releaseDate) diff --git a/miku/plugins/myanimelist.lua b/miku/plugins/myanimelist.lua index a0fd012..3f923c7 100644 --- a/miku/plugins/myanimelist.lua +++ b/miku/plugins/myanimelist.lua @@ -1,6 +1,7 @@ local mal = {} local xml = require("xml") +require "./miku/encoding" mal.command = 'anime , /manga ' @@ -117,7 +118,7 @@ function mal:send_anime_data(result, receiver) end if xml.find(result, 'synopsis')[1] then - desc = '\n_'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 250)))..'..._' + desc = '\n_'..encoding(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 250)))..'..._' else desc = '' end @@ -144,7 +145,7 @@ function mal:send_manga_data(result) end if xml.find(result, 'synonyms')[1] then - alt_name = '\noder: '..unescape(mal:delete_tags(xml.find(result, 'synonyms')[1])) + alt_name = '\noder: '..encoding(mal:delete_tags(xml.find(result, 'synonyms')[1])) else alt_name = '' end @@ -186,7 +187,7 @@ function mal:send_manga_data(result) end if xml.find(result, 'synopsis')[1] then - desc = '\n'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 200))) .. '...' + desc = '\n'..encoding(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 200))) .. '...' else desc = '' end diff --git a/miku/plugins/reddit.lua b/miku/plugins/reddit.lua index cc46488..5862efb 100644 --- a/miku/plugins/reddit.lua +++ b/miku/plugins/reddit.lua @@ -1,5 +1,7 @@ local reddit = {} +require "./miku/encoding" + reddit.command = 'reddit [r/subreddit | Suchbegriff]' function reddit:init(config) @@ -18,7 +20,7 @@ local format_results = function(posts) title = utilities.trim(title) .. '...' end local short_url = 'https://redd.it/' .. post.id - local s = '[' .. unescape(title) .. '](' .. short_url .. ')' + local s = '[' .. encoding(title) .. '](' .. short_url .. ')' if post.domain and not post.is_self and not post.over_18 then s = '`[`[' .. post.domain .. '](' .. post.url:gsub('%)', '\\)') .. ')`]` ' .. s end diff --git a/miku/plugins/reddit_post.lua b/miku/plugins/reddit_post.lua index cc2d16d..3a50d05 100644 --- a/miku/plugins/reddit_post.lua +++ b/miku/plugins/reddit_post.lua @@ -1,5 +1,7 @@ local reddit_post = {} +require "./miku/encoding" + reddit_post.triggers = { "reddit.com/r/([A-Za-z0-9-/-_-.]+)/comments/([A-Za-z0-9-/-_-.]+)" } @@ -19,9 +21,9 @@ function reddit_post:send_reddit_data(data) local author = utilities.md_escape(data[1].data.children[1].data.author) local subreddit = utilities.md_escape(data[1].data.children[1].data.subreddit) if string.len(data[1].data.children[1].data.selftext) > 300 then - selftext = string.sub(unescape(data[1].data.children[1].data.selftext:gsub("%b<>", "")), 1, 300) .. '...' + selftext = string.sub(encoding(data[1].data.children[1].data.selftext:gsub("%b<>", "")), 1, 300) .. '...' else - selftext = unescape(data[1].data.children[1].data.selftext:gsub("%b<>", "")) + selftext = encoding(data[1].data.children[1].data.selftext:gsub("%b<>", "")) end if not data[1].data.children[1].data.is_self then url = data[1].data.children[1].data.url diff --git a/miku/plugins/rss.lua b/miku/plugins/rss.lua index cba6cdf..3ca0434 100644 --- a/miku/plugins/rss.lua +++ b/miku/plugins/rss.lua @@ -1,6 +1,7 @@ local rss = {} local feedparser = require("feedparser") +require "./miku/encoding" rss.command = 'rss ' @@ -310,29 +311,29 @@ function rss:cron(self_plz) local subscribers = {} local text = '' -- Send one message per feed with the latest entries for k2, v2 in pairs(newentr) do - local title = unescape(v2.title) or 'Kein Titel' + local title = encoding(v2.title) or 'Kein Titel' local link = v2.link or v2.id or 'Kein Link' if v2.content then content = v2.content:gsub("%b<>", "") if string.len(v2.content) > 300 then - content = unescape(content) + content = encoding(content) content = string.sub(content, 1, 300)..'...' else - content = unescape(content) + content = encoding(content) end elseif v2.summary then content = v2.summary:gsub("%b<>", "") if string.len(v2.summary) > 300 then - content = unescape(content) + content = encoding(content) content = string.sub(content, 1, 300)..'...' else - content = unescape(content) + content = encoding(content) end else content = '' end content = cleanRSS(content) - text = text..'\n#RSS: '..title..'\n'..utilities.trim(content)..' Weiterlesen\n' + text = text..'\n[#RSS] '..title..'\n'..utilities.trim(content)..' Weiterlesen\n' end if text ~= '' then local newlast = newentr[1].id diff --git a/miku/plugins/steam.lua b/miku/plugins/steam.lua index 145b1ea..9fe1e6f 100644 --- a/miku/plugins/steam.lua +++ b/miku/plugins/steam.lua @@ -1,5 +1,7 @@ local steam = {} +require "./miku/encoding" + steam.triggers = { "store.steampowered.com/app/([0-9]+)", "steamcommunity.com/app/([0-9]+)" @@ -36,7 +38,7 @@ function steam:price_info(data) end function steam:send_steam_data(data, self, msg) - local description = string.sub(unescape(data.about_the_game:gsub("%b<>", "")), 1, DESC_LENTH) .. '...' + local description = string.sub(encoding(data.about_the_game:gsub("%b<>", "")), 1, DESC_LENTH) .. '...' local title = data.name local price = steam:price_info(data.price_overview) diff --git a/miku/plugins/tweet.lua b/miku/plugins/tweet.lua index 1e1723f..4894ced 100644 --- a/miku/plugins/tweet.lua +++ b/miku/plugins/tweet.lua @@ -1,5 +1,7 @@ local tweet = {} +require "./miku/encoding" + function tweet:init(config) if not cred_data.tw_consumer_key then print('Fehlender Key: tw_consumer_key.') @@ -75,7 +77,7 @@ function tweet:analyze_tweet(tweet) table.insert(urls, v.media_url) end text = text:gsub(v.url, "") -- Replace the URL in text - text = unescape(text) + text = encoding(text) end end @@ -125,7 +127,7 @@ end function tweet:sendTweet(self, msg, tweet) local header, text, urls = tweet:analyze_tweet(tweet) -- send the parts - local text = unescape(text) + local text = encoding(text) send_reply(self, msg, header .. "\n" .. text) tweet:send_all_files(self, msg, urls) return nil diff --git a/miku/plugins/twitter_send.lua b/miku/plugins/twitter_send.lua index 71b4b72..750ae2a 100644 --- a/miku/plugins/twitter_send.lua +++ b/miku/plugins/twitter_send.lua @@ -1,5 +1,7 @@ local twitter_send = {} +require "./miku/encoding" + function twitter_send:init(config) if not cred_data.tw_consumer_key then print('Fehlender Key: tw_consumer_key.') @@ -158,7 +160,7 @@ function twitter_send:twitter_verify_credentials(oauth_token, oauth_token_secret end local header = full_name.. " (@" ..user_name.. ")\n" - local description = unescape(response.description) + local description = encoding(response.description) if response.location then location = response.location else diff --git a/miku/plugins/twitter_user.lua b/miku/plugins/twitter_user.lua index 4f0f4f2..336f473 100644 --- a/miku/plugins/twitter_user.lua +++ b/miku/plugins/twitter_user.lua @@ -1,5 +1,7 @@ local twitter_user = {} +require "./miku/encoding" + function twitter_user:init(config) if not cred_data.tw_consumer_key then print('Fehlender Key: tw_consumer_key.') @@ -72,7 +74,7 @@ function twitter_user:action(msg) end local header = full_name.. " (@" ..user_name.. ")\n" - local description = unescape(response.description) + local description = encoding(response.description) if response.location then location = response.location else diff --git a/miku/utilities.lua b/miku/utilities.lua index 1ea93d3..9dd5225 100644 --- a/miku/utilities.lua +++ b/miku/utilities.lua @@ -1016,67 +1016,6 @@ function run_sh(msg) return text end -function unescape(str) - -- Character encoding - str = string.gsub(str, "´", "´") - str = string.gsub(str, "•", "•") - str = string.gsub(str, "é", "é") - str = string.gsub(str, ">", ">") - str = string.gsub(str, "…", "…") - str = string.gsub(str, "<", "<") - str = string.gsub(str, "—", "—") - str = string.gsub(str, "∇", "∇") - str = string.gsub(str, " ", " ") - str = string.gsub(str, "–", "–") - str = string.gsub(str, "Ψ", "ψ") - str = string.gsub(str, "ψ", "ψ") - str = string.gsub(str, """, '"') - str = string.gsub(str, "»", "»") - str = string.gsub(str, "®", "®") - str = string.gsub(str, "ß", "ß") - str = string.gsub(str, "™", "™") - str = string.gsub(str, "&", "&") - str = string.gsub(str, "'", "'") - str = string.gsub(str, """, '"') - str = string.gsub(str, "'", "'") - str = string.gsub(str, "|", "|") - str = string.gsub(str, " ", " ") - str = string.gsub(str, "®", "®") - str = string.gsub(str, "»", "»") - str = string.gsub(str, "ß", "ß") - str = string.gsub(str, "–", "–") - str = string.gsub(str, "’", "'") - str = string.gsub(str, "“", "“") - str = string.gsub(str, "”", "”") - str = string.gsub(str, "„", "„") - str = string.gsub(str, "…", "…") - str = string.gsub(str, "‹", "‹") - str = string.gsub(str, "€", "€") - str = string.gsub(str, "♪", "♪") - - -- Ä Ö Ü - str = string.gsub(str, "ä", "ä") - str = string.gsub(str, "Ä", "Ä") - str = string.gsub(str, "ä", "ä") - str = string.gsub(str, "Ä", "Ä") - str = string.gsub(str, "ö", "ö") - str = string.gsub(str, "Ö", "Ö") - str = string.gsub(str, "ö", "ö") - str = string.gsub(str, "Ö", "Ö") - str = string.gsub(str, "ü", "ü") - str = string.gsub(str, "Ü", "Ü") - str = string.gsub(str, "ü", "ü") - str = string.gsub(str, "Ü", "Ü") - - --emoticons - str = string.gsub(str, "⭐️", "⭐️") - - --str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end ) - --str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end ) - str = string.gsub( str, '&', '&' ) -- Be sure to do this after all others - return str -end - function gerRating(str) str = string.gsub(str, "de/0", "FSK0") str = string.gsub(str, "TV%-G", "FSK0")