2015-11-25 03:22:04 +01:00
|
|
|
-- This plugin will allow the admin to blacklist users who will be unable to
|
|
|
|
-- use the bot. This plugin should be at the top of your plugin list in config.
|
2015-08-09 02:53:46 +02:00
|
|
|
|
2016-04-08 23:12:02 +02:00
|
|
|
local blacklist = {}
|
|
|
|
|
2016-06-07 06:31:34 +02:00
|
|
|
local utilities = require('otouto.utilities')
|
2016-07-15 21:24:20 +02:00
|
|
|
local bindings = require('otouto.bindings')
|
2016-04-08 23:12:02 +02:00
|
|
|
|
|
|
|
function blacklist:init()
|
|
|
|
if not self.database.blacklist then
|
|
|
|
self.database.blacklist = {}
|
|
|
|
end
|
2016-02-21 20:28:40 +01:00
|
|
|
end
|
|
|
|
|
2016-04-08 23:12:02 +02:00
|
|
|
blacklist.triggers = {
|
2015-11-25 03:22:04 +01:00
|
|
|
''
|
2015-08-09 02:53:46 +02:00
|
|
|
}
|
|
|
|
|
2016-07-15 21:24:20 +02:00
|
|
|
blacklist.error = false
|
|
|
|
|
2016-05-27 02:26:30 +02:00
|
|
|
function blacklist:action(msg, config)
|
2016-07-15 21:24:20 +02:00
|
|
|
if self.database.blacklist[tostring(msg.from.id)] then
|
|
|
|
return
|
|
|
|
elseif self.database.blacklist[tostring(msg.chat.id)] then
|
|
|
|
bindings.leaveChat(self, { chat_id = msg.chat.id })
|
2016-03-22 11:16:26 +01:00
|
|
|
return
|
2015-11-25 03:22:04 +01:00
|
|
|
end
|
2016-07-14 03:57:23 +02:00
|
|
|
if not (
|
|
|
|
msg.from.id == config.admin
|
|
|
|
and (
|
|
|
|
msg.text:match('^'..config.cmd_pat..'blacklist')
|
|
|
|
or msg.text:match('^'..config.cmd_pat..'unblacklist')
|
|
|
|
)
|
|
|
|
) then
|
|
|
|
return true
|
2016-03-26 11:12:01 +01:00
|
|
|
end
|
2016-07-14 03:57:23 +02:00
|
|
|
local targets = {}
|
|
|
|
if msg.reply_to_message then
|
|
|
|
table.insert(targets, {
|
|
|
|
id_str = tostring(msg.reply_to_message.from.id),
|
|
|
|
name = utilities.build_name(msg.reply_to_message.from.first_name, msg.reply_to_message.from.last_name)
|
|
|
|
})
|
2015-08-09 02:53:46 +02:00
|
|
|
else
|
2016-07-14 03:57:23 +02:00
|
|
|
local input = utilities.input(msg.text)
|
|
|
|
if input then
|
|
|
|
for _, user in ipairs(utilities.index(input)) do
|
|
|
|
if self.database.users[user] then
|
|
|
|
table.insert(targets, {
|
|
|
|
id = self.database.users[user].id,
|
|
|
|
id_str = tostring(self.database.users[user].id),
|
|
|
|
name = utilities.build_name(self.database.users[user].first_name, self.database.users[user].last_name)
|
|
|
|
})
|
|
|
|
elseif tonumber(user) then
|
|
|
|
local t = {
|
|
|
|
id_str = user,
|
|
|
|
id = tonumber(user)
|
|
|
|
}
|
|
|
|
if tonumber(user) < 0 then
|
|
|
|
t.name = 'Group (' .. user .. ')'
|
|
|
|
else
|
|
|
|
t.name = 'Unknown (' .. user .. ')'
|
|
|
|
end
|
|
|
|
table.insert(targets, t)
|
|
|
|
elseif user:match('^@') then
|
|
|
|
local u = utilities.resolve_username(self, user)
|
|
|
|
if u then
|
|
|
|
table.insert(targets, {
|
|
|
|
id = u.id,
|
|
|
|
id_str = tostring(u.id),
|
|
|
|
name = utilities.build_name(u.first_name, u.last_name)
|
|
|
|
})
|
|
|
|
else
|
|
|
|
table.insert(targets, { err = 'Sorry, I do not recognize that username ('..user..').' })
|
|
|
|
end
|
|
|
|
else
|
|
|
|
table.insert(targets, { err = 'Invalid username or ID ('..user..').' })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
utilities.send_reply(self, msg, 'Please specify a user or users via reply, username, or ID, or a group or groups via ID.')
|
|
|
|
return
|
otouto 3.11
"things occurred"
Added some utilities (id_from_username, id_from_message), removed some utilities (latcyr, others?).
Removed cycle-wasting "shortcuts" -- no more automatic id_str or name; text_lower remains.
Moved userdata (nicknames, lastfm, etc) to a different tree in the database (automatic migration will occur). /me now returns userdata.
Speaking of migration, database now stores the latest version run to make future automigration easy.
Database now saves hourly rather than minutely.
Changed readme and some plugins to reflect above changes.
Removed broken rockspec (Brayden, feel free to re-add once it's working).
Added option to automatically block people (via drua) when blacklisted.
Fixed about.lua trigger problems.
administration 1.11 - Removed /kickme and /broadcast. Users should leave manually, and announcements should be made via channel rather than spam. /setqotd now handles forwarded messages correctly. /kick, /ban, /hammer,
/mod, /admin now support multiple arguments. Added get_targets function. No migration is necessary.
2016-07-05 09:29:11 +02:00
|
|
|
end
|
2015-08-09 02:53:46 +02:00
|
|
|
end
|
2016-07-14 03:57:23 +02:00
|
|
|
local output = ''
|
|
|
|
if msg.text:match('^'..config.cmd_pat..'blacklist') then
|
|
|
|
for _, target in ipairs(targets) do
|
|
|
|
if target.err then
|
|
|
|
output = output .. target.err .. '\n'
|
|
|
|
elseif self.database.blacklist[target.id_str] then
|
|
|
|
output = output .. target.name .. ' is already blacklisted.\n'
|
|
|
|
else
|
|
|
|
self.database.blacklist[target.id_str] = true
|
|
|
|
output = output .. target.name .. ' is now blacklisted.\n'
|
|
|
|
if config.drua_block_on_blacklist and target.id > 0 then
|
|
|
|
require('drua-tg').block(target.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
elseif msg.text:match('^'..config.cmd_pat..'unblacklist') then
|
|
|
|
for _, target in ipairs(targets) do
|
|
|
|
if target.err then
|
|
|
|
output = output .. target.err .. '\n'
|
|
|
|
elseif not self.database.blacklist[target.id_str] then
|
|
|
|
output = output .. target.name .. ' is not blacklisted.\n'
|
|
|
|
else
|
|
|
|
self.database.blacklist[target.id_str] = nil
|
|
|
|
output = output .. target.name .. ' is no longer blacklisted.\n'
|
|
|
|
if config.drua_block_on_blacklist and target.id > 0 then
|
|
|
|
require('drua-tg').unblock(target.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
utilities.send_reply(self, msg, output)
|
|
|
|
end
|
2015-08-09 02:53:46 +02:00
|
|
|
|
2016-07-14 03:57:23 +02:00
|
|
|
return blacklist
|