chomens-bot-js/commands/wikipedia.js

37 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2022-11-27 02:35:28 -05:00
const wiki = require('wikipedia')
const util = require('util')
const { EmbedBuilder } = require('discord.js')
2022-08-14 05:51:45 -04:00
module.exports = {
name: 'wikipedia',
alias: ['wiki'],
2022-08-19 02:49:37 -04:00
description: 'Working Wikipedia!',
usage: '<page>',
2022-08-14 05:51:45 -04:00
trusted: 0,
execute: async function (bot, username, sender, prefix, args, config, hash, ownerhash, selector) {
2022-08-14 05:51:45 -04:00
try {
2022-11-27 02:35:28 -05:00
const page = await wiki.page(args.join(' '))
const summary = await page.summary()
bot.tellraw(selector, { text: summary.extract, color: 'green' })
2022-08-14 05:51:45 -04:00
} catch (e) {
2022-11-27 02:35:28 -05:00
bot.tellraw(selector, { text: e.toString(), color: 'red' })
2022-08-14 05:51:45 -04:00
}
},
discordExecute: async function (bot, username, sender, prefix, args, channeldc, message, config) {
2022-08-14 05:51:45 -04:00
try {
2022-11-27 02:35:28 -05:00
const page = await wiki.page(args.join(' '))
const summary = await page.summary()
const Embed = new EmbedBuilder()
2022-12-01 05:15:30 -05:00
.setColor(config.discord.embedsColors.normal)
2022-11-27 02:35:28 -05:00
.setTitle('Output')
.setDescription(summary.extract)
channeldc.send({ embeds: [Embed] })
2022-08-14 05:51:45 -04:00
} catch (e) {
const Embed = new EmbedBuilder()
2022-12-01 05:15:30 -05:00
.setColor(config.discord.embedsColors.error)
2022-11-27 02:35:28 -05:00
.setTitle('Error')
.setDescription(`\`\`\`${util.inspect(e)}\`\`\``)
channeldc.send({ embeds: [Embed] })
2022-08-14 05:51:45 -04:00
}
2022-11-27 02:35:28 -05:00
}
}