{"size": 3256, "ext": "js", "max_stars_repo_path": "src/_Commands/Web/wiki.command.js", "max_stars_repo_name": "DragonOfMath/discord-dragon-bot", "max_stars_repo_stars_event_min_datetime": "2019-01-07T17:52:21.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-07T17:52:21.000Z", "max_issues_repo_path": "src/_Commands/Web/wiki.command.js", "max_issues_repo_name": "DragonOfMath/discord-dragon-bot", "max_issues_repo_issues_event_min_datetime": "2018-01-11T08:55:38.000Z", "max_issues_repo_issues_event_max_datetime": "2018-07-01T00:45:51.000Z", "max_forks_repo_path": "src/_Commands/Web/wiki.command.js", "max_forks_repo_name": "DragonOfMath/discord-dragon-bot", "max_forks_repo_forks_event_min_datetime": "2021-02-01T12:06:20.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-01T12:06:20.000Z"}
{"max_stars_count": 1, "max_issues_count": 5, "max_forks_count": 1, "avg_line_length": 36.1777777778, "max_line_length": 109, "alphanum_fraction": 0.5896805897}
const {fetch,truncate} = require('../../Utils');

function escape(x) {
	return x.replace(/\s/g,'_');
}

module.exports = {
	'bulbapedia': {
		aliases: ['pokemonwiki','pkmnwiki','pokewiki'],
		category: 'Web',
		title: 'Bulbapedia',
		info: 'Search for Pokemon articles on Bulbapedia.',
		parameters: ['[topic]'],
		permissions: 'inclusive',
		fn({client, arg}) {
			let page = arg ? escape(arg) : 'Special:Random';
			return fetch('https://bulbapedia.bulbagarden.net/wiki/' + page, {html: true})
			.then($ => {
				let title = $('h1#firstHeading').text();
				let url = 'https://bulbapedia.bulbagarden.net/wiki/' + escape(title);
				let description = truncate($('div#mw-content-text > p').text(), 1000);
				let img = $('a.image[href*="wiki/File:"] > img[alt]').attr('src');
				return { title, description, url, image: (img ? {url: 'https:'+img} : null) };
			})
			.catch(e => e.message || e);
		}
	},
	'minecraft': {
		aliases: ['minecraftwiki','mc','mcwiki'],
		category: 'Web',
		title: 'Minecraft Wiki',
		info: 'Search the Minecraft Wiki.',
		parameters: ['[topic]'],
		permissions: 'inclusive',
		fn({arg}) {
			let page = arg ? escape(arg) : 'Special:RandomRootpage';
			return fetch('https://minecraft.gamepedia.com/' + page, {html: true})
			.then($ => {
				let title = $('meta[property="og:title"]').attr('content');
				let url   = $('meta[property="og:url"]').attr('content');
				let img   = $('meta[property="og:image"]').attr('content');
				let description = truncate($('#bodyContent > #mw-content-text > p').text(), 1000);
				return { title, description, url, image: (img ? {url: img} : null) };
			})
			.catch(e => e.message || e);
		}
	},
	'terraria': {
		aliases: ['terrawiki'],
		category: 'Web',
		title: 'Terraria Wiki',
		info: 'Search the Terraria Wiki.',
		parameters: ['[topic]'],
		permissions: 'inclusive',
		fn({arg}) {
			let page = arg ? escape(arg) : 'Special:Random';
			return fetch('https://terraria.gamepedia.com/' + page, {html: true})
			.then($ => {
				let title = $('meta[property="og:title"]').attr('content');
				let url   = $('meta[property="og:url"]').attr('content');
				let img   = $('meta[property="og:image"]').attr('content');
				let description = truncate($('#bodyContent > #mw-content-text > p').text(), 1000);
				return { title, description, url, image: (img ? {url: img} : null) };
			})
			.catch(e => e.message || e);
		}
	},
	'yugioh': {
		aliases: ['ygo','yugiohwiki','ygowiki','yugipedia'],
		category: 'Web',
		title: 'Yu-Gi-Oh! Wiki',
		info: 'Get info about a Yu-Gi-Oh! card, archetype, character, etc.',
		parameters: ['[topic]'],
		permissions: 'inclusive',
		fn({arg}) {
			let page = arg ? escape(arg) : 'Special:Random';
			return fetch('http://yugioh.wikia.com/wiki/' + page,{html: true})
			.then($ => {
				let isACard = !!$('table.cardtable').length;
				let title = $('meta[property="og:title"]').attr('content');
				let url   = $('meta[property="og:url"]').attr('content');
				let img   = $('meta[property="og:image"]').attr('content');
				let description = !isACard ? truncate($('meta[property="og:description"]').attr('content'), 1000) : null;
				return { title, description, url, image: (img ? {url: img} : null) };
			})
			.catch(e => e.message || e);
		}
	}
};
