From 5f010ca1eeab7831e832babee779339bbd8818bd Mon Sep 17 00:00:00 2001 From: Andreas Bielawski Date: Tue, 2 Aug 2016 16:19:20 +0200 Subject: [PATCH] =?UTF-8?q?-=20Neu:=20Settings-Plugin.=20Hier=20wird=20man?= =?UTF-8?q?=20in=20Zukunft=20einiges=20einstellen=20k=C3=B6nnen,=20momenta?= =?UTF-8?q?n=20wurde=20nur=20eine=20Einstellung=20zum...=20=20=20-=20AFK-K?= =?UTF-8?q?eyboard=20hinzugef=C3=BCgt.=20Wenn=20es=20eingeschaltet=20ist?= =?UTF-8?q?=20(=C3=BCber=20/settings),=20wird=20ein=20"Wieder=20da."=20But?= =?UTF-8?q?ton=20eingeblendet,=20mit=20dem=20man=20sich=20leicht=20wieder?= =?UTF-8?q?=20"online"=20schalten=20kann=20-=20Utilites:=20Bei=20makeHuman?= =?UTF-8?q?Tine()=20wird=20nun=20der=20Singular=20verwendet,=20wenn=20n?= =?UTF-8?q?=C3=B6tig=20("1=20Sekunde"=20statt=20"1=20Sekunden")?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- otouto/plugins/afk.lua | 13 +++++++-- otouto/plugins/settings.lua | 56 +++++++++++++++++++++++++++++++++++++ otouto/utilities.lua | 18 ++++++++++-- 3 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 otouto/plugins/settings.lua diff --git a/otouto/plugins/afk.lua b/otouto/plugins/afk.lua index bab7d6e..b25f028 100644 --- a/otouto/plugins/afk.lua +++ b/otouto/plugins/afk.lua @@ -84,9 +84,9 @@ function afk:pre_process(msg, self) redis:hset(hash, 'afk_text', false) 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 - 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 @@ -103,8 +103,15 @@ function afk:action(msg) local chat_id = msg.chat.id local user_name = get_name(msg) 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 return afk \ No newline at end of file diff --git a/otouto/plugins/settings.lua b/otouto/plugins/settings.lua new file mode 100644 index 0000000..b0997dc --- /dev/null +++ b/otouto/plugins/settings.lua @@ -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 \ No newline at end of file diff --git a/otouto/utilities.lua b/otouto/utilities.lua index 06931e1..a18c930 100644 --- a/otouto/utilities.lua +++ b/otouto/utilities.lua @@ -918,11 +918,23 @@ function makeHumanTime(totalseconds) local minutes = minutes % 60 local hours = math.floor(totalseconds / 3600) if minutes == 00 and hours == 00 then - return seconds..' Sekunden' + if seconds == 1 then + return seconds..' Sekunde' + else + return seconds..' Sekunden' + end elseif hours == 00 and minutes ~= 00 then - return string.format("%02d:%02d", minutes, seconds)..' Minuten' + if minutes == 1 then + return string.format("%02d:%02d", minutes, seconds)..' Minute' + else + return string.format("%02d:%02d", minutes, seconds)..' Minuten' + end elseif hours ~= 00 then - return string.format("%02d:%02d:%02d", hours, minutes, seconds)..' Stunden' + 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' + end end end