Fixes & Verbesserungen

-download_to_file in paar Plugins entfernt
-Antworte auf Nachrichten
-Stabilitätsverbesserungen
This commit is contained in:
Akamaru 2016-12-15 19:24:08 +01:00
parent 90eb1add06
commit cddb7e03ab
13 changed files with 58 additions and 112 deletions

View File

@ -22,7 +22,7 @@ function about:init(config)
end end
function about:action(msg, config) function about:action(msg, config)
utilities.send_message(msg.chat.id, about.text, true, nil, true) utilities.send_message(msg.chat.id, about.text, true, msg.message_id, true)
end end
return about return about

View File

@ -11,30 +11,27 @@ function figuya:get_figuya(figu)
if c ~= 200 then return nil end if c ~= 200 then return nil end
local data = json.decode(b) local data = json.decode(b)
local title = '*'..data.title..'*' local title = data.title
local desc = '\n'..unescape(data.description) if string.len(data.description) > 400 then
desc = string.sub(unescape(data.description:gsub("%b<>", "")), 1, 400)..'..'
else
desc = unescape(data.description)..'.'
end
local pic = data.thumbnail_url local pic = data.thumbnail_url
local text = title..desc local text = '<b>'..title..'</b>\n<i>'..desc..'</i>'..'<a href="'..pic..'">.</a>'
if string.len(text) > 200 then return text
text = string.sub(unescape(text:gsub("%b<>", "")), 1, 197)..'...'
else
text = text
end
return text, pic
end end
function figuya:action(msg, config, matches) function figuya:action(msg, config, matches)
local figu = matches[1] local figu = matches[1]
local text, pic = figuya:get_figuya(figu) local text = figuya:get_figuya(figu)
if not text then if not text then
utilities.send_reply(msg, config.errors.results) utilities.send_reply(msg, config.errors.results)
return return
end end
utilities.send_typing(receiver, 'upload_photo') utilities.send_message(msg.chat.id, text, false, msg.message_id, 'html')
utilities.send_photo(msg.chat.id, pic, text)
end end
return figuya return figuya

View File

@ -72,8 +72,7 @@ function playstation_store:action(msg, config, matches)
end end
if image_url then if image_url then
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(image_url) utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
end end
utilities.send_reply(msg, text, 'HTML') utilities.send_reply(msg, text, 'HTML')
end end

View File

@ -39,7 +39,7 @@ function plex:get_plex(query)
local ok, response_code, response_headers, response_status_line = http.request(request_constructor) local ok, response_code, response_headers, response_status_line = http.request(request_constructor)
if not ok then return 'NOTOK' end if not ok then return 'NOTOK' end
local data = json.decode(table.concat(response_body)).MediaContainer.Metadata[1] local data = json.decode(table.concat(response_body)).MediaContainer.Metadata[1]
local title = '<b>'..data.title..'</b>' local title = '<b>'..data.title..'</b>'
if data.tagline then if data.tagline then
@ -159,12 +159,7 @@ function plex:get_plex(query)
text = title..from..studio..date1..episodes..fsk..duration..rating..desc text = title..from..studio..date1..episodes..fsk..duration..rating..desc
end end
if string.match(title, 'Local Network') then
return 'Nichts gefunden!'
else
return text, pic, data.title return text, pic, data.title
end
end end
function plex:inline_callback(inline_query, config, matches) function plex:inline_callback(inline_query, config, matches)
@ -196,7 +191,7 @@ function plex:action(msg, config)
if pic then if pic then
utilities.send_typing(receiver, 'upload_photo') utilities.send_typing(receiver, 'upload_photo')
local file = download_to_file(pic, 'plex.png') local file = download_to_file(pic, 'plex.png')
utilities.send_photo(msg.chat.id, file) utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
end end
utilities.send_reply(msg, text, 'HTML') utilities.send_reply(msg, text, 'HTML')
end end

View File

@ -9,15 +9,6 @@ function pokedex:init(config)
]] ]]
end end
function pokedex:get_sprite(path)
local url = "http://pokeapi.co/"..path
local b, c = http.request(url)
if c ~= 200 then return nil end
local data = json.decode(b)
local image = data.image
return image
end
function pokedex:get_pkmn(query) function pokedex:get_pkmn(query)
local url = "http://pokeapi.co/api/v1/pokemon/" .. query .. "/" local url = "http://pokeapi.co/api/v1/pokemon/" .. query .. "/"
local res, code = http.request(url) local res, code = http.request(url)
@ -39,21 +30,22 @@ function pokedex:get_pkmn(query)
end end
function pokedex:action(msg, config) function pokedex:action(msg, config)
local input = utilities.input_from_msg(msg) local query = utilities.input_from_msg(msg)
if not input then if not query then
utilities.send_reply(msg, pokedex.doc, true) utilities.send_reply(msg, pokedex.doc, true)
return return
end end
utilities.send_typing(msg.chat.id, 'typing') utilities.send_typing(msg.chat.id, 'typing')
local text, id = pokedex:get_pkmn(input) local text, id = pokedex:get_pkmn(query)
local image = 'http://pokeapi.co/media/img/'..id..'.png'
if not text then if not text then
utilities.send_reply(msg, config.errors.result) utilities.send_reply(msg, config.errors.result)
return return
end end
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
utilities.send_photo(msg.chat.id, download_to_file('http://pokeapi.co/media/img/'..id..'.png'), nil, msg.message_id) utilities.send_photo(msg.chat.id, image, nil, msg.message_id)
utilities.send_reply(msg, text, 'HTML') utilities.send_reply(msg, text, 'HTML')
end end

View File

@ -20,37 +20,39 @@ function ponyfaces:get_ponyface_by_id(id)
if code ~= 200 then return nil end if code ~= 200 then return nil end
local data = json.decode(res) local data = json.decode(res)
if not data then return nil end if not data then return nil end
return data.faces[1].image local link = 'http://ponyfac.es/'..data.faces[1].id
local pic = data.faces[1].image
return link, pic
end end
function ponyfaces:get_ponyface(tag) function ponyfaces:get_ponyface(tag)
local url = BASE_URL..'/tag:'..tag local url = BASE_URL..'/tag:'..tag
local res, code = http.request(url) local res, code = http.request(url)
if code ~= 200 then return nil end if code ~= 200 then return nil end
local pf = json.decode(res).faces local data = json.decode(res).faces
-- truly randomize -- truly randomize
math.randomseed(os.time()) math.randomseed(os.time())
-- random max json table size -- random max json table size
local i = math.random(#pf) local i = math.random(#data)
local link_image = pf[i].image local link = 'http://ponyfac.es/'..data[i].id
return link_image local pic = data[i].image
return link, pic
end end
function ponyfaces:action(msg, config, matches) function ponyfaces:action(msg, config, matches)
if tonumber(matches[1]) ~= nil then if tonumber(matches[1]) ~= nil then
local id = matches[1] local id = matches[1]
url = ponyfaces:get_ponyface_by_id(id) link, pic = ponyfaces:get_ponyface_by_id(id)
else else
local tag = matches[1] local tag = matches[1]
url = ponyfaces:get_ponyface(tag) link, pic = ponyfaces:get_ponyface(tag)
end end
if not url then if not pic then
utilities.send_reply(msg, config.errors.results) utilities.send_reply(msg, config.errors.results)
return return
end end
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(url, 'pf.png') utilities.send_photo(msg.chat.id, pic, link, msg.message_id)
utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
end end
return ponyfaces return ponyfaces

View File

@ -1,32 +0,0 @@
local pornhub = {}
function pornhub:init(config)
pornhub.triggers = {
"pornhub.com/gif/(.+)$",
"^/phg (.+)$",
"^/porngif (.+)$"
}
pornhub.doc = [[*
]]..config.cmd_pat..[[phg* _<ID>_: Sendet GIF von PornHub (NSFW)]]
end
pornhub.command = 'ge <ID>'
function pornhub:action(msg, config, matches)
local url = 'http://img.pornhub.com/gif/'..matches[1]..'.gif'
utilities.send_typing(msg.chat.id, 'upload_document')
local file = download_to_file(url)
if not file then
utilities.send_reply(msg, config.errors.results)
return
end
if string.starts(msg.text_lower, '/phg') or string.starts(msg.text_lower, '/porngif') then
source = 'http://www.pornhub.com/gif/'..matches[1]
else
source = nil
end
utilities.send_document(msg.chat.id, file, source, msg.message_id)
end
return pornhub

View File

@ -31,12 +31,11 @@ function pr0gramm:action(msg, config, matches)
return return
end end
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_document')
local file = download_to_file(url)
if string.match(url, ".gif") or string.match(url, ".zip") or string.match(url, ".webm") or string.match(url, ".mp4") then if string.match(url, ".gif") or string.match(url, ".zip") or string.match(url, ".webm") or string.match(url, ".mp4") then
utilities.send_document(msg.chat.id, file, nil, msg.message_id) utilities.send_document(msg.chat.id, url, nil, msg.message_id)
else else
utilities.send_photo(msg.chat.id, file, nil, msg.message_id) utilities.send_photo(msg.chat.id, url, nil, msg.message_id)
end end
end end

View File

@ -103,7 +103,7 @@ function quotes:action(msg, config, matches)
end end
if matches[1] == "quote" then if matches[1] == "quote" then
utilities.send_message(msg.chat.id, quotes:get_quote(msg), true, nil, false) utilities.send_message(msg.chat.id, quotes:get_quote(msg), true, msg.message_id, false)
return return
elseif matches[1] == "addquote" and matches[2] then elseif matches[1] == "addquote" and matches[2] then
utilities.send_reply(msg, quotes:save_quote(msg), true) utilities.send_reply(msg, quotes:save_quote(msg), true)

View File

@ -25,9 +25,9 @@ function rule34:get_r34_info(tag)
local i = math.random(#r34) local i = math.random(#r34)
local url = 'http:'..r34[i].file_url local img_url = 'http:'..r34[i].file_url
local source_url = 'http://rule34.xxx/index.php?page=post&s=view&id='..r34[i].id local source_url = 'http://rule34.xxx/index.php?page=post&s=view&id='..r34[i].id
return url, source_url return img_url, source_url
end end
function rule34:get_r34_post(id) function rule34:get_r34_post(id)
@ -51,32 +51,29 @@ function rule34:action(msg, config, matches)
utilities.send_reply(msg, 'Nobody here but us chickens!') utilities.send_reply(msg, 'Nobody here but us chickens!')
return return
end end
utilities.send_typing(msg.chat.id, 'upload_photo')
local file = download_to_file(img_url)
if string.ends(img_url, ".gif") then if string.ends(img_url, ".gif") then
utilities.send_document(msg.chat.id, file, nil, msg.message_id) utilities.send_typing(msg.chat.id, 'upload_document')
utilities.send_document(msg.chat.id, img_url, nil, msg.message_id)
else else
utilities.send_photo(msg.chat.id, file, nil, msg.message_id) utilities.send_typing(msg.chat.id, 'upload_photo')
utilities.send_photo(msg.chat.id, img_url, nil, msg.message_id)
end end
else else
local tag = string.gsub(matches[1], " ", '_') local tag = string.gsub(matches[1], " ", '_')
local tag = string.gsub(tag, ":", '%%3A') local tag = string.gsub(tag, ":", '%%3A')
local tag = string.gsub(tag, "+", '%%2B') local tag = string.gsub(tag, "+", '%%2B')
local url, id = rule34:get_r34_info(tag) local img_url, source_url = rule34:get_r34_info(tag)
if not url then if not img_url then
utilities.send_reply(msg, 'Nobody here but us chickens!') utilities.send_reply(msg, 'Nobody here but us chickens!')
return return
end end
utilities.send_typing(msg.chat.id, 'upload_photo') if string.ends(img_url, ".gif") then
local file = download_to_file(url) utilities.send_typing(msg.chat.id, 'upload_document')
if string.ends(url, ".gif") then utilities.send_document(msg.chat.id, img_url, source_url, msg.message_id)
utilities.send_document(msg.chat.id, file, id, msg.message_id)
else else
utilities.send_photo(msg.chat.id, file, id, msg.message_id) utilities.send_typing(msg.chat.id, 'upload_photo')
utilities.send_photo(msg.chat.id, img_url, source_url, msg.message_id)
end end
end end
end end

View File

@ -17,20 +17,19 @@ end
soundboard.command = 'sound <Sound>' soundboard.command = 'sound <Sound>'
local BASE_URL = 'http://code.ponywave.de/workspace/mikubot/sounds' local BASE_URL = 'http://code.ponywave.de/workspace/mikubot/sounds'
--local BASE_URL = 'http://kyouko.local/sounds'
local GRONKH_URL = 'http://code.ponywave.de/workspace/mikubot/gronkhsounds' local GRONKH_URL = 'http://code.ponywave.de/workspace/mikubot/gronkhsounds'
function soundboard:inline_callback(inline_query, config, matches) function soundboard:inline_callback(inline_query, config, matches)
local board = matches[1] local board = matches[1]
local input = matches[2] local input = matches[2]
if board == 'sound' then if board == 'sound' then
url = BASE_URL..'/'..string.lower(input)..'.mp3' sound = BASE_URL..'/'..string.lower(input)..'.mp3'
elseif board == 'gronkh' then elseif board == 'gronkh' then
url = GRONKH_URL..'/'..string.lower(input)..'.mp3' sound = GRONKH_URL..'/'..string.lower(input)..'.mp3'
end end
local _, code = get_http_header(url) local _, code = get_http_header(sound)
if code ~= 200 then utilities.answer_inline_query(inline_query, nil, 5, true) return end if code ~= 200 then utilities.answer_inline_query(inline_query, nil, 5, true) return end
local results = '[{"type":"audio","id":"7900","title":"'..input..'","audio_url":"'..url..'"}]' local results = '[{"type":"audio","id":"7900","title":"'..input..'","audio_url":"'..sound..'"}]'
utilities.answer_inline_query(inline_query, results, 2) utilities.answer_inline_query(inline_query, results, 2)
end end
@ -49,17 +48,16 @@ function soundboard:action(msg, config, matches)
end end
if board == 'sound' then if board == 'sound' then
url = BASE_URL..'/'..string.lower(input)..'.mp3' sound = BASE_URL..'/'..string.lower(input)..'.mp3'
elseif board == 'gronkh' then elseif board == 'gronkh' then
url = GRONKH_URL..'/'..string.lower(input)..'.mp3' sound = GRONKH_URL..'/'..string.lower(input)..'.mp3'
end end
local sound = download_to_file(url)
if not sound then if not sound then
utilities.send_reply(msg, config.errors.results) utilities.send_reply(msg, config.errors.results)
return return
end end
utilities.send_audio(msg.chat.id, sound, msg.message_id) utilities.send_audio(msg.chat.id, sound, nil, msg.message_id)
end end
return soundboard return soundboard

View File

@ -25,7 +25,7 @@ special.triggers = {
"^[Nn][Aa][Nn][Oo] [Hh][Aa][Kk][Aa][Ss][Ee]$", "^[Nn][Aa][Nn][Oo] [Hh][Aa][Kk][Aa][Ss][Ee]$",
"^/[Tt][Hh][Yy][Mm][Ee]$", "^/[Tt][Hh][Yy][Mm][Ee]$",
"^[Yy][Oo][Ll][Oo]$", "^[Yy][Oo][Ll][Oo]$",
"[Ii] [Ww][Ii][Ss][Hh] [Ss][Qq][Uu][Ii][Dd][Ss] [Ww][Ee][Rr][Ee] [Rr][Ee][Aa][Ll]", "^[Ii] [Ww][Ii][Ss][Hh] [Ss][Qq][Uu][Ii][Dd][Ss] [Ww][Ee][Rr][Ee] [Rr][Ee][Aa][Ll]$",
"^/[Kk][Ii][Ll][Ll] (.*)", "^/[Kk][Ii][Ll][Ll] (.*)",
"^[Pp][Ee]$", "^[Pp][Ee]$",
"^[Vv][Aa]$", "^[Vv][Aa]$",

View File

@ -29,8 +29,7 @@ function spotify:send_track_data(data, msg)
local text = '<b>'..name..'</b> von <b>'..artist..'</b> aus dem Album <b>'..album..'</b> <i>('..duration..')</i>' local text = '<b>'..name..'</b> von <b>'..artist..'</b> aus dem Album <b>'..album..'</b> <i>('..duration..')</i>'
if preview then if preview then
utilities.send_typing(msg.chat.id, 'upload_audio') utilities.send_typing(msg.chat.id, 'upload_audio')
local file = download_to_file(preview, name..'.mp3') utilities.send_audio(msg.chat.id, preview, 'Aus dem Album "'..album..'"\nLänge: '..duration, msg.message_id, 30, artist, name)
utilities.send_audio(msg.chat.id, file, 'Aus dem Album "'..album..'"\nLänge: '..duration, msg.message_id, 30, artist, name)
else else
utilities.send_reply(msg, text, 'HTML') utilities.send_reply(msg, text, 'HTML')
end end