The second RT-COVID snippet working with a slash command called '/covidcasesrecentstate' requiring a string parameter called 'state' (it's meant to contain a two-letter US state code)
// Prompts us with a discord and RT-COVID library we WILL need
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
// The code
// Yeah, just the original code you'll see
await lib.discord.channels['@0.0.6'].messages.create({
channel_id: context.params.event.channel_id,
content: `<@!${context.params.event.member.user.id}> just triggered the **covidcasesrecentstate** command!`
});
// NOTE: ONE PARAMETER (STATE) REQUIRED!
console.log(`${context.params.event.data.options[0].value}`)
// The main function (if runtime error, delete the lines above this except lines 1 to 4)
let result = await lib.rtlive.covid19['@0.1.0'].latest({
region: context.params.event.data.options[0].value
});
await lib.discord.channels['@0.3.1'].messages.create({
channel_id: `${context.params.event.channel_id}`,
content: `PLEASE NOTE THAT THIS MAY NOT BE ACCURATE!
Region: ${context.params.event.data.options[0].value},
Infections: ` + result.infections + `,
Positive tests: ` + result.test_adjusted_positive + `,
Preliminary Positive: ` + result.test_adjusted_positive_raw + `,
Positive: ` + result.positive + `,
New Deaths: ` + result.new_deaths + `,
New 'DELTA' COVID variant cases: ` + result.new_cases_delta + `,
New Cases (all): ` + result.new_cases + `,
New Tests (all): ` + result.new_tests
,
// Next few lines give out a button which goes to https://who.int
"components": [
{
"type": 1,
"components": [
{
"style": 5,
"label": `WHO's public advise`,
"url": `https://www.who.int/emergencies/diseases/novel-coronavirus-2019/advice-for-public`,
"disabled": false,
"emoji": {
"id": null,
"name": `❓`
},
"type": 2
}
]
}
]
});