From 0a94c93560bbefde6d6f02421a752e2a1cad64b9 Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Fri, 8 Jul 2016 13:36:51 +0200 Subject: [PATCH] =?UTF-8?q?-=20Imgblacklist=20=C3=BCberarbeitet=20-=20Tage?= =?UTF-8?q?sschau=5FEIL:=20Fix=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otouto/plugins/imgblacklist.lua | 38 +++++++++++++++++++------------ otouto/plugins/tagesschau_eil.lua | 2 +- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/otouto/plugins/imgblacklist.lua b/otouto/plugins/imgblacklist.lua index 70b1048..b13a64b 100644 --- a/otouto/plugins/imgblacklist.lua +++ b/otouto/plugins/imgblacklist.lua @@ -6,7 +6,11 @@ local redis = (loadfile "./otouto/redis.lua")() imgblacklist.command = 'imgblacklist' function imgblacklist:init(config) - imgblacklist.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('imgblacklist', true).table + imgblacklist.triggers = { + "^/imgblacklist show$", + "^/imgblacklist (add) (.*)$", + "^/imgblacklist (remove) (.*)$" + } imgblacklist.doc = [[* ]]..config.cmd_pat..[[imgblacklist* _show_: Zeige Blacklist *]]..config.cmd_pat..[[imgblacklist* _add_ __: Fügt Wort der Blacklist hinzu @@ -47,30 +51,34 @@ function imgblacklist:remove_blacklist(word) end end -function imgblacklist:action(msg, config) +function imgblacklist:action(msg, config, matches) if msg.from.id ~= config.admin then utilities.send_reply(self, msg, config.errors.sudo) return end - local input = utilities.input(msg.text) - local input = string.lower(input) + + local action = matches[1] + if matches[2] then word = string.lower(matches[2]) else word = nil end _blacklist = redis:smembers("telegram:img_blacklist") - if input:match('(add) (.*)') then - local word = input:match('add (.*)') - output = imgblacklist:add_blacklist(word) - elseif input:match('(remove) (.*)') then - local word = input:match('remove (.*)') - output = imgblacklist:remove_blacklist(word) - elseif input:match('(show)') then - output = imgblacklist:show_blacklist() - else - utilities.send_message(self, msg.chat.id, imgblacklist.doc, true, msg.message_id, true) + if action == 'add' and not word then + utilities.send_reply(self, msg, imgblacklist.doc, true) return + elseif action == "add" and word then + utilities.send_reply(self, msg, imgblacklist:add_blacklist(word), true) + return end + + if action == 'remove' and not word then + utilities.send_reply(self, msg, imgblacklist.doc, true) + return + elseif action == "remove" and word then + utilities.send_reply(self, msg, imgblacklist:remove_blacklist(word), true) + return + end - utilities.send_message(self, msg.chat.id, output, true, nil, true) + utilities.send_reply(self, msg, imgblacklist:show_blacklist()) end return imgblacklist diff --git a/otouto/plugins/tagesschau_eil.lua b/otouto/plugins/tagesschau_eil.lua index a548bb2..59328e8 100644 --- a/otouto/plugins/tagesschau_eil.lua +++ b/otouto/plugins/tagesschau_eil.lua @@ -88,8 +88,8 @@ function tagesschau_eil:cron(self_plz) -- print('EIL: Prüfe...') local last_eil = redis:get(hash..':last_entry') local res,code = http.request(url) - local data = json.decode(res) if code ~= 200 then return end + local data = json.decode(res) if not data then return end if data.breakingnews[1] then if data.breakingnews[1].date ~= last_eil then