fban.help = '/fban [user] - Bans a user from the current chat and the Fed the group is part of. This command can only be used by Fed admins. Aliases: /fedban, /fb.'
end
function fban.on_new_message(_, message)
if message.chat.type ~= 'supergroup' then
return false
elseif mattata.is_user_fedbanned(message.chat.id, message.from.id) and not mattata.is_user_fed_whitelisted(message.chat.id, message.from.id) then
mattata.send_message(message.chat.id, 'Banned ' .. message.from.first_name .. ', because they\'ve been banned in one of this group\'s Feds!')
if reason and type(reason) == 'string' and reason:match('^[Ff][Oo][Rr] ') then
reason = reason:match('^[Ff][Oo][Rr] (.-)$')
end
if tonumber(user) == nil and not user:match('^%@') then
user = '@' .. user
end
local user_object = mattata.get_user(user) or mattata.get_chat(user) -- resolve the username/ID to a user object
if not user_object then
local output = language['errors']['unknown']
return mattata.send_reply(message, output)
elseif user_object.result.id == self.info.id then
return false -- don't let the bot Fed-ban itself
end
user_object = user_object.result
local status = mattata.get_chat_member(message.chat.id, user_object.id)
local is_admin = mattata.is_group_admin(message.chat.id, user_object.id)
if not status then
local output = language['errors']['generic']
return mattata.send_reply(message, output)
elseif is_admin then -- we won't try and Fed-ban moderators and administrators.
local output = 'I can\'t ban that user from the Fed because they\'re an admin in one of the groups!'
return mattata.send_reply(message, output)
end
local success = mattata.fed_ban_chat_member(message.chat.id, user_object.id, is_admin_feds) -- attempt to Fed-ban the user from the group
if not success then
mattata.send_reply(message, 'I couldn\'t ban that user in this group, because it appears I don\'t have permission to! I have still added them to the Fed-ban list(s) though!')