mirror of
https://github.com/Expand-sys/PharmaBot
synced 2026-03-22 12:27:08 +11:00
added a command
This commit is contained in:
parent
20dc99c2b0
commit
f3f8e964c3
2 changed files with 26 additions and 7 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const { findDrug } = require('../../helpers/OpenFDA')
|
const { findDrug, adverseEvent } = require('../../helpers/OpenFDA')
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
@ -7,7 +7,7 @@ module.exports = {
|
||||||
aliases: ['openFDA'],
|
aliases: ['openFDA'],
|
||||||
description: 'fids drug based on proprietary name',
|
description: 'fids drug based on proprietary name',
|
||||||
async execute(message, args) {
|
async execute(message, args) {
|
||||||
if(args[0] == "find" || args[0] == "Find"){
|
if(args[0].toLowerCase() == "find"){
|
||||||
let res = await findDrug(args[1])
|
let res = await findDrug(args[1])
|
||||||
if(res == 'Couldnt find the Medicine Specified'){
|
if(res == 'Couldnt find the Medicine Specified'){
|
||||||
message.reply(res)
|
message.reply(res)
|
||||||
|
|
@ -29,6 +29,9 @@ module.exports = {
|
||||||
.setFooter('heh nice');
|
.setFooter('heh nice');
|
||||||
message.reply(embed)
|
message.reply(embed)
|
||||||
}
|
}
|
||||||
|
}else if(args[0].toLowerCase() == "adverseevent"){
|
||||||
|
let res = await adverseEvent(args[1])
|
||||||
|
console.log(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,28 @@
|
||||||
const https = require('https')
|
const https = require('https')
|
||||||
const got = require('got')
|
const got = require('got')
|
||||||
|
const apikey= process.env.APIKEY
|
||||||
|
|
||||||
async function findDrug(drug){
|
async function findDrug(drug){
|
||||||
let query = "proprietary_name:"+drug
|
let query = "proprietary_name:"+drug
|
||||||
let res
|
let res
|
||||||
try{
|
try{
|
||||||
res = await got("https://api.fda.gov/other/nsde.json?api_key=IbMkYkBOkuTRvQZDaXgfjxYP2wzDtySmg8477KvA&search="+query,{
|
res = await got("https://api.fda.gov/other/nsde.json?api_key="+apikey+"&search="+query,{
|
||||||
|
dnsLookupIpVersion: 'ipv4'
|
||||||
|
});
|
||||||
|
res = res.body
|
||||||
|
res = JSON.parse(res)
|
||||||
|
} catch(err){
|
||||||
|
console.log(err)
|
||||||
|
res = 'Couldnt find the Medicine Specified'
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
async function adverseEvent(drug){
|
||||||
|
//https://api.fda.gov/other/event.json?search=patient.drug.activesubstance.activesubstancename:Prozac
|
||||||
|
let query = "patient.drug.medicinalproduct:"+drug
|
||||||
|
let res
|
||||||
|
try{
|
||||||
|
res = await got("https://api.fda.gov/drug/event.json?api_key="+apikey+"&search="+query,{
|
||||||
dnsLookupIpVersion: 'ipv4'
|
dnsLookupIpVersion: 'ipv4'
|
||||||
});
|
});
|
||||||
res = res.body
|
res = res.body
|
||||||
|
|
@ -18,7 +34,7 @@ async function findDrug(drug){
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
findDrug
|
findDrug,
|
||||||
|
adverseEvent
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue