-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdailyquote.lua
More file actions
39 lines (35 loc) · 889 Bytes
/
dailyquote.lua
File metadata and controls
39 lines (35 loc) · 889 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
local version = "0.1.0"
command.define {
name = "Daily Quote: Version",
run = function()
editor.flashNotification("Version: " .. version)
end
}
local function fetchQuotes()
local response = http.request("https://iamdangry.github.io/silverbullet-dailyquote-lua/quotes.json", {
headers = {
Accept = "application/json"
}
})
if not response or not response.body then
print("No response or no body")
return {}
end
local quotes = response.body
return quotes
end
-- Pick a random quote from parsed quotes
function random_quote()
local quotes = fetchQuotes()
if #quotes == 0 then
return nil
end
local quote = quotes[math.random(1, #quotes)]
local template = [[
> **quote** Quote
> ]] .. quote.content .. [[
> — ]] .. quote.author .. [[
]]
print(quote)
return template
end