local pasta = {} function pasta:init(config) pasta.triggers = { "^/(delpasta) (.+)$", "^/(addpasta) (.+)$", "^/(pasta)$", "^/(listpasta)$", "^/(delpasta)$" } pasta.doc = [[* ]]..config.cmd_pat..[[addpasta* __: Fügt Zitat hinzu. *]]..config.cmd_pat..[[delpasta* __: Löscht das Zitat (nur Superuser) *]]..config.cmd_pat..[[pasta*: Gibt zufälliges Zitat aus *]]..config.cmd_pat..[[listpasta*: Listet alle Zitate auf ]] end pasta.command = 'pasta' local hash = 'telegram:pasta' function pasta:save_pasta(text) local copypasta = text:sub(11) print('Saving pasta to redis set '..hash) redis:sadd(hash, copypasta) return '*Gespeichert!*' end function pasta:delete_pasta(text) local copypasta = text:sub(11) if redis:sismember(hash, quote) == true then print('Deleting pasta from redis set '..hash) redis:srem(hash, quote) return '*Copypasta erfolgreich gelöscht!*' else return 'Diese Copypasta existiert nicht.' end end function pasta:get_pasta() print('Getting pasta from redis set '..hash) local pasta_table = redis:smembers(hash) if not pasta_table[1] then return 'Es wurden noch keine Copypastas gespeichert.\nSpeichere doch welche mit /addpasta [Zitat]' else return pasta_table[math.random(1,#pasta_table)] end end function pasta:callback(callback, msg, self, config) print('Getting all pastas from redis set '..hash) local pasta_table = redis:smembers(hash) local text = "" for num,quote in pairs(pasta_table) do text = text..num..") "..quote..'\n' end if not text or text == "" then utilities.answer_callback_query(callback, 'Es wurden noch keine Copypastas gespeichert.', true) else -- In case the copypasta list is > 4096 chars local text_len = string.len(text) while text_len > 4096 do to_send_text = string.sub(text, 1, 4096) text = string.sub(text, 4096, text_len) local res = utilities.send_message(callback.from.id, to_send_text, true) if not res then utilities.answer_callback_query(callback, 'Bitte starte den Bot zuerst privat!', true) return end text_len = string.len(text) end local res = utilities.send_message(callback.from.id, text, true) if not res then utilities.answer_callback_query(callback, 'Bitte starte den Bot zuerst privat!', true) return end utilities.answer_callback_query(callback, 'Pastas per PN verschickt') end end function pasta:action(msg, config, matches) if msg.chat.type == 'private' then utilities.send_reply(msg, 'Dieses Plugin kann nur in Gruppen verwendet werden!') return end if matches[1] == "pasta" then utilities.send_message(msg.chat.id, pasta:get_pasta(), true, nil, false) return elseif matches[1] == "addpasta" and matches[2] then utilities.send_reply(msg, pasta:save_pasta(msg.text), true) return elseif matches[1] == "delpasta" and matches[2] then if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end utilities.send_reply(msg, pasta:delete_pasta(msg.text), true) return elseif matches[1] == "delpasta" and not matches[2] then if not is_sudo(msg, config) then utilities.send_reply(msg, config.errors.sudo) return end if msg.reply_to_message then local text = msg.reply_to_message.text utilities.send_reply(msg, pasta:delete_pasta(text), true) return end elseif matches[1] == "listpasta" then utilities.send_reply(msg, 'Bitte klicke hier unten auf diese attraktive Schaltfläche.', false, '{"inline_keyboard":[[{"text":"Alle Zitate per PN","callback_data":"copypasta:"}]]}') return end utilities.send_reply(msg, pasta.doc, true) end return pasta