This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/pluginsold/hackernews.lua
2015-06-16 21:40:12 +02:00

25 lines
727 B
Lua

do
function run(msg, matches)
local result = 'Hacker News Top5:\n'
local top_stories_json, code = https.request('https://hacker-news.firebaseio.com/v0/topstories.json')
if code ~=200 then return nil end
local top_stories = json:decode(top_stories_json)
for i = 1, 5 do
local story_json, code = https.request('https://hacker-news.firebaseio.com/v0/item/'..top_stories[i]..'.json')
if code ~=200 then return nil end
local story = json:decode(story_json)
result = result .. i .. '. ' .. story.title .. ' - ' .. story.url .. '\n'
end
return result
end
return {
description = "Show top 5 hacker news (ycombinator.com)",
usage = "!hackernews",
patterns = {"^!hackernews$"},
run = run
}
end