Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.getWikipediaShortInformation = (msg, argument) => {
wiki().search(argument).then(data => {
// Getting the first result of the search results
// TODO: Find a way to handle disambiguation pages
const bestResult = data.results[0]
wiki().page(bestResult).then(page => {
page.fullInfo().then(info => console.log(info))
}).catch(e => {
// Logging the error
Util.log('[2] An error occurred while requesting the data from Wikipedia', ` Searched for: ${argument} - Best Result: ${bestResult}`, 1)
Util.betterError(msg, e)
// Error handling 101
msg.reply('sorry, an error occurred while trying to execute your command. Please check your spelling or try another keyword.')
})
}).catch(e => {
// Logging the error
wiki().search(argument).then(data => {
// Getting the first result of the search results
// TODO: Find a way to handle disambiguation pages
const bestResult = data.results[0]
wiki().page(bestResult).then(page => {
page.fullInfo().then(info => console.log(info))
}).catch(e => {
// Logging the error
Util.log('[2] An error occurred while requesting the data from Wikipedia', ` Searched for: ${argument} - Best Result: ${bestResult}`, 1)
Util.betterError(msg, e)
// Error handling 101
msg.reply('sorry, an error occurred while trying to execute your command. Please check your spelling or try another keyword.')
})
}).catch(e => {
// Logging the error
async run(message) {
const query = message.content.split(/\s+/g).slice(1).join(" ");
if (!query) {
return message.channel.send('You must specify something to search!');
}
const data = await wiki().search(query, 1);
if (!data.results || !data.results.length) {
return message.channel.send('No matches found!');
}
const page = await wiki().page(data.results[0]);
const summary = await page.summary();
const paragraphs = summary.split('\n');
if (!query.options) {
paragraphs.length = Math.min(1, paragraphs.length);
}
try {
const embed = new Discord.MessageEmbed()
.setAuthor(page.raw.title)
.setDescription(paragraphs.join('\n\n'))
.addField('Link', `**${page.raw.fullurl}**`)
async run(message) {
const query = message.content.split(/\s+/g).slice(1).join(" ");
if (!query) {
return message.channel.send('You must specify something to search!');
}
const data = await wiki().search(query, 1);
if (!data.results || !data.results.length) {
return message.channel.send('No matches found!');
}
const page = await wiki().page(data.results[0]);
const summary = await page.summary();
const paragraphs = summary.split('\n');
if (!query.options) {
paragraphs.length = Math.min(1, paragraphs.length);
}
try {
const embed = new Discord.MessageEmbed()
.setAuthor(page.raw.title)
.setDescription(paragraphs.join('\n\n'))
.addField('Link', `**${page.raw.fullurl}**`)
.setFooter('Wikipedia', 'https://a.safe.moe/8GCNj.png')
.setColor('#c7c8ca');
return message.channel.send(`First search result of \`${query}\` on Wikipedia:`, { embed });
} catch (err) {
exports.run = async (client, message, Discord, args) => {
const query = message.content.split(/\s+/g).slice(1).join(" ");
if (!query) {
return message.channel.send('You must specify something to search!').then(m => m.delete(5000));
}
message.channel.send(`Searching for ${query} on Wikipedia...`).then(m => m.delete(5000));
const data = await wiki().search(query, 1)
if (!data.results || !data.results.length) {
return message.channel.send('No matches found!')
}
const page = await wiki().page(data.results[0])
const summary = await page.summary()
const paragraphs = summary.split('\n')
if (!query.options) {
paragraphs.length = Math.min(2, paragraphs.length)
}
try {
const embed = new Discord.MessageEmbed()
.setAuthor(page.raw.title)
.setDescription(paragraphs.join('\n\n'))
.addField('Link', `**${page.raw.fullurl}**`)
.setFooter('Wikipedia', 'https://a.safe.moe/8GCNj.png')
.setColor('#c7c8ca')
return message.channel.send(`First search result of \`${query}\` on Wikipedia:`, {embed})
} catch(err) {
module.exports.run = (remainder, parts, reply) => {
wiki().search(remainder, 1)
.then(data => data.results[0])
.then(wiki().page)
.then(page => shortSummary(page, true))
.then(reply)
.catch(() => reply(errorMessage(remainder)));
};
const wiki = require("wikijs").default();
module.exports = {
arguments: [{
description: "The Wikipedia page to get a link to.",
key: "page",
required: true,
type: "string",
}],
category: "wiki",
description: "Gets the link to a Wikipedia page.",
handler: args => wiki.page(args.page).catch(error => {
if (error.message === "No article found") {
args.send(args.localize("wikipedia_article_not_found"));
}
}).then(page => {
args.send(page.raw.title + " - " + page.raw.canonicalurl);
module.exports.run = (remainder, parts, reply) => {
wiki().search(remainder, 1)
.then(data => data.results[0])
.then(wiki().page)
.then(page => shortSummary(page, true))
.then(reply)
.catch(() => reply(errorMessage(remainder)));
};
const wikipedia = (name) => new Promise((resolve, reject) => {
var url, mainImage, infoBox, summary, title;
wikijs().page(name)
.then((page) => {
url = page.raw.fullurl;
title = page.raw.title;
page.summary()
.then((summaryRes) => {
summary = summaryRes;
page.fullInfo()
.then((infoBoxRes) => {
infoBox = infoBoxRes;
page.mainImage()
.then((mainImageRes) => {
mainImage = mainImageRes;
resolve({url, mainImage, infoBox, summary, title});
})
.catch((err) => {
const noImageErr = 'Cannot read property \'imageinfo\' of undefined';
const wiki = require("wikijs").default();
module.exports = async ({ Constants: { Colors } }, documents, msg, commandData) => {
await msg.send({
embed: {
color: Colors.INFO,
title: `Searching Wikipedia just for you ⌛`,
description: `Please stand by...`,
},
});
let result;
if (!msg.suffix) {
const random = await wiki.random(1);
result = await wiki.page(random[0]);
} else {
const search = await wiki.search(msg.suffix, 1);
if (!search.results.length) {