How to use wikijs - 10 common examples

To help you get started, we’ve selected a few wikijs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github julianYaman / wikipedia-bot / modules / requests.js View on Github external
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
github julianYaman / wikipedia-bot / modules / requests.js View on Github external
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
github Mitorisia / Komugari / commands / utility / wiki.js View on Github external
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}**`)
github Mitorisia / Komugari / commands / utility / wiki.js View on Github external
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) {
github Mitorisia / Komugari / _commands / search / wiki.js View on Github external
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) {
github Gravebot / Gravebot / src / commands / useful / wiki.js View on Github external
new Wiki().search(suffix, 1).then(data => {
      new Wiki().page(data.results[0]).then(page => {
        page.summary().then(summary => {
          resolve(summary.toString().split('\n'));
        });
      })
      .catch(() => {
        resolve(`${T('wiki_error', lang)} **${suffix}**`);
      });
    });
  });
github Gravebot / Gravebot / src / commands / useful / wiki.js View on Github external
return new Promise(resolve => {
    new Wiki().search(suffix, 1).then(data => {
      new Wiki().page(data.results[0]).then(page => {
        page.summary().then(summary => {
          resolve(summary.toString().split('\n'));
        });
      })
      .catch(() => {
        resolve(`${T('wiki_error', lang)} **${suffix}**`);
      });
    });
  });
}
github Gravebot / Gravebot / lib / misc.js View on Github external
function wiki(bot, msg, suffix) {
  if (!suffix) {
    bot.sendMessage(msg.channel, 'Usage: **`!wiki`** `search terms`');
    return;
  }
  new Wiki().search(suffix, 1).then(function(data) {
    new Wiki().page(data.results[0]).then(function(page) {
      page.summary().then(function(summary) {
        let sum_text = summary.toString().split('\n');
        R.forEach(paragraph => {
          bot.sendMessage(msg.channel, paragraph);
        }, sum_text);
      });
    });
  });
}
github Gravebot / Gravebot / lib / misc.js View on Github external
new Wiki().search(suffix, 1).then(function(data) {
    new Wiki().page(data.results[0]).then(function(page) {
      page.summary().then(function(summary) {
        let sum_text = summary.toString().split('\n');
        R.forEach(paragraph => {
          bot.sendMessage(msg.channel, paragraph);
        }, sum_text);
      });
    });
  });
}
github wobscale / EuIrcBot / modules / wikipedia / index.js View on Github external
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)));
};

wikijs

Mediawiki interface for Node and Web

MIT
Latest version published 1 year ago

Package Health Score

58 / 100
Full package analysis

Popular wikijs functions