forked from MTSR/telegram
Support short bot command syntax
This commit is contained in:
parent
572c2bb2cf
commit
0172e7e740
17
init.lua
17
init.lua
@ -90,10 +90,21 @@ function telegram.send_message(chat_id, text)
|
||||
make_request("sendMessage", request_body, nil)
|
||||
end
|
||||
|
||||
local function get_command(msg)
|
||||
local comm = nil
|
||||
local bot_name = nil
|
||||
|
||||
comm, bot_name = string.match(msg.text, "/(%a+)@(.+)")
|
||||
if not comm then
|
||||
comm = string.match(msg.text, "/(%a+)")
|
||||
end
|
||||
|
||||
-- TODO Check the bot name if using full command
|
||||
return COMMANDS[comm]
|
||||
end
|
||||
|
||||
function telegram.on_text_receive(msg)
|
||||
local comm, bot_name = string.match(msg.text, "/(%a+)@(.+)")
|
||||
-- TODO Check the bot name
|
||||
local command = COMMANDS[comm]
|
||||
local command = get_command(msg)
|
||||
if command then
|
||||
command(msg)
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user