whitelist.help = '/whitelist [user] - Whitelists a user to use the bot in the current chat. This command can only be used by moderators and administrators of a supergroup.'
end
function whitelist:on_message(message, configuration, language)
if message.chat.type ~= 'supergroup'
then
return mattata.send_reply(
message,
language['errors']['supergroup']
)
elseif not mattata.is_group_admin(
message.chat.id,
message.from.id
)
then
return mattata.send_reply(
message,
language['errors']['admin']
)
end
local reason = false
local input = message.reply
and (
message.reply.from.username
or tostring(message.reply.from.id)
)
or mattata.input(message.text)
if not input
then
local success = mattata.send_force_reply(
message,
language['whitelist']['1']
)
if success
then
redis:set(
string.format(
'action:%s:%s',
message.chat.id,
success.result.message_id
),
'/whitelist'
)
end
return
elseif not message.reply
then
if input:match('^.- .-$')
then
reason = input:match(' (.-)$')
input = input:match('^(.-) ')
end
elseif mattata.input(message.text)
then
reason = mattata.input(message.text)
end
if tonumber(input) == nil
and not input:match('^%@')
then
input = '@' .. input
end
local user = mattata.get_user(input)
or mattata.get_chat(input) -- Resolve the username/ID to a user object.
if not user
then
return mattata.send_reply(
message,
language['errors']['unknown']
)
elseif user.result.id == self.info.id
then
return
end
user = user.result
local status = mattata.get_chat_member(
message.chat.id,
user.id
)
if not status
then
return mattata.send_reply(
message,
language['errors']['generic']
)
elseif mattata.is_group_admin(
message.chat.id,
user.id
)
or status.result.status == 'creator'
or status.result.status == 'administrator'
then -- We won't try and whitelist moderators and administrators.