invite plugin
This commit is contained in:
parent
ae0411ff25
commit
7ce798b21b
@ -14,4 +14,4 @@ if [ ! -f ./tg/bin/telegram-cli ]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
./tg/bin/telegram-cli -k tg/tg-server.pub -s ./bot/bot.lua
|
||||
./tg/bin/telegram-cli -k tg/tg-server.pub -s ./bot/bot.lua -W
|
||||
|
42
plugins/invite.lua
Normal file
42
plugins/invite.lua
Normal file
@ -0,0 +1,42 @@
|
||||
-- Invite other user to the chat group.
|
||||
-- Use !invite name User_name or !invite id id_number
|
||||
-- The User_name is the print_name (there are no spaces but _)
|
||||
|
||||
do
|
||||
|
||||
local function run(msg, matches)
|
||||
-- User submitted a user name
|
||||
if matches[1] == "name" then
|
||||
user = matches[2]
|
||||
user = string.gsub(user," ","_")
|
||||
end
|
||||
-- User submitted an id
|
||||
if matches[1] == "id" then
|
||||
user = matches[2]
|
||||
user = 'user#id'..user
|
||||
end
|
||||
-- The message must come from a chat group
|
||||
if msg.to.type == 'chat' then
|
||||
chat = 'chat#id'..msg.to.id
|
||||
else
|
||||
return 'This isnt a chat group!'
|
||||
end
|
||||
print ("Trying to add: "..user.." to "..chat)
|
||||
status = chat_add_user (chat, user, ok_cb, false)
|
||||
if not status then
|
||||
return "An error happened"
|
||||
end
|
||||
return "Added user: "..user.." to "..chat
|
||||
end
|
||||
|
||||
return {
|
||||
description = "Invite other user to the chat group",
|
||||
usage = "!invite name [user_name], !invite id [user_id]",
|
||||
patterns = {
|
||||
"^!invite (name) (.*)$",
|
||||
"^!invite (id) (%d+)$"
|
||||
},
|
||||
run = run
|
||||
}
|
||||
|
||||
end
|
Reference in New Issue
Block a user