Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local head, body = discord.http("https://www.worldometers.info/coronavirus/")
- if head.code ~= 200 then
- return discord.sendError("COVID", "Failed to retrieve data", "Try again later.")
- end
- if not parameters then
- local remCommaFromNum = function(str)
- return tonumber((str:gsub(',', '')))
- end
- local mainCounter = string.gmatch(body, "maincounter%-number\".->([%d,]+)")
- local totalCases = mainCounter()
- local totalDeaths = mainCounter()
- local totalRecovered = mainCounter()
- local closedCases = remCommaFromNum(totalDeaths) + remCommaFromNum(totalRecovered)
- local activeCasesInMildCondition = string.match(body, "#8080FF\">([%d,]+)</span>.+Mild Condition")
- local activeCasesInCriticalCondition = string.match(body, ":red \">([%d,]+)</span>.+Serious or Critical")
- local activeCases = remCommaFromNum(activeCasesInMildCondition) + remCommaFromNum(activeCasesInCriticalCondition)
- discord.reply({
- embed = {
- color = 0xAD0000,
- title = "COVID-19 Outbreak",
- fields = {
- {
- name = "😷 Total Cases",
- value = totalCases,
- inline = false
- },
- {
- name = "💀 Total Deaths",
- value = totalDeaths,
- inline = true
- },
- {
- name = ":green_heart: Total Recovered",
- value = totalRecovered,
- inline = true
- },
- {
- name = "↗️ Active Cases",
- value = activeCases,
- inline = false
- },
- {
- name = "👁️ Cases in Mild Condition",
- value = activeCasesInMildCondition,
- inline = true
- },
- {
- name = "⚠️ Cases in Critical Condition",
- value = activeCasesInCriticalCondition,
- inline = true
- }
- }
- }
- })
- else
- if #parameters < 2 then
- return discord.sendError("COVID", "Invalid parameter.", "Use the country name in English, not its abbreviation.")
- end
- local defaultZero = function(str)
- return ((str == string.rep(' ', #str)) and 0 or str)
- end
- local i, f = body:find("<table .+</table>")
- if not i then
- return discord.sendError("COVID", "Error.", "Try again.")
- end
- body = body:sub(i, f)
- local data = body:lower():match("%W" .. parameters:lower() .. ".+</tr>")
- if not data then
- return print("Country not found.")
- end
- data = data:gmatch("<td.->(.-)</td>")
- local totalCases = defaultZero(data())
- --data()
- local newCases = defaultZero(data())
- local totalDeaths = defaultZero(data())
- local newDeaths = defaultZero(data())
- local totalRecovered = defaultZero(data())
- --data()
- local activeCases = defaultZero(data())
- local seriousCritical = defaultZero(data())
- --data()
- local totalCasesPerMillion = defaultZero(data())
- discord.reply({
- embed = {
- color = 0xAD0000,
- title = "'" .. parameters .. "' COVID-19 Outbreak",
- fields = {
- {
- name = ":mask: Total Cases",
- value = totalCases,
- inline = true
- },
- {
- name = ":mask: New Cases",
- value = newCases,
- inline = true
- },
- {
- name = ":family_mwgb: Total Cases Per Million People",
- value = totalCasesPerMillion,
- inline = false
- },
- {
- name = ":green_heart: Total Recovered",
- value = totalRecovered,
- inline = false
- },
- {
- name = ":skull: Total Deaths",
- value = totalDeaths,
- inline = true
- },
- {
- name = ":coffin: New Deaths",
- value = newDeaths,
- inline = true
- },
- { name = '', value = '', inline = true },
- {
- name = ":eye: Active Cases",
- value = activeCases,
- inline = true
- },
- {
- name = ":warning: Serious/Critical Cases",
- value = seriousCritical,
- inline = true
- }
- }
- }
- })
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement