mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-23 18:05:01 +02:00
Add external dog and cat fact apis
This commit is contained in:
@@ -19,6 +19,11 @@ module.exports = class CatCommand extends Command {
|
|||||||
url: 'https://thecatapi.com/',
|
url: 'https://thecatapi.com/',
|
||||||
reason: 'API',
|
reason: 'API',
|
||||||
reasonURL: 'https://docs.thecatapi.com/'
|
reasonURL: 'https://docs.thecatapi.com/'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Cat Facts API',
|
||||||
|
url: 'https://catfact.ninja/',
|
||||||
|
reason: 'API'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@@ -29,6 +34,16 @@ module.exports = class CatCommand extends Command {
|
|||||||
.get('https://api.thecatapi.com/v1/images/search')
|
.get('https://api.thecatapi.com/v1/images/search')
|
||||||
.query({ limit: 1 })
|
.query({ limit: 1 })
|
||||||
.set({ 'x-api-key': THECATAPI_KEY });
|
.set({ 'x-api-key': THECATAPI_KEY });
|
||||||
return msg.say(facts[Math.floor(Math.random() * facts.length)], { files: [body[0].url] });
|
const fact = await this.getFact();
|
||||||
|
return msg.say(fact, { files: [body[0].url] });
|
||||||
|
}
|
||||||
|
|
||||||
|
async getFact() {
|
||||||
|
try {
|
||||||
|
const { body } = await request.get('https://catfact.ninja/fact');
|
||||||
|
return body.fact;
|
||||||
|
} catch {
|
||||||
|
return facts[Math.floor(Math.random() * facts.length)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ module.exports = class DogCommand extends Command {
|
|||||||
url: 'https://thedogapi.com/',
|
url: 'https://thedogapi.com/',
|
||||||
reason: 'API',
|
reason: 'API',
|
||||||
reasonURL: 'https://docs.thedogapi.com/'
|
reasonURL: 'https://docs.thedogapi.com/'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Dog API',
|
||||||
|
url: 'https://kinduff.github.io/dog-api/',
|
||||||
|
reason: 'API'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
@@ -29,6 +34,16 @@ module.exports = class DogCommand extends Command {
|
|||||||
.get('https://api.thedogapi.com/v1/images/search')
|
.get('https://api.thedogapi.com/v1/images/search')
|
||||||
.query({ limit: 1 })
|
.query({ limit: 1 })
|
||||||
.set({ 'x-api-key': THEDOGAPI_KEY });
|
.set({ 'x-api-key': THEDOGAPI_KEY });
|
||||||
return msg.say(facts[Math.floor(Math.random() * facts.length)], { files: [body[0].url] });
|
const fact = await this.getFact();
|
||||||
|
return msg.say(fact, { files: [body[0].url] });
|
||||||
|
}
|
||||||
|
|
||||||
|
async getFact() {
|
||||||
|
try {
|
||||||
|
const { body } = await request.get('https://dog-api.kinduff.com/api/facts');
|
||||||
|
return body.facts[0];
|
||||||
|
} catch {
|
||||||
|
return facts[Math.floor(Math.random() * facts.length)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user