chomens-bot-js/commands/wikipedia.js

37 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-08-14 05:51:45 -04:00
/* eslint-disable max-len */
const wiki = require('wikipedia');
const util = require('util');
const {MessageEmbed} = require('discord.js');
module.exports = {
name: 'wikipedia',
alias: ['wiki'],
usage: '<anything>',
trusted: 0,
execute: async function(bot, username, usernameraw, sender, prefix, args) {
try {
const page = await wiki.page(args.join(' '));
const summary = await page.summary();
bot.core.run('minecraft:tellraw @a ' + JSON.stringify({text: summary.extract, color: 'green'}));
} catch (e) {
bot.core.run('minecraft:tellraw @a ' + JSON.stringify({text: e.toString(), color: 'red'}));
}
},
discordExecute: async function(bot, username, usernameraw, sender, prefix, args, channeldc) {
try {
const page = await wiki.page(args.join(' '));
const summary = await page.summary();
const Embed = new MessageEmbed()
.setColor('#FFFF00')
.setTitle('Output')
.setDescription(summary.extract);
channeldc.send({embeds: [Embed]});
} catch (e) {
const Embed = new MessageEmbed()
.setColor('#FF0000')
.setTitle('Error')
.setDescription(`\`\`\`${util.inspect(e)}\`\`\``);
channeldc.send({embeds: [Embed]});
}
},
};