Merge Upstream

This commit is contained in:
Andreas Bielawski 2016-08-16 17:42:25 +02:00
commit d4ed80a288
3 changed files with 50 additions and 16 deletions

View File

@ -3,7 +3,7 @@ local bot = {}
bindings = require('miku.bindings')
utilities = require('miku.utilities')
bot.version = '160815'
bot.version = '160816'
function bot:init(config) -- The function run when the bot is started or reloaded.
cred_data = load_cred()

View File

@ -47,6 +47,9 @@ function banhammer:kick_user(user_id, chat_id, self, onlykick)
chat_id = chat_id,
user_id = user_id
} )
local hash = 'chat:'..chat_id..':users'
print('User '..user_id..' was kicked/left the chat, deleting them from redis set '..hash)
redis:srem(hash, user_id)
if onlykick then return end
if not request then return 'User gebannt, aber kicken war nicht erfolgreich. Bin ich Administrator oder ist der User hier überhaupt?' end
return 'User '..user_id..' gebannt!'
@ -173,8 +176,7 @@ end
function banhammer:action(msg, config, matches)
if not is_sudo(msg, config) then
utilities.send_reply(self, msg, config.errors.sudo)
return
return -- Silent ignore
end
if matches[1] == 'leave' then
@ -193,7 +195,13 @@ function banhammer:action(msg, config, matches)
if not msg.reply_to_message then
return
end
user_id = msg.reply_to_message.from.id
if msg.reply_to_message.new_chat_member then
user_id = msg.reply_to_message.new_chat_member.id
elseif msg.reply_to_message.left_chat_member then
user_id = msg.reply_to_message.left_chat_member.id
else
user_id = msg.reply_to_message.from.id
end
end
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then
@ -220,7 +228,11 @@ function banhammer:action(msg, config, matches)
if not msg.reply_to_message then
return
end
user_id = msg.reply_to_message.from.id
if msg.reply_to_message.new_chat_member then
user_id = msg.reply_to_message.new_chat_member.id
else
user_id = msg.reply_to_message.from.id
end
end
banhammer:kick_user(user_id, msg.chat.id, self, true)
return
@ -249,7 +261,11 @@ function banhammer:action(msg, config, matches)
if not msg.reply_to_message then
return
end
local user_id = msg.reply_to_message.from.id
if msg.reply_to_message.new_chat_member then
user_id = msg.reply_to_message.new_chat_member.id
else
user_id = msg.reply_to_message.from.id
end
local hash = 'whitelist:user#id'..user_id
redis:set(hash, true)
utilities.send_reply(self, msg, 'User '..user_id..' whitelisted')
@ -260,7 +276,13 @@ function banhammer:action(msg, config, matches)
if not msg.reply_to_message then
return
end
local user_id = msg.reply_to_message.from.id
if msg.reply_to_message.new_chat_member then
user_id = msg.reply_to_message.new_chat_member.id
elseif msg.reply_to_message.left_chat_member then
user_id = msg.reply_to_message.left_chat_member.id
else
user_id = msg.reply_to_message.from.id
end
local hash = 'whitelist:user#id'..user_id
redis:del(hash)
utilities.send_reply(self, msg, 'User '..user_id..' von der Whitelist entfernt!')
@ -326,7 +348,13 @@ function banhammer:action(msg, config, matches)
if not msg.reply_to_message then
return
end
local user_id = msg.reply_to_message.from.id
if msg.reply_to_message.new_chat_member then
user_id = msg.reply_to_message.new_chat_member.id
elseif msg.reply_to_message.left_chat_member then
user_id = msg.reply_to_message.left_chat_member.id
else
user_id = msg.reply_to_message.from.id
end
local hash = 'blocked:'..user_id
redis:set(hash, true)
utilities.send_reply(self, msg, 'User '..user_id..' darf den Bot nun nicht mehr nutzen.')
@ -337,7 +365,13 @@ function banhammer:action(msg, config, matches)
if not msg.reply_to_message then
return
end
local user_id = msg.reply_to_message.from.id
if msg.reply_to_message.new_chat_member then
user_id = msg.reply_to_message.new_chat_member.id
elseif msg.reply_to_message.left_chat_member then
user_id = msg.reply_to_message.left_chat_member.id
else
user_id = msg.reply_to_message.from.id
end
local hash = 'blocked:'..user_id
redis:del(hash)
utilities.send_reply(self, msg, 'User '..user_id..' darf den Bot wieder nutzen.')

View File

@ -80,20 +80,20 @@ function stats:chat_stats(chat_id)
end
function stats:pre_process(msg, self)
-- Ignore service msg
if is_service_msg(msg) then
print('Service message')
return msg
end
if msg.left_chat_member then
-- delete user from redis set, but keep message count
local hash = 'chat:'..msg.chat.id..':users'
local user_id_left = msg.left_chat_member.id
print('User '..user_id_left..' was kicked, deleting him/her from redis set '..hash)
print('User '..user_id_left..' was kicked/left the chat, deleting them from redis set '..hash)
redis:srem(hash, user_id_left)
return msg
end
-- Ignore service msg
if is_service_msg(msg) then
print('Service message')
return msg
end
-- Save user on Redis
local hash = 'user:'..msg.from.id