new plugins

dmm.lua
ehentai.lua
minecraft.lua
This commit is contained in:
Akamaru 2015-05-07 19:47:06 +02:00
parent 41c18ef046
commit 3f5313f1c2
4 changed files with 249 additions and 0 deletions

60
plugins/dmm.lua Normal file
View File

@ -0,0 +1,60 @@
do
function get_videos(html)
local videos = {}
for p in html:gmatch("<p class=\"tmb\">.-<div class=\"value\">") do
table.insert(videos, {
link = p:match("href=\"(.-)\""):gsub("?.*", ""),
img = p:match("src=\"(.-)\""):gsub("pt.jpg", "pl.jpg"),
title = p:match("alt=\"(.-)\""),
name = p:match("<p class=\"sublink\">(.*)"):gsub("<.->", ""):match("^%s*(.-)%s*$")
})
end
return videos
end
function get_dmm(rawid)
local label, num = string.match(rawid, "(%a+).-(%d+)")
local id = string.format("%s%05d", label:lower(), num)
local res, code = http.request("http://www.dmm.co.jp/search/=/searchstr="..id)
if code ~= 200 then return "HTTP ERROR" end
return get_videos(res)[1]
end
function get_dmm_random()
local res, code = http.request("http://www.dmm.co.jp/digital/videoa/-/list/=/sort=ranking/")
if code ~= 200 then return "HTTP ERROR" end
local videos = get_videos(res)
return videos[math.random(1, #videos)]
end
function send_title(cb_extra, success, result)
if success then
local message = cb_extra[2] .. "\n" .. cb_extra[3] .. "\n" ..cb_extra[4]
send_msg(cb_extra[1], message, ok_cb, false)
end
end
function run(msg, matches)
local receiver = get_receiver(msg)
if matches[1] == "/dmm" then
video = get_dmm_random()
else
video = get_dmm(matches[1])
end
file_path = download_to_file(video.img)
send_photo(receiver, file_path, send_title, {receiver, video.title, video.name, video.link})
return false
end
return {
description = "Send dmm video info",
usage = {"/dmm (id): Send a dmm video cover and title. If not id, send a random one"},
patterns = {
"^/dmm$",
"^/dmm (.+)"
},
run = run
}
end

72
plugins/ehentai.lua Normal file
View File

@ -0,0 +1,72 @@
do
function get_high_rating()
local res, code = http.request("http://g.e-hentai.org/?f_doujinshi=1&f_manga=1&f_artistcg=1&f_gamecg=1&f_western=0&f_non-h=1&f_imageset=1&f_cosplay=1&f_asianporn=1&f_misc=1&f_search=&f_apply=Apply+Filter&advsearch=1&f_sname=on&f_stags=on&f_sr=on&f_srdd=4")
if code ~= 200 then return "HTTP ERROR" end
local gidlist = {}
for gid, gtok in res:gmatch("http://g.e%-hentai.org/g/([^/]+)/([^/]+)/") do
table.insert(gidlist, {gid, gtok})
end
gidlist = {gidlist[math.random(1, #gidlist)]}
local reqbody = json:encode{method="gdata", gidlist=gidlist}
local resbody = {}
local result, respcode, respheaders, respstatus = http.request {
url="http://g.e-hentai.org/api.php",
method="POST",
headers={
["Content-Type"]="application/json",
["Content-Length"]=tostring(#reqbody)
},
source=ltn12.source.string(reqbody),
sink=ltn12.sink.table(resbody),
}
local data = json:decode(resbody[1]).gmetadata[1]
return data.thumb, data.title .. '\n' .. data.title_jpn .. '\n' .. 'rating: ' .. data.rating .. '\n' .. "http://g.e-hentai.org/g/" .. data.gid .. '/' .. data.token
end
function get_popular()
local res, code = http.request("http://g.e-hentai.org/")
if code ~= 200 then return "HTTP ERROR" end
local mangas = {}
for p in res:gmatch("class=\"id1\"(.-)class=\"id44\"") do
table.insert(mangas, {
link = p:match("href=\"(.-)\""),
img = p:match("img src=\"(.-)\""),
title = p:match("title=\"(.-)\"")
})
end
local manga = mangas[math.random(1, #mangas)]
return manga.img, manga.title .. '\n' .. manga.link
end
function run(msg, matches)
local url = nil
local txt = nil
if matches[1] == "/eh" then
url, txt = get_popular()
elseif matches[1] == "pop" then
url, txt = get_popular()
elseif matches[1] == "top" then
url, txt = get_high_rating()
end
local receiver = get_receiver(msg)
send_photo_from_url(receiver, url)
return txt
end
return {
description = "Send an e-hentai manga info.",
usage = {
"/eh: Send an popular right now e-hentai manga info which is popular right now.",
"/eh pop: Send an popular right now e-hentai manga info which is popular right now.",
"/eh top: Send a > 4-star e-hentai manga info."
},
patterns = {
"^/eh$",
"^/eh (pop)$",
"^/eh (top)$",
},
run = run
}
end

117
plugins/minecraft.lua Normal file
View File

@ -0,0 +1,117 @@
-- -- Lua 5.1+ base64 v3.0 (c) 2009 by Alex Kloss <alexthkloss@web.de>
-- -- licensed under the terms of the LGPL2
-- -- character table string
local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
-- -- encoding
-- local function enc(data)
-- return ((data:gsub('.', function(x)
-- local r,b='',x:byte()
-- for i=8,1,-1 do r=r..(b%2^i-b%2^(i-1)>0 and '1' or '0') end
-- return r;
-- end)..'0000'):gsub('%d%d%d?%d?%d?%d?', function(x)
-- if (#x < 6) then return '' end
-- local c=0
-- for i=1,6 do c=c+(x:sub(i,i)=='1' and 2^(6-i) or 0) end
-- return b:sub(c+1,c+1)
-- end)..({ '', '==', '=' })[#data%3+1])
-- end
-- decoding
function dec(data)
data = string.gsub(data, '[^'..b..'=]', '')
return (data:gsub('.', function(x)
if (x == '=') then return '' end
local r,f='',(b:find(x)-1)
for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end
return r;
end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x)
if (#x ~= 8) then return '' end
local c=0
for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end
return string.char(c)
end))
end
----------------------------------------------
local ltn12 = require "ltn12"
local mime = require "mime"
local function mineSearch(ip, port, receiver) --25565
local responseText = ""
local api = "https://api.syfaro.net/server/status"
local parameters = "?ip="..(URL.escape(ip) or "").."&port="..(URL.escape(port) or "").."&players=true&favicon=true"
local http = require("socket.http")
local respbody = {}
local body, code, headers, status = http.request{
url = api..parameters,
method = "GET",
redirect = true,
sink = ltn12.sink.table(respbody)
}
local body = table.concat(respbody)
if (status == nil) then return "ERROR: status = nil" end
if code ~=200 then return "ERROR: "..code..". Status: "..status end
local jsonData = json:decode(body)
responseText = responseText..ip..":"..port.." ->\n"
if (jsonData.motd ~= nil) then
local tempMotd = ""
tempMotd = jsonData.motd:gsub('%§.', '')
if (jsonData.motd ~= nil) then responseText = responseText.." Motd: "..tempMotd.."\n" end
end
if (jsonData.online ~= nil) then
responseText = responseText.." Online: "..tostring(jsonData.online).."\n"
end
if (jsonData.players ~= nil) then
if (jsonData.players.max ~= nil) then
responseText = responseText.." Max Players: "..jsonData.players.max.."\n"
end
if (jsonData.players.now ~= nil) then
responseText = responseText.." Players online: "..jsonData.players.now.."\n"
end
if (jsonData.players.sample ~= nil and jsonData.players.sample ~= false) then
responseText = responseText.." Players: "..table.concat(jsonData.players.sample, ", ").."\n"
end
end
if (jsonData.favicon ~= nil and false) then
file = io.open("/tmp/telegrambot-mineIcon.png","w")
file:write(dec(jsonData.favicon))
io.close(file)
send_photo(receiver, "/tmp/telegrambot-mineIcon.png")
end
return responseText
end
local function parseText(chat, text)
if (text == nil or text == "!mine") then
return "USAGE"
end
ip, port = string.match(text, "^!mine (.-) (.*)$")
if (ip ~= nil and port ~= nil) then
return mineSearch(ip, port, chat)
end
local ip = string.match(text, "^!mine (.*)$")
if (ip ~= nil) then
return mineSearch(ip, "25565", chat)
end
return "ERROR: no input ip?"
end
local function run(msg, matches)
local chat_id = tostring(msg.to.id)
local result = parseText(chat_id, msg.text)
return result
end
return {
description = "Searches Minecraft server and send info",
usage = "!mine <ip> [port]",
patterns = {
"^!mine (.*)$"
},
run = run
}

0
tmp/.gitkeep Normal file
View File