From f7dce5e861e90581dd1317847aa4ca6771323150 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Mon, 3 Jul 2017 06:45:46 +0200 Subject: slack.lua: add a feature to undo emoji --- plugins/degesch/slack.lua | 49 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/plugins/degesch/slack.lua b/plugins/degesch/slack.lua index 87786da..fb99b99 100644 --- a/plugins/degesch/slack.lua +++ b/plugins/degesch/slack.lua @@ -24,12 +24,52 @@ local read_servers = function (v) end end +-- This is a reverse list of Slack's automatic emoji, noseless forms +local unemojify, emoji, emoji_default = false, {}, { + heart = "<3", + broken_heart = "", + neutral_face = ":|", + open_mouth = ":o", + angry = ">:(", + slightly_smiling_face = ":)", + disappointed = ":(", + confused = ":/", + stuck_out_tongue = ":p", + stuck_out_tongue_winking_eye = ";p", +} +local load_emoji = function (extra) + emoji = {} + for k, v in pairs (emoji_default) do emoji[k] = v end + for k, v in extra:gmatch "([^,]+) ([^,]+)" do emoji[k] = v end +end + degesch.setup_config { servers = { type = "string_array", default = "\"\"", comment = "list of server names that are Slack IRC gateways", on_change = read_servers + }, + unemojify = { + type = "boolean", + default = "true", + comment = "convert emoji to normal ASCII emoticons", + on_change = function (v) unemojify = v end + }, + extra_emoji = { + type = "string_array", + default = "\"grinning :)),joy :'),innocent o:),persevere >_<\"", + comment = "overrides or extra emoji for unemojify", + on_change = function (v) load_emoji (v) end } } @@ -48,9 +88,16 @@ degesch.hook_irc (function (hook, server, line) .. msg.prefix:match "^[^!@]*" .. " :" .. text end) --- Unfuck :nick!nick@irc.tinyspeck.com MODE #channel +v nick : active +-- Unfuck emoji and :nick!nick@irc.tinyspeck.com MODE #channel +v nick : active degesch.hook_irc (function (hook, server, line) if not servers[server.name] then return line end + if unemojify then + local start, text = line:match ("^(.- PRIVMSG .-:)(.*)$") + if start then return start .. text:gsub (":([a-z_]+):", function (name) + if emoji[name] then return emoji[name] end + return ":" .. name .. ":" + end) end + end return line:gsub ("^(:%S+ MODE .+) : .*", "%1") end) -- cgit v1.2.3-70-g09d2