mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-13 08:19:08 +02:00
Fact Command
This commit is contained in:
@@ -12,7 +12,7 @@ Xiao is a Discord bot coded in JavaScript with
|
||||
300 commands, she is one of the most feature-filled bots out there, and formerly
|
||||
served over 10,000 servers with a uniquely devoted fanbase.
|
||||
|
||||
## Commands (304)
|
||||
## Commands (305)
|
||||
### Utility:
|
||||
|
||||
* **prefix**: Shows or sets the command prefix.
|
||||
@@ -60,6 +60,7 @@ served over 10,000 servers with a uniquely devoted fanbase.
|
||||
* **discord-email-fun-fact**: Responds with a random fun fact from the Discord emails.
|
||||
* **dog-fact**: Responds with a random dog fact.
|
||||
* **dog**: Responds with a random dog image.
|
||||
* **fact**: Responds with a random fact.
|
||||
* **fact-core**: Responds with a random Fact Core quote.
|
||||
* **fidget**: Responds with a random image of Fidget.
|
||||
* **fortune**: Responds with a random fortune.
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
const { Command } = require('discord.js-commando');
|
||||
const snekfetch = require('snekfetch');
|
||||
|
||||
module.exports = class FactCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'fact',
|
||||
aliases: ['wikifakt'],
|
||||
group: 'random',
|
||||
memberName: 'fact',
|
||||
description: 'Responds with a random fact.'
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg) {
|
||||
try {
|
||||
const article = await this.randomWikipediaArticle();
|
||||
const { body } = await snekfetch
|
||||
.get('https://en.wikipedia.org/w/api.php')
|
||||
.query({
|
||||
action: 'query',
|
||||
prop: 'extracts',
|
||||
format: 'json',
|
||||
titles: article,
|
||||
exintro: '',
|
||||
explaintext: '',
|
||||
redirects: '',
|
||||
formatversion: 2
|
||||
});
|
||||
let fact = body.query.pages[0].extract;
|
||||
if (fact.length > 200) {
|
||||
const facts = fact.split('.');
|
||||
fact = `${facts[0]}.`;
|
||||
if (fact.length < 200 && facts.length > 1) fact += `${facts[1]}.`;
|
||||
}
|
||||
return msg.say(fact);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
async randomWikipediaArticle() {
|
||||
const { body } = await snekfetch
|
||||
.get('https://en.wikipedia.org/w/api.php')
|
||||
.query({
|
||||
action: 'query',
|
||||
list: 'random',
|
||||
rnnamespace: 0,
|
||||
rnlimit: 1,
|
||||
format: 'json',
|
||||
formatversion: 2
|
||||
});
|
||||
return body.query.random[0].title;
|
||||
}
|
||||
};
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "73.0.1",
|
||||
"version": "73.1.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user