From 6710869e5f562820bb0d5071d8ce2b1a6329b5d5 Mon Sep 17 00:00:00 2001 From: Akamaru Date: Sat, 14 Nov 2015 23:49:52 +0100 Subject: [PATCH] =?UTF-8?q?text=5Fset=20und=20text=5Fgut=20wurden=20nun=20?= =?UTF-8?q?auf=20basis=20des=20zitate=20plugins=20zusammengef=C3=BChrt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/{ => pluginsold}/text_get.lua | 0 plugins/{ => pluginsold}/text_set.lua | 0 plugins/saved_text.lua | 86 +++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) rename plugins/{ => pluginsold}/text_get.lua (100%) rename plugins/{ => pluginsold}/text_set.lua (100%) create mode 100644 plugins/saved_text.lua diff --git a/plugins/text_get.lua b/plugins/pluginsold/text_get.lua similarity index 100% rename from plugins/text_get.lua rename to plugins/pluginsold/text_get.lua diff --git a/plugins/text_set.lua b/plugins/pluginsold/text_set.lua similarity index 100% rename from plugins/text_set.lua rename to plugins/pluginsold/text_set.lua diff --git a/plugins/saved_text.lua b/plugins/saved_text.lua new file mode 100644 index 0000000..be0bf93 --- /dev/null +++ b/plugins/saved_text.lua @@ -0,0 +1,86 @@ +do + +local function save_text(msg) + if msg.text:sub(10):isempty() then + return "Benutzung: /addtext [Text]" + end + + local savedtext = msg.text:sub(10) + local hash = 'telegram:savedtext' + print('Saving text to redis set '..hash) + redis:sadd(hash, savedtext) + return 'Gespeichert: "'..savedtext..'"' +end + +local function delete_text(msg) + if msg.text:sub(10):isempty() then + return "Benutzung: /delquote [Text]" + end + + local savedtext = msg.text:sub(10) + local hash = 'telegram:savedtext' + print('Deleting text from redis set '..hash) + if redis:sismember(hash, savedtext) == true then + redis:srem(hash, savedtext) + return 'Text erfolgreich gelöscht!' + else + return 'Dieser Text existiert nicht.' + end +end + +local function get_text(msg) + local to_id = tostring(msg.to.id) + local hash = 'telegram:savedtext' + + if hash then + print('Getting text from redis set '..hash) + local text_table = redis:smembers(hash) + if not text_table[1] then + return 'Es wurden noch kein Text gespeichert.\nSpeichere doch einen mit /addtext [Text]' + else + return text_table[math.random(1,#text_table)] + end + end +end + +local function list_text(msg) + local hash = 'telegram:savedtext' + + if hash then + print('Getting text from redis set '..hash) + local text_table = redis:smembers(hash) + local text = "" + for num,savedtext in pairs(text_table) do + text = text..num..") "..savedtext..'\n' + end + if not text or text == "" then + return 'Es wurden noch kein Text gespeichert.\nSpeichere doch einen mit /addtext [Text]' + else + return text + end + end +end + +local function run(msg, matches) + if matches[1] == "addtext" then + return save_text(msg) + elseif matches[1] == "deltext" then + return delete_text(msg) + elseif matches[1] == "listtext" then + return list_text(msg) + end +end + +return { + description = "", + usage = {}, + patterns = { + "^/(deltext) (.+)$", + "^/(addtext) (.+)$", + "^/(listtext)$" + }, + run = run, + privileged = true +} + +end \ No newline at end of file