Neue Plugins: copypasta.lua & instagram.lua

This commit is contained in:
Akamaru 2016-11-22 15:45:46 +01:00
parent 0334188aab
commit 5b09f7dba0
2 changed files with 173 additions and 0 deletions

125
miku/plugins/copypasta.lua Normal file
View File

@ -0,0 +1,125 @@
local pasta = {}
function pasta:init(config)
pasta.triggers = {
"^/(delpasta) (.+)$",
"^/(addpasta) (.+)$",
"^/(pasta)$",
"^/(listpasta)$",
"^/(delpasta)$"
}
pasta.doc = [[*
]]..config.cmd_pat..[[addpasta* _<Zitat>_: Fügt Zitat hinzu.
*]]..config.cmd_pat..[[delpasta* _<Zitat>_: 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

View File

@ -0,0 +1,48 @@
local instagram = {}
function instagram:init(config)
instagram.triggers = {
"https?://www.instagram.com/p/(.*)"
}
end
function instagram:get_instagram(url)
local api_key = cred_data.iframely_api_key
local res, code = https.request('https://iframe.ly/api/oembed?url=https://www.instagram.com/p/'..URL.escape(url)..'&api_key='..api_key)
if code ~= 200 then return end
local data = json.decode(res)
if data.title then
title = data.title:gsub('"', '\\"')
else
title = 'Kein Titel'
end
if data.description then
description = data.description:gsub('"', '\\"')
description_in_text = '\n'..description
else
description_in_text = ''
description = 'Keine Beschreibung verfügbar'
end
local pic = data.thumbnail_url
local text = title..'\n'..description_in_text
return pic, text
end
function instagram:action(msg, config, matches)
local url = matches[1]
local pic, text = instagram:get_instagram(url)
if not url then
utilities.send_reply(msg, 'Fehler')
return
end
utilities.send_typing(msg.chat.id, 'upload_photo')
utilities.send_photo(msg.chat.id, pic, text, msg.message_id)
end
return instagram