diff --git a/miku/plugins/chucknorris.lua b/miku/plugins/chucknorris.lua new file mode 100644 index 0000000..55ee4d1 --- /dev/null +++ b/miku/plugins/chucknorris.lua @@ -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 \ No newline at end of file diff --git a/miku/plugins/dogify.lua b/miku/plugins/dogify.lua new file mode 100644 index 0000000..127bab2 --- /dev/null +++ b/miku/plugins/dogify.lua @@ -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* __: 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 \ No newline at end of file diff --git a/miku/plugins/mal_user.lua b/miku/plugins/mal_user.lua new file mode 100644 index 0000000..fbd0671 --- /dev/null +++ b/miku/plugins/mal_user.lua @@ -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* __: Sendet Infos über einen MyAnimeList-User +]] +end + +mal_user.command = 'malu ' + +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 = ''..name..' schaut derzeit '..watching..' Animes, hat '..pause..' pausiert, '..dropped..' abgebrochen und '..complete..' beendet. '..planed..' stehen auf der Watchlist.\nProfil aufrufen' + + 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 \ No newline at end of file diff --git a/miku/plugins/myfigurecollection.lua b/miku/plugins/myfigurecollection.lua new file mode 100644 index 0000000..085e7ef --- /dev/null +++ b/miku/plugins/myfigurecollection.lua @@ -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* __: Zeigt den zuletzt hinzugefügten Artikel eines MyFigureCollection-Users +]] +end + +mfc.command = 'mfc ' + +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 '..user..'\'s Sammlung ('..owned..' Artikel):\n'..title..'\nArt: '..art..' ('..category..')\nErschien am '..date..' für '..price..'' + + 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 \ No newline at end of file diff --git a/miku/plugins/nicovideo.lua b/miku/plugins/nicovideo.lua new file mode 100644 index 0000000..e5c54c5 --- /dev/null +++ b/miku/plugins/nicovideo.lua @@ -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 = ''..title..'\nHochgeladen am '..date..' von '..user..', '..views..'x angesehen, Länge: '..dura..', '..favs..'x favoritisiert, '..comm..' Kommentare' + + 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 \ No newline at end of file