Created
September 15, 2020 05:07
-
-
Save kalkafox/107bf7b58e7828a797499db959d971f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ZEUS VERSION 2.0.0 | |
-- MADE BY @KALKAIO | |
zeus = zeus or {} | |
local http = require "http.request" | |
local json = require "json" | |
local curl = require "cURL" | |
function zeus.log(str) | |
local timestamp = "[" .. os.date("%c", os.time()) .. "] " | |
print("[ZEUS] " .. timestamp .. str) | |
end | |
function zeus.sleep(n) | |
os.execute("sleep " .. tonumber(n)) | |
end | |
function zeus.curl(message, api) | |
c = curl.easy{ | |
url = api, | |
post = true, | |
httpheader = { | |
"Content-Type: application/json"; | |
}, | |
postfields = json.encode(message) | |
} | |
c:perform() | |
end | |
function zeus.discord(tbl, api) | |
if not tbl.instruction then tbl.instruction = "No instruction found" end | |
local timestamp = "*** This was generated on " .. os.date("%H:%M:%S at %m/%d/%Y",os.time()) .. " UTC ***\n\n" | |
message = { | |
username = "Zeus Weather Alerts", | |
embeds = {{ | |
color = tbl.event == "Tornado Warning" and 12788529 or 16312092, | |
title = tbl.event:upper() .. "!", | |
author = { | |
name = "Zeus Weather Alert" | |
}, | |
fields = { | |
{ | |
name = "Affected Areas:", | |
value = "```" .. tbl.areaDesc .. "```" | |
}, | |
{ | |
name = "Instruction:", | |
value = "```" .. tbl.instruction .. "```" | |
}, | |
{ | |
name = "Description:", | |
value = "```" .. string.sub(tbl.description, 1, 900) .. " [...]``` \n\nCharacter limited. Read the full report at [the NWS page](" .. "https://api.weather.gov/alerts/" .. tbl.id .. ")" | |
} | |
}, | |
footer = { | |
text = timestamp, | |
icon_url = "https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/160/twitter/228/clock-face-three-oclock_1f552.png" | |
} | |
}} | |
} | |
zeus.curl(message, api) | |
end | |
zeus.recognized = {} | |
zeus.shouldDiscord = false | |
zeus.num = 0 | |
zeus.log("Initializing Zeus!") | |
while true do | |
if not os.execute("sleep 3") then zeus.log("Force quitting!") break end | |
zeus.log("Querying...") | |
local headers, stream = assert(http.new_from_uri("https://api.weather.gov/alerts/active?area=LA,MS"):go()) | |
local body = assert(stream:get_body_as_string()) | |
local data = json.decode(body) | |
zeus.log("Queried.") | |
if (headers:get ":status" == "200") then | |
zeus.data = zeus.data or data.features | |
zeus.log("Table populated.") | |
for k, v in pairs(zeus.data) do | |
local p = v.properties | |
if not zeus.recognized[p.id] then | |
zeus.log("Unrecognized feature.") | |
zeus.recognized[p.id] = p | |
if zeus.shouldDiscord then | |
zeus.log("Flagged feature " .. p.id .. " for Discord.") | |
zeus.discord(p, "https://canary.discordapp.com/api/webhooks/754875801652166757/KeJjmbC8BAZz6i1bvSu2QWXThfrJ6RlFWLluFaT8960wnF0fyw7Dp-SwsgNEaM4b2AFV") | |
end | |
if k == #zeus.data then | |
zeus.discord(p, "https://canary.discordapp.com/api/webhooks/754875801652166757/KeJjmbC8BAZz6i1bvSu2QWXThfrJ6RlFWLluFaT8960wnF0fyw7Dp-SwsgNEaM4b2AFV") | |
end | |
end | |
end | |
else | |
zeus.log("API Weather timed out, retrying.") | |
end | |
if zeus == 0 then | |
zeus = 1 | |
zeus.shouldDiscord = true | |
end | |
zeus.sleep(3) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment