2016-06-11 14:46:41 +02:00
|
|
|
local imgblacklist = {}
|
|
|
|
|
|
|
|
imgblacklist.command = 'imgblacklist'
|
|
|
|
|
|
|
|
function imgblacklist:init(config)
|
2016-07-17 13:22:27 +02:00
|
|
|
imgblacklist.triggers = {
|
2016-08-01 21:07:27 +02:00
|
|
|
"^/[Ii][Mm][Gg][Bb][Ll][Aa][Cc][Kk][Ll][Ii][Ss][Tt] show$",
|
|
|
|
"^/[Ii][Mm][Gg][Bb][Ll][Aa][Cc][Kk][Ll][Ii][Ss][Tt] (add) (.*)$",
|
|
|
|
"^/[Ii][Mm][Gg][Bb][Ll][Aa][Cc][Kk][Ll][Ii][Ss][Tt] (remove) (.*)$"
|
2016-07-17 13:22:27 +02:00
|
|
|
}
|
2016-06-11 14:46:41 +02:00
|
|
|
imgblacklist.doc = [[*
|
|
|
|
]]..config.cmd_pat..[[imgblacklist* _show_: Zeige Blacklist
|
|
|
|
*]]..config.cmd_pat..[[imgblacklist* _add_ _<Wort>_: Fügt Wort der Blacklist hinzu
|
|
|
|
*]]..config.cmd_pat..[[imgblacklist* _remove_ _<Wort>_: Entfernt Wort von der Blacklist]]
|
|
|
|
end
|
|
|
|
|
|
|
|
function imgblacklist:show_blacklist()
|
|
|
|
if not _blacklist[1] then
|
|
|
|
return "Keine Wörter geblacklisted!\nBlackliste welche mit `/imgblacklist add [Wort]`"
|
|
|
|
else
|
|
|
|
local sort_alph = function( a,b ) return a < b end
|
|
|
|
table.sort( _blacklist, sort_alph )
|
|
|
|
local blacklist = "Folgende Wörter stehen auf der Blacklist:\n"
|
|
|
|
for v,word in pairs(_blacklist) do
|
|
|
|
blacklist = blacklist..'- '..word..'\n'
|
|
|
|
end
|
|
|
|
return blacklist
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function imgblacklist:add_blacklist(word)
|
2016-08-01 21:07:27 +02:00
|
|
|
print('Blackliste '..word..' - Speicher in Redis Hash telegram:img_blacklist')
|
2016-06-11 14:46:41 +02:00
|
|
|
if redis:sismember("telegram:img_blacklist", word) == true then
|
|
|
|
return '"'..word..'" steht schon auf der Blacklist.'
|
|
|
|
else
|
|
|
|
redis:sadd("telegram:img_blacklist", word)
|
|
|
|
return '"'..word..'" blacklisted!'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function imgblacklist:remove_blacklist(word)
|
2016-08-01 21:07:27 +02:00
|
|
|
print('Deblackliste '..word..' - Lösche aus Redis Hash telegram:img_blacklist')
|
2016-06-11 14:46:41 +02:00
|
|
|
if redis:sismember("telegram:img_blacklist", word) == true then
|
|
|
|
redis:srem("telegram:img_blacklist", word)
|
|
|
|
return '"'..word..'" erfolgreich von der Blacklist gelöscht!'
|
|
|
|
else
|
|
|
|
return '"'..word..'" steht nicht auf der Blacklist.'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-17 13:22:27 +02:00
|
|
|
function imgblacklist:action(msg, config, matches)
|
2016-09-08 01:35:10 +02:00
|
|
|
if not is_sudo(msg, config) then
|
2016-08-26 17:42:31 +02:00
|
|
|
utilities.send_reply(msg, config.errors.sudo, true)
|
2016-06-12 17:35:32 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-07-17 13:22:27 +02:00
|
|
|
|
|
|
|
local action = matches[1]
|
|
|
|
if matches[2] then word = string.lower(matches[2]) else word = nil end
|
2016-06-11 14:46:41 +02:00
|
|
|
_blacklist = redis:smembers("telegram:img_blacklist")
|
|
|
|
|
2016-07-17 13:22:27 +02:00
|
|
|
if action == 'add' and not word then
|
2016-08-24 15:38:29 +02:00
|
|
|
utilities.send_reply(msg, imgblacklist.doc, true)
|
2016-06-11 14:46:41 +02:00
|
|
|
return
|
2016-07-17 13:22:27 +02:00
|
|
|
elseif action == "add" and word then
|
2016-08-24 15:38:29 +02:00
|
|
|
utilities.send_reply(msg, imgblacklist:add_blacklist(word), true)
|
2016-07-17 13:22:27 +02:00
|
|
|
return
|
2016-06-11 14:46:41 +02:00
|
|
|
end
|
2016-07-17 13:22:27 +02:00
|
|
|
|
|
|
|
if action == 'remove' and not word then
|
2016-08-24 15:38:29 +02:00
|
|
|
utilities.send_reply(msg, imgblacklist.doc, true)
|
2016-07-17 13:22:27 +02:00
|
|
|
return
|
|
|
|
elseif action == "remove" and word then
|
2016-08-24 15:38:29 +02:00
|
|
|
utilities.send_reply(msg, imgblacklist:remove_blacklist(word), true)
|
2016-07-17 13:22:27 +02:00
|
|
|
return
|
|
|
|
end
|
2016-06-11 14:46:41 +02:00
|
|
|
|
2016-08-24 15:38:29 +02:00
|
|
|
utilities.send_reply(msg, imgblacklist:show_blacklist())
|
2016-06-11 14:46:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return imgblacklist
|