New method to escape markdown.

Improvements to patterns.lua.
This commit is contained in:
topkecleon 2016-04-02 19:20:28 -04:00
parent 1eb434f198
commit c74d1913a4
4 changed files with 17 additions and 28 deletions

View File

@ -84,10 +84,7 @@ on_msg_receive = function(msg) -- The fn run whenever a message is received.
msg.chat.id_str = tostring(msg.chat.id) msg.chat.id_str = tostring(msg.chat.id)
msg.from.id_str = tostring(msg.from.id) msg.from.id_str = tostring(msg.from.id)
msg.text_lower = msg.text:lower() msg.text_lower = msg.text:lower()
msg.from.name = msg.from.first_name msg.from.name = build_name(msg.from.first_name, msg.from.last_name)
if msg.from.last_name then
msg.from.name = msg.from.first_name .. ' ' .. msg.from.last_name
end
local success, result = pcall(function() local success, result = pcall(function()
return v.action(msg) return v.action(msg)

View File

@ -2,16 +2,16 @@
-- he upset himself over the very thought of me doing so. -- he upset himself over the very thought of me doing so.
local triggers = { local triggers = {
'^/s/.-/.-/?$' '^/?s/.-/.-/?$'
} }
local action = function(msg) local action = function(msg)
if not msg.reply_to_message then return end if not msg.reply_to_message then return end
local output = msg.reply_to_message.text or '' local output = msg.reply_to_message.text or ''
output = output:gsub( local m1, m2 = msg.text:match('^/?s/(.-)/(.-)/?$')
msg.text:match('^/s/(.-)/(.-)/?$') if not m2 then return true end
) output = output:gsub(m1, m2)
output = 'Did you mean:\n"' .. output:sub(1, 4000) .. '"' output = 'Did you mean:\n"' .. output:sub(1, 4000) .. '"'
sendReply(msg.reply_to_message, output) sendReply(msg.reply_to_message, output)

View File

@ -12,12 +12,7 @@ local action = function(msg)
if msg.reply_to_message then if msg.reply_to_message then
msg = msg.reply_to_message msg = msg.reply_to_message
end msg.from.name = build_name(msg.from.first_name, msg.from.last_name)
if msg.from.last_name then
msg.from.name = msg.from.first_name .. ' ' .. msg.from.last_name
else
msg.from.name = msg.from.first_name
end end
local chat_id = math.abs(msg.chat.id) local chat_id = math.abs(msg.chat.id)

View File

@ -77,7 +77,7 @@ local lc_list = {
-- Replaces letters with corresponding Cyrillic characters. -- Replaces letters with corresponding Cyrillic characters.
latcyr = function(str) latcyr = function(str)
for k,v in pairs(lc_list) do for k,v in pairs(lc_list) do
str = string.gsub(str, k, v) str = str:gsub(k, v)
end end
return str return str
end end
@ -140,6 +140,15 @@ table_size = function(tab)
end end
-- Just an easy way to get a user's full name.
build_name = function(first, last)
if last then
return first .. ' ' .. last
else
return first
end
end
resolve_username = function(input) resolve_username = function(input)
input = input:gsub('^@', '') input = input:gsub('^@', '')
@ -186,10 +195,7 @@ user_from_message = function(msg)
if not target.first_name then target.first_name = 'User' end if not target.first_name then target.first_name = 'User' end
target.name = target.first_name target.name = build_name(target.first_name, target.last_name)
if target.last_name then
target.name = target.first_name .. ' ' .. target.last_name
end
return target return target
@ -264,12 +270,3 @@ function string:md_escape()
text = text:gsub('`', '\\`') text = text:gsub('`', '\\`')
return text return text
end end
-- Just an easy way to get a user's full name.
build_name = function(first, last)
if last then
return first .. ' ' .. last
else
return first
end
end