This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/miku/plugins/imgblacklist.lua

82 lines
2.6 KiB
Lua
Raw Normal View History

local imgblacklist = {}
imgblacklist.command = 'imgblacklist'
function imgblacklist:init(config)
imgblacklist.triggers = {
"^/[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) (.*)$"
}
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)
print('Blackliste '..word..' - Speicher in Redis Hash telegram:img_blacklist')
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)
print('Deblackliste '..word..' - Lösche aus Redis Hash telegram:img_blacklist')
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
function imgblacklist:action(msg, config, matches)
2016-09-08 01:35:10 +02:00
if not is_sudo(msg, config) then
utilities.send_reply(msg, config.errors.sudo, true)
return
end
local action = matches[1]
if matches[2] then word = string.lower(matches[2]) else word = nil end
_blacklist = redis:smembers("telegram:img_blacklist")
if action == 'add' and not word then
utilities.send_reply(msg, imgblacklist.doc, true)
return
elseif action == "add" and word then
utilities.send_reply(msg, imgblacklist:add_blacklist(word), true)
return
end
if action == 'remove' and not word then
utilities.send_reply(msg, imgblacklist.doc, true)
return
elseif action == "remove" and word then
utilities.send_reply(msg, imgblacklist:remove_blacklist(word), true)
return
end
utilities.send_reply(msg, imgblacklist:show_blacklist())
end
return imgblacklist