- Neu: Settings-Plugin. Hier wird man in Zukunft einiges einstellen können, momentan wurde nur eine Einstellung zum...

- AFK-Keyboard hinzugefügt. Wenn es eingeschaltet ist (über /settings), wird ein "Wieder da." Button eingeblendet, mit dem man sich leicht wieder "online" schalten kann
- Utilites: Bei makeHumanTine() wird nun der Singular verwendet, wenn nötig ("1 Sekunde" statt "1 Sekunden")
This commit is contained in:
Andreas Bielawski 2016-08-02 16:19:20 +02:00
parent 49824fcb26
commit 5f010ca1ee
3 changed files with 81 additions and 6 deletions

View File

@ -84,9 +84,9 @@ function afk:pre_process(msg, self)
redis:hset(hash, 'afk_text', false) redis:hset(hash, 'afk_text', false)
local afk_text = afk_text:gsub("%*","") local afk_text = afk_text:gsub("%*","")
local afk_text = afk_text:gsub("_","") local afk_text = afk_text:gsub("_","")
utilities.send_message(self, msg.chat.id, user_name..' ist wieder da (war: *'..afk_text..'* für '..duration..')!', true, nil, true) utilities.send_reply(self, msg, user_name..' ist wieder da (war: *'..afk_text..'* für '..duration..')!', true, '{"hide_keyboard":true,"selective":true}')
else else
utilities.send_message(self, msg.chat.id, user_name..' ist wieder da (war '..duration..' weg)!') utilities.send_reply(self, msg, user_name..' ist wieder da (war '..duration..' weg)!', false, '{"hide_keyboard":true,"selective":true}')
end end
end end
@ -103,8 +103,15 @@ function afk:action(msg)
local chat_id = msg.chat.id local chat_id = msg.chat.id
local user_name = get_name(msg) local user_name = get_name(msg)
local timestamp = msg.date local timestamp = msg.date
local uhash = 'user:'..msg.from.id
local show_afk_keyboard = redis:hget(uhash, 'afk_keyboard')
if show_afk_keyboard == 'true' then
keyboard = '{"keyboard":[[{"text":"Wieder da."}]], "one_time_keyboard":true, "selective":true, "resize_keyboard":true}'
else
keyboard = nil
end
utilities.send_reply(self, msg, afk:switch_afk(user_name, user_id, chat_id, timestamp, matches[2])) utilities.send_reply(self, msg, afk:switch_afk(user_name, user_id, chat_id, timestamp, matches[2]), false, keyboard)
end end
return afk return afk

View File

@ -0,0 +1,56 @@
local settings = {}
settings.triggers = {
"^(⚙ [Ee]instellungen)$",
"^(/settings)$",
"^(💤 [Aa][Ff][Kk]%-[Kk]eyboard einschalten)",
"^(💤 [Aa][Ff][Kk]%-[Kk]eyboard ausschalten)",
"^(❌ [Ee]instellungen verstecken)"
}
--[[
[
[ "Top Left", "Top Right" ],
[ "Bottom Left", "Bottom Right" ]
]
]]
function settings:keyboard(user_id)
if redis:hget('user:'..user_id, 'afk_keyboard') == 'true' then
afk_button = '{"text":"💤 AFK-Keyboard ausschalten"}'
else
afk_button = '{"text":"💤 AFK-Keyboard einschalten"}'
end
local hide_settings_button = '{"text":"❌ Einstellungen verstecken"}'
local settings_keyboard = '[['..afk_button..','..hide_settings_button..']]'
return settings_keyboard
end
function settings:action(msg, config, matches)
if msg.chat.type ~= "private" then
return
end
local hash = 'user:'..msg.from.id
if matches[1] == '⚙ Einstellungen' or matches[1] == '/settings' then
utilities.send_reply(self, msg, 'Was möchtest du einstellen?', false, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}')
return
elseif matches[1] == '💤 AFK-Keyboard einschalten' then
redis:hset(hash, 'afk_keyboard', 'true')
utilities.send_reply(self, msg, 'Das AFK-Keyboard wurde erfolgreich *eingeschaltet*.', true, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}')
return
elseif matches[1] == '💤 AFK-Keyboard ausschalten' then
redis:hset(hash, 'afk_keyboard', 'false')
utilities.send_reply(self, msg, 'Das AFK-Keyboard wurde erfolgreich *ausgeschaltet*.', true, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}')
return
elseif matches[1] == '❌ Einstellungen verstecken' then
utilities.send_reply(self, msg, 'Um die Einstellungen wieder einzublenden, führe /settings aus.', true, '{"hide_keyboard":true}')
return
end
end
return settings

View File

@ -918,13 +918,25 @@ function makeHumanTime(totalseconds)
local minutes = minutes % 60 local minutes = minutes % 60
local hours = math.floor(totalseconds / 3600) local hours = math.floor(totalseconds / 3600)
if minutes == 00 and hours == 00 then if minutes == 00 and hours == 00 then
if seconds == 1 then
return seconds..' Sekunde'
else
return seconds..' Sekunden' return seconds..' Sekunden'
end
elseif hours == 00 and minutes ~= 00 then elseif hours == 00 and minutes ~= 00 then
if minutes == 1 then
return string.format("%02d:%02d", minutes, seconds)..' Minute'
else
return string.format("%02d:%02d", minutes, seconds)..' Minuten' return string.format("%02d:%02d", minutes, seconds)..' Minuten'
end
elseif hours ~= 00 then elseif hours ~= 00 then
if hours == 1 then
return string.format("%02d:%02d:%02d", hours, minutes, seconds)..' Stunde'
else
return string.format("%02d:%02d:%02d", hours, minutes, seconds)..' Stunden' return string.format("%02d:%02d:%02d", hours, minutes, seconds)..' Stunden'
end end
end end
end
function is_blacklisted(msg) function is_blacklisted(msg)
_blacklist = redis:smembers("telegram:img_blacklist") _blacklist = redis:smembers("telegram:img_blacklist")