New method to escape markdown.
Improvements to patterns.lua.
This commit is contained in:
parent
1eb434f198
commit
c74d1913a4
5
bot.lua
5
bot.lua
@ -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.from.id_str = tostring(msg.from.id)
|
||||
msg.text_lower = msg.text:lower()
|
||||
msg.from.name = msg.from.first_name
|
||||
if msg.from.last_name then
|
||||
msg.from.name = msg.from.first_name .. ' ' .. msg.from.last_name
|
||||
end
|
||||
msg.from.name = build_name(msg.from.first_name, msg.from.last_name)
|
||||
|
||||
local success, result = pcall(function()
|
||||
return v.action(msg)
|
||||
|
@ -2,16 +2,16 @@
|
||||
-- he upset himself over the very thought of me doing so.
|
||||
|
||||
local triggers = {
|
||||
'^/s/.-/.-/?$'
|
||||
'^/?s/.-/.-/?$'
|
||||
}
|
||||
|
||||
local action = function(msg)
|
||||
|
||||
if not msg.reply_to_message then return end
|
||||
local output = msg.reply_to_message.text or ''
|
||||
output = output:gsub(
|
||||
msg.text:match('^/s/(.-)/(.-)/?$')
|
||||
)
|
||||
local m1, m2 = 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) .. '"'
|
||||
sendReply(msg.reply_to_message, output)
|
||||
|
||||
|
@ -12,12 +12,7 @@ local action = function(msg)
|
||||
|
||||
if msg.reply_to_message then
|
||||
msg = msg.reply_to_message
|
||||
end
|
||||
|
||||
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
|
||||
msg.from.name = build_name(msg.from.first_name, msg.from.last_name)
|
||||
end
|
||||
|
||||
local chat_id = math.abs(msg.chat.id)
|
||||
|
@ -77,7 +77,7 @@ local lc_list = {
|
||||
-- Replaces letters with corresponding Cyrillic characters.
|
||||
latcyr = function(str)
|
||||
for k,v in pairs(lc_list) do
|
||||
str = string.gsub(str, k, v)
|
||||
str = str:gsub(k, v)
|
||||
end
|
||||
return str
|
||||
end
|
||||
@ -140,6 +140,15 @@ table_size = function(tab)
|
||||
|
||||
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)
|
||||
|
||||
input = input:gsub('^@', '')
|
||||
@ -186,10 +195,7 @@ user_from_message = function(msg)
|
||||
|
||||
if not target.first_name then target.first_name = 'User' end
|
||||
|
||||
target.name = target.first_name
|
||||
if target.last_name then
|
||||
target.name = target.first_name .. ' ' .. target.last_name
|
||||
end
|
||||
target.name = build_name(target.first_name, target.last_name)
|
||||
|
||||
return target
|
||||
|
||||
@ -264,12 +270,3 @@ function string:md_escape()
|
||||
text = text:gsub('`', '\\`')
|
||||
return text
|
||||
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
|
||||
|
Reference in New Issue
Block a user