Merge Upstream
This commit is contained in:
commit
d4ed80a288
@ -3,7 +3,7 @@ local bot = {}
|
|||||||
bindings = require('miku.bindings')
|
bindings = require('miku.bindings')
|
||||||
utilities = require('miku.utilities')
|
utilities = require('miku.utilities')
|
||||||
|
|
||||||
bot.version = '160815'
|
bot.version = '160816'
|
||||||
|
|
||||||
function bot:init(config) -- The function run when the bot is started or reloaded.
|
function bot:init(config) -- The function run when the bot is started or reloaded.
|
||||||
cred_data = load_cred()
|
cred_data = load_cred()
|
||||||
|
@ -47,6 +47,9 @@ function banhammer:kick_user(user_id, chat_id, self, onlykick)
|
|||||||
chat_id = chat_id,
|
chat_id = chat_id,
|
||||||
user_id = user_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 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
|
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!'
|
return 'User '..user_id..' gebannt!'
|
||||||
@ -173,8 +176,7 @@ end
|
|||||||
|
|
||||||
function banhammer:action(msg, config, matches)
|
function banhammer:action(msg, config, matches)
|
||||||
if not is_sudo(msg, config) then
|
if not is_sudo(msg, config) then
|
||||||
utilities.send_reply(self, msg, config.errors.sudo)
|
return -- Silent ignore
|
||||||
return
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if matches[1] == 'leave' then
|
if matches[1] == 'leave' then
|
||||||
@ -193,7 +195,13 @@ function banhammer:action(msg, config, matches)
|
|||||||
if not msg.reply_to_message then
|
if not msg.reply_to_message then
|
||||||
return
|
return
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
if msg.chat.type == 'group' or msg.chat.type == 'supergroup' then
|
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
|
if not msg.reply_to_message then
|
||||||
return
|
return
|
||||||
end
|
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
|
end
|
||||||
banhammer:kick_user(user_id, msg.chat.id, self, true)
|
banhammer:kick_user(user_id, msg.chat.id, self, true)
|
||||||
return
|
return
|
||||||
@ -249,7 +261,11 @@ function banhammer:action(msg, config, matches)
|
|||||||
if not msg.reply_to_message then
|
if not msg.reply_to_message then
|
||||||
return
|
return
|
||||||
end
|
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
|
local hash = 'whitelist:user#id'..user_id
|
||||||
redis:set(hash, true)
|
redis:set(hash, true)
|
||||||
utilities.send_reply(self, msg, 'User '..user_id..' whitelisted')
|
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
|
if not msg.reply_to_message then
|
||||||
return
|
return
|
||||||
end
|
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
|
local hash = 'whitelist:user#id'..user_id
|
||||||
redis:del(hash)
|
redis:del(hash)
|
||||||
utilities.send_reply(self, msg, 'User '..user_id..' von der Whitelist entfernt!')
|
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
|
if not msg.reply_to_message then
|
||||||
return
|
return
|
||||||
end
|
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
|
local hash = 'blocked:'..user_id
|
||||||
redis:set(hash, true)
|
redis:set(hash, true)
|
||||||
utilities.send_reply(self, msg, 'User '..user_id..' darf den Bot nun nicht mehr nutzen.')
|
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
|
if not msg.reply_to_message then
|
||||||
return
|
return
|
||||||
end
|
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
|
local hash = 'blocked:'..user_id
|
||||||
redis:del(hash)
|
redis:del(hash)
|
||||||
utilities.send_reply(self, msg, 'User '..user_id..' darf den Bot wieder nutzen.')
|
utilities.send_reply(self, msg, 'User '..user_id..' darf den Bot wieder nutzen.')
|
||||||
|
@ -80,21 +80,21 @@ function stats:chat_stats(chat_id)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function stats:pre_process(msg, self)
|
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
|
if msg.left_chat_member then
|
||||||
-- delete user from redis set, but keep message count
|
-- delete user from redis set, but keep message count
|
||||||
local hash = 'chat:'..msg.chat.id..':users'
|
local hash = 'chat:'..msg.chat.id..':users'
|
||||||
local user_id_left = msg.left_chat_member.id
|
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)
|
redis:srem(hash, user_id_left)
|
||||||
return msg
|
return msg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Ignore service msg
|
||||||
|
if is_service_msg(msg) then
|
||||||
|
print('Service message')
|
||||||
|
return msg
|
||||||
|
end
|
||||||
|
|
||||||
-- Save user on Redis
|
-- Save user on Redis
|
||||||
local hash = 'user:'..msg.from.id
|
local hash = 'user:'..msg.from.id
|
||||||
-- print('Saving user', hash) -- remove comment to restore old behaviour
|
-- print('Saving user', hash) -- remove comment to restore old behaviour
|
||||||
|
Reference in New Issue
Block a user