Merge Upstream

This commit is contained in:
Akamaru 2016-08-28 18:38:01 +02:00
commit a305708f01
4 changed files with 36 additions and 30 deletions

View File

@ -157,6 +157,13 @@ function bot:on_msg_receive(msg, config) -- The fn run whenever a message is rec
msg.text = string.gsub(msg.text, config.cmd_pat..'([A-Za-z0-9-_-]+)@'..self.info.username, "/%1") msg.text = string.gsub(msg.text, config.cmd_pat..'([A-Za-z0-9-_-]+)@'..self.info.username, "/%1")
msg.text_lower = msg.text:lower() msg.text_lower = msg.text:lower()
end end
if is_channel_disabled(msg)then
if not is_sudo(msg, config) or msg.text ~= "/channel enable" then
return
end
end
msg = pre_process_msg(self, msg, config) msg = pre_process_msg(self, msg, config)
if not msg then return end -- deleted by banning if not msg then return end -- deleted by banning
@ -318,10 +325,12 @@ end
function pre_process_msg(self, msg, config) function pre_process_msg(self, msg, config)
for n=1, #self.plugins do for n=1, #self.plugins do
local plugin = self.plugins[n] local plugin = self.plugins[n]
if plugin.pre_process and msg then if plugin.pre_process and msg then
-- print('Preprocess '..plugin.name) -- remove comment to restore old behaviour if not is_plugin_disabled_on_chat(plugin.name, msg, true) then
new_msg = plugin:pre_process(msg, config) -- print('Preprocess '..plugin.name) -- remove comment to restore old behaviour
if not new_msg then return end -- Message was deleted new_msg = plugin:pre_process(msg, config)
if not new_msg then return end -- Message was deleted
end
end end
end end
return new_msg return new_msg
@ -372,13 +381,15 @@ function match_plugins(self, msg, config, plugin)
end end
end end
function is_plugin_disabled_on_chat(plugin_name, msg) function is_plugin_disabled_on_chat(plugin_name, msg, silent)
local hash = get_redis_hash(msg, 'disabled_plugins') local hash = get_redis_hash(msg, 'disabled_plugins')
local disabled = redis:hget(hash, plugin_name) local disabled = redis:hget(hash, plugin_name)
-- Plugin is disabled -- Plugin is disabled
if disabled == 'true' then if disabled == 'true' then
print('Plugin '..plugin_name..' ist in diesem Chat deaktiviert') if not silent then
print('Plugin '..plugin_name..' ist in diesem Chat deaktiviert')
end
return true return true
else else
return false return false

View File

@ -11,18 +11,6 @@ function channels:init(config)
]]..config.cmd_pat..[[channel* _<enable>_/_<disable>_: Aktiviert/deaktiviert den Bot im Chat]] ]]..config.cmd_pat..[[channel* _<enable>_/_<disable>_: Aktiviert/deaktiviert den Bot im Chat]]
end end
-- Checks if bot was disabled on specific chat
function channels:is_channel_disabled(msg)
local hash = 'chat:'..msg.chat.id..':disabled'
local disabled = redis:get(hash)
if not disabled or disabled == "false" then
return false
end
return disabled
end
function channels:enable_channel(msg) function channels:enable_channel(msg)
local hash = 'chat:'..msg.chat.id..':disabled' local hash = 'chat:'..msg.chat.id..':disabled'
local disabled = redis:get(hash) local disabled = redis:get(hash)
@ -55,12 +43,7 @@ function channels:pre_process(msg, config)
end end
end end
if channels:is_channel_disabled(msg) then return msg
print('Channel wurde deaktiviert')
return
end
return msg
end end
function channels:action(msg, config, matches) function channels:action(msg, config, matches)

View File

@ -15,9 +15,9 @@ function reddit_post:get_reddit_data(subreddit, reddit_code)
end end
function reddit_post:send_reddit_data(data) function reddit_post:send_reddit_data(data)
local title = utilities.md_escape(data[1].data.children[1].data.title) local title = data[1].data.children[1].data.title
local author = utilities.md_escape(data[1].data.children[1].data.author) local author = data[1].data.children[1].data.author
local subreddit = utilities.md_escape(data[1].data.children[1].data.subreddit) local subreddit = data[1].data.children[1].data.subreddit
if string.len(data[1].data.children[1].data.selftext) > 300 then if string.len(data[1].data.children[1].data.selftext) > 300 then
selftext = string.sub(unescape(data[1].data.children[1].data.selftext:gsub("%b<>", "")), 1, 300) .. '...' selftext = string.sub(unescape(data[1].data.children[1].data.selftext:gsub("%b<>", "")), 1, 300) .. '...'
else else
@ -30,7 +30,7 @@ function reddit_post:send_reddit_data(data)
end end
local score = comma_value(data[1].data.children[1].data.score) local score = comma_value(data[1].data.children[1].data.score)
local comments = comma_value(data[1].data.children[1].data.num_comments) local comments = comma_value(data[1].data.children[1].data.num_comments)
local text = '*'..author..'* in */r/'..subreddit..'* _('..score..' Upvotes - '..comments..' Kommentare)_:\n'..title..'\n'..selftext..url local text = '<b>'..author..'</b> in <b>/r/'..subreddit..'</b> <i>('..score..' Upvotes - '..comments..' Kommentare)</i>:\n<b>'..title..'\n</b>'..selftext..url
return text return text
end end
@ -44,7 +44,7 @@ function reddit_post:action(msg, config, matches)
local text = reddit_post:send_reddit_data(data) local text = reddit_post:send_reddit_data(data)
if not text then utilities.send_reply(msg, config.errors.connection) return end if not text then utilities.send_reply(msg, config.errors.connection) return end
utilities.send_reply(msg, text, true) utilities.send_reply(msg, text, 'HTML')
end end
return reddit_post return reddit_post

View File

@ -1118,4 +1118,16 @@ function table.contains(table, element)
return false return false
end end
-- Checks if bot was disabled on specific chat
function is_channel_disabled(msg)
local hash = 'chat:'..msg.chat.id..':disabled'
local disabled = redis:get(hash)
if not disabled or disabled == "false" then
return false
end
return disabled
end
return utilities return utilities