2016-08-03 19:05:05 +02:00
local leave_group = { }
leave_group.triggers = {
' ^//tgservice group_chat_created$ ' ,
2016-09-05 13:11:21 +02:00
' ^//tgservice supergroup_chat_created$ ' ,
' ^//tgservice new_chat_member$ ' ,
' ^//tgservice (left_chat_member)$ '
2016-08-03 19:05:05 +02:00
}
local report_to_admin = true -- set to false to not be notified, when Bot leaves groups without you
2016-08-24 15:38:29 +02:00
function leave_group : check_for_admin ( msg , config )
local result = bindings.request ( ' getChatMember ' , {
2016-08-03 19:05:05 +02:00
chat_id = msg.chat . id ,
user_id = config.admin
} )
if not result.ok then
2016-08-01 21:51:37 +02:00
print ( ' Konnte nicht prüfen, ob Admin in Gruppe ist! Verlasse sie sicherheitshalber... ' )
2016-08-03 19:05:05 +02:00
return false
end
if result.result . status ~= " member " and result.result . status ~= " administrator " and result.result . status ~= " creator " then
return false
else
return true
end
end
2016-09-05 13:11:21 +02:00
function leave_group : action ( msg , config , matches )
2016-08-03 19:05:05 +02:00
if not is_service_msg ( msg ) then return end -- Bad attempt at trolling!
2016-09-05 13:11:21 +02:00
if matches [ 1 ] == ' left_chat_member ' then
if msg.left_chat_member . id == config.admin then
admin_in_group = false
else
admin_in_group = leave_group : check_for_admin ( msg , config )
end
else
admin_in_group = leave_group : check_for_admin ( msg , config )
end
2016-08-03 19:05:05 +02:00
if not admin_in_group then
print ( ' Admin ist nicht in der Gruppe, verlasse sie deshalb... ' )
2016-08-24 15:38:29 +02:00
utilities.send_reply ( msg , ' Dieser Bot wurde in eine fremde Gruppe hinzugefügt. Dies wird gemeldet! \n This bot was added to foreign group. This incident will be reported! ' )
local result = bindings.request ( ' leaveChat ' , {
2016-08-03 19:05:05 +02:00
chat_id = msg.chat . id
} )
local chat_name = msg.chat . title
local chat_id = msg.chat . id
local from = msg.from . name
local from_id = msg.from . id
if report_to_admin then
2016-08-24 15:38:29 +02:00
utilities.send_message ( config.admin , ' #WARNUNG: Bot wurde in fremde Gruppe hinzugefügt: \n Gruppenname: ' .. chat_name .. ' ( ' .. chat_id .. ' ) \n Hinzugefügt von: ' .. from .. ' ( ' .. from_id .. ' ) ' )
2016-08-03 19:05:05 +02:00
end
end
end
return leave_group