*New Feature

* Cowin API integration
* Command ```!vaccine 110009 25-05-2021```
This commit is contained in:
Indrajith K L
2021-05-13 02:57:20 +05:30
parent 4868721d30
commit 187e6bc1f2
4 changed files with 60 additions and 0 deletions

13
package-lock.json generated
View File

@@ -214,6 +214,14 @@
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
}, },
"axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"requires": {
"follow-redirects": "^1.10.0"
}
},
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
@@ -527,6 +535,11 @@
"progress": "^2.0.3" "progress": "^2.0.3"
} }
}, },
"follow-redirects": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.1.tgz",
"integrity": "sha512-HWqDgT7ZEkqRzBvc2s64vSZ/hfOceEol3ac/7tKwzuvEyWx3/4UegXh5oBOIotkGsObyk3xznnSRVADBgWSQVg=="
},
"fs-minipass": { "fs-minipass": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz",

View File

@@ -13,6 +13,7 @@
"dependencies": { "dependencies": {
"@discordjs/opus": "^0.4.0", "@discordjs/opus": "^0.4.0",
"airtable": "^0.10.1", "airtable": "^0.10.1",
"axios": "^0.21.1",
"discord.js": "^12.5.1", "discord.js": "^12.5.1",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"ffmpeg-static": "^4.2.7", "ffmpeg-static": "^4.2.7",

41
src/commands/vaccine.js Normal file
View File

@@ -0,0 +1,41 @@
const axios = require('axios').default;
const {MessageEmbed} = require('discord.js');
const instance = axios.create({
baseURL: 'https://cdn-api.co-vin.in/api/v2',
headers: {
'accept': '*/*',
'accept-language': 'en-US',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'
}
});
async function getVaccineAvailablity(message, args) {
const [pincode, date] = args;
const url = `/appointment/sessions/public/findByPin?${new URLSearchParams({ pincode, date })}`;
instance.get(url).then(res => {
if (res.data && res.data.sessions) {
const {sessions} = res.data;
if (sessions && sessions.length > 0 ){
sessions.forEach(async (session) => {
const vaccineMessage = new MessageEmbed()
.setTitle(`${session.name} : ${session.address}`)
.addField('State', session.state_name, true)
.addField('District', session.district_name, true)
.addField('Vaccine', session.vaccine, true)
.addField('Available Capacity', session.available_capacity, true)
.addField('Available SLots', session.slots.join("/"), true)
.setColor("RANDOM");
message.channel.send(vaccineMessage);
})
}else {
message.channel.send(`No Vaccine Available at place with pincode => ${pincode} on ${date}`)
}
}
}).catch(error => message.channel.send(`Error Fetching Data from Cowin`));
}
module.exports = {
execute(client, message, args) {
getVaccineAvailablity(message, args);
}
}

View File

@@ -19,6 +19,11 @@
"name": "loadout", "name": "loadout",
"description": "Get CoD Mobile User Loadout", "description": "Get CoD Mobile User Loadout",
"file": "./commands/loadout.js" "file": "./commands/loadout.js"
},
{
"name": "vaccine",
"description": "Get Vaccine Availability by Pincode",
"file": "./commands/vaccine.js"
} }
] ]
} }