AFK Plugin nun mit Zeitangabe
This commit is contained in:
parent
af4d3fcba7
commit
1031849145
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ plugins/help2.lua
|
||||
plugins/pegelf_img.lua
|
||||
plugins/plex.lua
|
||||
plugins/chantalle.lua
|
||||
plugins/plex_xml.lua
|
@ -107,6 +107,7 @@ end
|
||||
|
||||
-- Apply plugin.pre_process function
|
||||
function pre_process_msg(msg)
|
||||
--for name,plugin in orderedPairs(plugins) do
|
||||
for name,plugin in pairs(plugins) do
|
||||
if plugin.pre_process and msg then
|
||||
-- print('Preprocess', name)
|
||||
|
@ -662,3 +662,9 @@ function cache_data(plugin, query, data, timeout, typ)
|
||||
end
|
||||
redis:expire(hash, timeout)
|
||||
end
|
||||
|
||||
function orderedPairs(t)
|
||||
-- Equivalent of the pairs() function on tables. Allows to iterate
|
||||
-- in order
|
||||
return orderedNext, t, nil
|
||||
end
|
@ -18,7 +18,7 @@ local function get_afk_text(hash)
|
||||
end
|
||||
end
|
||||
|
||||
local function switch_afk(user_name, user_id, chat_id, text)
|
||||
local function switch_afk(user_name, user_id, chat_id, timestamp, text)
|
||||
local hash = 'afk:'..chat_id..':'..user_id
|
||||
|
||||
if is_offline(hash) then
|
||||
@ -32,6 +32,8 @@ local function switch_afk(user_name, user_id, chat_id, text)
|
||||
|
||||
print('Setting redis hash afk in '..hash..' to true')
|
||||
redis:hset(hash, 'afk', true)
|
||||
print('Setting redis hash timestamp in '..hash..' to '..timestamp)
|
||||
redis:hset(hash, 'time', timestamp)
|
||||
|
||||
if text then
|
||||
print('Setting redis hash afk_text in '..hash..' to '..text)
|
||||
@ -57,12 +59,29 @@ local function pre_process(msg)
|
||||
|
||||
if is_offline(hash) then
|
||||
local afk_text = get_afk_text(hash)
|
||||
|
||||
-- calculate afk time
|
||||
local timestamp = redis:hget(hash, 'time')
|
||||
local current_timestamp = msg.date
|
||||
local afk_time = current_timestamp - timestamp
|
||||
local seconds = afk_time % 60
|
||||
local minutes = math.floor(afk_time / 60)
|
||||
local minutes = minutes % 60
|
||||
local hours = math.floor(afk_time / 3600)
|
||||
if minutes == 00 and hours == 00 then
|
||||
duration = seconds..' Sekunden'
|
||||
elseif hours == 00 and minutes ~= 00 then
|
||||
duration = string.format("%02d:%02d", minutes, seconds)..' Minuten'
|
||||
elseif hours ~= 00 then
|
||||
duration = string.format("%02d:%02d:%02d", hours, minutes, seconds)..' Stunden'
|
||||
end
|
||||
|
||||
redis:hset(hash, 'afk', false)
|
||||
if afk_text then
|
||||
redis:hset(hash, 'afk_text', false)
|
||||
send_msg(receiver, user_name..' ist wieder da! (war: '..afk_text..')', ok_cb, false)
|
||||
send_msg(receiver, user_name..' ist wieder da! (war: '..afk_text..' für '..duration..')', ok_cb, false)
|
||||
else
|
||||
send_msg(receiver, user_name..' ist wieder da!', ok_cb, false)
|
||||
send_msg(receiver, user_name..' ist wieder da! (war '..duration..' weg)', ok_cb, false)
|
||||
end
|
||||
end
|
||||
|
||||
@ -77,11 +96,12 @@ local function run(msg, matches)
|
||||
local user_id = msg.from.id
|
||||
local chat_id = msg.to.id
|
||||
local user_name = get_name(msg)
|
||||
local timestamp = msg.date
|
||||
|
||||
if matches[2] then
|
||||
return switch_afk(user_name, user_id, chat_id, matches[2])
|
||||
return switch_afk(user_name, user_id, chat_id, timestamp, matches[2])
|
||||
else
|
||||
return switch_afk(user_name, user_id, chat_id)
|
||||
return switch_afk(user_name, user_id, chat_id, timestamp)
|
||||
end
|
||||
end
|
||||
|
||||
|
Reference in New Issue
Block a user