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)
|
make_request("sendMessage", request_body, nil)
|
||||||
end
|
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)
|
function telegram.on_text_receive(msg)
|
||||||
local comm, bot_name = string.match(msg.text, "/(%a+)@(.+)")
|
local command = get_command(msg)
|
||||||
-- TODO Check the bot name
|
|
||||||
local command = COMMANDS[comm]
|
|
||||||
if command then
|
if command then
|
||||||
command(msg)
|
command(msg)
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user