slack.lua: add a feature to undo emoji
This commit is contained in:
		@@ -24,12 +24,52 @@ local read_servers = function (v)
 | 
				
			|||||||
	end
 | 
						end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- This is a reverse list of Slack's automatic emoji, noseless forms
 | 
				
			||||||
 | 
					local unemojify, emoji, emoji_default = false, {}, {
 | 
				
			||||||
 | 
						heart                        = "<3",
 | 
				
			||||||
 | 
						broken_heart                 = "</3",
 | 
				
			||||||
 | 
						sunglasses                   = "8)",
 | 
				
			||||||
 | 
						anguished                    = "D:",
 | 
				
			||||||
 | 
						cry                          = ":'(",
 | 
				
			||||||
 | 
						monkey_face                  = ":o)",
 | 
				
			||||||
 | 
						kiss                         = ":*",
 | 
				
			||||||
 | 
						smiley                       = "=)",
 | 
				
			||||||
 | 
						smile                        = ":D",
 | 
				
			||||||
 | 
						wink                         = ";)",
 | 
				
			||||||
 | 
						laughing                     = ":>",
 | 
				
			||||||
 | 
						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 {
 | 
					degesch.setup_config {
 | 
				
			||||||
	servers = {
 | 
						servers = {
 | 
				
			||||||
		type = "string_array",
 | 
							type = "string_array",
 | 
				
			||||||
		default = "\"\"",
 | 
							default = "\"\"",
 | 
				
			||||||
		comment = "list of server names that are Slack IRC gateways",
 | 
							comment = "list of server names that are Slack IRC gateways",
 | 
				
			||||||
		on_change = read_servers
 | 
							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
 | 
							.. msg.prefix:match "^[^!@]*" .. " :" .. text
 | 
				
			||||||
end)
 | 
					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)
 | 
					degesch.hook_irc (function (hook, server, line)
 | 
				
			||||||
	if not servers[server.name] then return line end
 | 
						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")
 | 
						return line:gsub ("^(:%S+ MODE .+) : .*", "%1")
 | 
				
			||||||
end)
 | 
					end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user