Merge branch 'api_plugins'

This commit is contained in:
Andreas Bielawski 2016-08-22 23:05:53 +02:00
commit 8c8ba6ff64
5 changed files with 219 additions and 0 deletions

View File

@ -0,0 +1,29 @@
local chucknorris = {}
chucknorris.command = 'cn'
function chucknorris:init(config)
chucknorris.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('cn', true).table
chucknorris.doc = [[*
]]..config.cmd_pat..[[cn*: Postet einen zufälligen Chuck-Norris-Witz]]
end
function chucknorris:get_joke()
local url = 'http://api.icndb.com/jokes/random'
local res, code = http.request(url)
if code ~= 200 then return nil end
local data = json.decode(res)
local text = data.value.joke
return text
end
function chucknorris:action(msg, config)
local text = chucknorris:get_joke()
if not text then
utilities.send_reply(self, msg, config.errors.connection)
return
end
utilities.send_reply(self, msg, unescape(text))
end
return chucknorris

30
miku/plugins/dogify.lua Normal file
View File

@ -0,0 +1,30 @@
local dogify = {}
function dogify:init(config)
dogify.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('dogify', true).table
dogify.doc = [[*
]]..config.cmd_pat..[[dogify* _<text/den/du/willst>_: Wow, much doge!
]]
end
dogify.command = 'dogify text/den/du/willst'
function dogify:action(msg, config, matches)
local input = utilities.input_from_msg(msg)
if not input then
utilities.send_reply(self, msg, dogify.doc, true)
return
end
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local path = input:gsub(" ", "%%20")
local photo_url = 'http://dogr.io/'..path..'.png?split=false&.png'
local file = download_to_file(photo_url)
if not file then
utilities.send_reply(self, msg, config.errors.connection)
return
end
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
end
return dogify

44
miku/plugins/mal_user.lua Normal file
View File

@ -0,0 +1,44 @@
local mal_user = {}
function mal_user:init(config)
mal_user.triggers = {
"^/malu (.+)$",
"myanimelist.net/profile/(.*)$"
}
mal_user.doc = [[*
]]..config.cmd_pat..[[malu* _<User>_: Sendet Infos über einen MyAnimeList-User
]]
end
mal_user.command = 'malu <User>'
function mal_user:get_infos(user)
local url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22http%3A%2F%2Fmyanimelist.net%2Fmalappinfo.php%3Fu%3D'..user..'%22&format=json&diagnostics=true&callback='
local res, code = https.request(url)
if code ~= 200 then return nil end
local data = json.decode(res).query.results.myanimelist.myinfo
if not data then return nil end
local name = data.user_name
local watching = data.user_watching
local pause = data.user_onhold
local dropped = data.user_dropped
local complete = data.user_completed
local planed = data.user_plantowatch
local mal_url = 'http://myanimelist.net/profile/'..data.user_name
local text = '<b>'..name..'</b> schaut derzeit <b>'..watching..' Animes</b>, hat <b>'..pause..' pausiert</b>, <b>'..dropped..' abgebrochen</b> und <b>'..complete..' beendet</b>. <b>'..planed..'</b> stehen auf der Watchlist.\n<a href="'..mal_url..'">Profil aufrufen</a>'
return text
end
function mal_user:action(msg, config, matches)
local user = matches[1]
local text = mal_user:get_infos(user)
if not text then
utilities.send_reply(self, msg, config.errors.results)
return
end
utilities.send_reply(self, msg, text, 'HTML')
end
return mal_user

View File

@ -0,0 +1,57 @@
local mfc = {}
function mfc:init(config)
mfc.triggers = {
"^/[Mm][Ff][Cc] (.+)$",
"myfigurecollection.net/user/(.+)$",
"myfigurecollection.net/collection/(.+)$"
}
mfc.doc = [[*
]]..config.cmd_pat..[[mfc* _<User>_: Zeigt den zuletzt hinzugefügten Artikel eines MyFigureCollection-Users
]]
end
mfc.command = 'mfc <User>'
local makeOurDate = function(dateString)
local pattern = "(%d+)%-(%d+)%-(%d+)"
local year, month, day = dateString:match(pattern)
if day == "00" then
return month..'.'..year
else
return day..'.'..month..'.'..year
end
end
function mfc:get_infos(user)
local url = 'http://myfigurecollection.net/api.php?type=json&mode=collection&username='..user
local res, code = http.request(url)
if code ~= 200 then return nil end
local data = json.decode(res).collection.owned
if not data then return nil end
local title = data.item[1].data.name
local owned = data.num_items
local profile_url = 'http://de.myfigurecollection.net/collection/'..user
local art = data.item[1].root.name
local category = data.item[1].category.name
local date = makeOurDate(data.item[1].data.release_date)
local price = '¥'..data.item[1].data.price
local url = 'http://de.myfigurecollection.net/item/'..data.item[1].data.id
local text = 'Letzter Artikel aus <b>'..user..'\'s</b> <a href="'..profile_url..'">Sammlung</a> ('..owned..' Artikel):\n<a href="'..url..'">'..title..'</a>\nArt: '..art..' ('..category..')\n<i>Erschien am '..date..' für '..price..'</i>'
return text
end
function mfc:action(msg, config, matches)
local user = matches[1]
local text = mfc:get_infos(user)
if not text then
utilities.send_reply(self, msg, config.errors.results)
return
end
utilities.send_reply(self, msg, text, 'HTML')
end
return mfc

View File

@ -0,0 +1,59 @@
local nicovideo = {}
nicovideo.triggers = {
"nicovideo.jp/watch/(sm%d+)",
"nicovideo.jp/watch/(%d+)",
"nico.ms/(sm%d+)"
}
local makeOurDate = function(dateString)
local pattern = "(%d+)%-(%d+)%-(%d+)T"
local year, month, day = dateString:match(pattern)
if month == "00" then
return year
elseif day == "00" then
return month..'.'..year
else
return day..'.'..month..'.'..year
end
end
function nicovideo:get_video(id)
local url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22http%3A%2F%2Fext.nicovideo.jp%2Fapi%2Fgetthumbinfo%2F'..id..'%22&format=json'
local res, code = https.request(url)
if code ~= 200 then return nil end
local data = json.decode(res).query.results.nicovideo_thumb_response.thumb
if not data then return nil end
local title = data.title
local date = makeOurDate(data.first_retrieve)
if data.user_nickname then
user = data.user_nickname
else
user = data.ch_name
end
local views = comma_value(data.view_counter)
local dura = data.length
local favs = comma_value(data.mylist_counter)
local comm = comma_value(data.comment_num)
local pic = data.thumbnail_url
local text = '<b>'..title..'</b>\nHochgeladen am '..date..' von <b>'..user..'</b>, <i>'..views..'x angesehen, Länge: '..dura..', '..favs..'x favoritisiert, '..comm..' Kommentare</i>'
return text, pic
end
function nicovideo:action(msg, config, matches)
local id = matches[1]
local text, pic_url = nicovideo:get_video(id)
if not text then
utilities.send_reply(self, msg, config.errors.results)
return
end
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(pic_url, 'nicovideo_thumb.png')
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
utilities.send_reply(self, msg, text, 'HTML')
end
return nicovideo