Take a look on what I wrote and give me some feedback:
lua Code:
local trim = function(str)
return str:trim(" \t\r\n")
end
local match = function(str)
local ret = {}
for msg, emote in str:gmatch("(.-)%*(.-)%*") do
str = str:replace(msg, "")
str = str:replace("*"..emote.."*", "")
msg = trim(msg)
emote = trim(emote)
table.insert(ret, {
msg:len() > 0 and msg or nil,
emote:len() > 0 and emote or nil,
})
end
str = trim(str)
if str:len() > 0 then
table.insert(ret, {str, nil})
end
return #ret > 0 and ret or nil
end
In short, match("message") will return either nil if nothing matched or a table containing {message, emote} that you can go trough each one, unpack each entry and send the message in the /say or /emote channels depending if it's a string or nil.
Far better than my first sketch, aye?