diff --git a/chat-plugins/dexsearch.js b/chat-plugins/datasearch.js similarity index 90% rename from chat-plugins/dexsearch.js rename to chat-plugins/datasearch.js index 6d37743a48..d1644ba491 100644 --- a/chat-plugins/dexsearch.js +++ b/chat-plugins/datasearch.js @@ -1,8 +1,9 @@ /** - * Dexsearch commands + * Data searching commands. * Pokemon Showdown - http://pokemonshowdown.com/ * - * Commands for advanced searching for pokemon, moves, and items. + * Commands for advanced searching for pokemon, moves, items and learnsets. + * These commands run on a seperate process if possible, and execute synchronously otherwise. * * @license MIT license */ @@ -51,6 +52,9 @@ const PM = exports.PM = new ProcessManager({ case 'itemsearch': result = runItemsearch(data.target, data.cmd, data.canAll, data.message); break; + case 'learn': + result = runLearn(data.target, data.message); + break; default: result = null; } @@ -193,6 +197,42 @@ exports.commands = { "Command accepts natural language. (tip: fewer words tend to work better)", "Searches with \"fling\" in them will find items with the specified Fling behavior.", "Searches with \"natural gift\" in them will find items with the specified Natural Gift behavior."], + + learnset: 'learn', + learnall: 'learn', + learn5: 'learn', + g6learn: 'learn', + rbylearn: 'learn', + gsclearn: 'learn', + advlearn: 'learn', + dpplearn: 'learn', + bw2learn: 'learn', + learn: function (target, room, user, connection, cmd, message) { + if (!this.canBroadcast(true)) return; + if (this.broadcasting && !user.can('broadcast', null, room)) { + this.errorReply("You need to be voiced to broadcast this command's information."); + this.errorReply("To see it for yourself, use: /" + message.substr(1)); + return false; + } + + if (!target) return this.parse('/help learn'); + + runSearch({ + target: target, + cmd: 'learn', + message: cmd, + }).then(response => { + if (!this.canBroadcast()) return; + if (response.reply) { + this.sendReplyBox(response.reply); + } else if (response.error) { + this.errorReply(response.error); + } + room.update(); + }); + }, + learnhelp: ["/learn [pokemon], [move, move, ...] - Displays how a Pok\u00e9mon can learn the given moves, if it can at all.", + "!learn [pokemon], [move, move, ...] - Show everyone that information. Requires: + % @ # & ~"], }; if (process.send && module === process.mainModule) { @@ -1139,6 +1179,82 @@ function runItemsearch(target, cmd, canAll, message) { return {reply: resultsStr}; } +function runLearn(target, cmd) { + let lsetData = {set:{}}; + let targets = target.split(','); + let template = Tools.getTemplate(targets[0]); + let move = {}; + let problem; + let gen = ({rby:1, gsc:2, adv:3, dpp:4, bw2:5}[cmd.substring(0, 3)] || 6); + let format = 'gen' + gen + 'ou'; + let all = (cmd === 'learnall'); + if (cmd === 'learn5') lsetData.set.level = 5; + if (cmd === 'g6learn') lsetData.format = {noPokebank: true}; + + if (!template.exists) { + return {error: "Pok\u00e9mon '" + template.id + "' not found."}; + } + + if (targets.length < 2) { + return {error: "You must specify at least one move."}; + } + + for (let i = 1, len = targets.length; i < len; i++) { + move = Tools.getMove(targets[i]); + if (!move.exists) { + return {error: "Move '" + move.id + "' not found."}; + } + problem = TeamValidator(format).checkLearnset(move, template.species, lsetData); + if (problem) break; + } + let buffer = ""; + if (format) buffer += "In Gen " + gen + ", "; + buffer += "" + template.name + (problem ? " learn " : " learn ") + (targets.length > 2 ? "these moves" : move.name); + if (!problem) { + let sourceNames = {E:"egg", S:"event", D:"dream world", X:"egg, traded back", Y: "event, traded back"}; + let sourcesBefore = lsetData.sourcesBefore; + if (lsetData.sources || sourcesBefore < gen) buffer += " only when obtained"; + buffer += " from:
"; + } + return {reply: buffer}; +} + function runSearch(query) { return PM.send(query); } diff --git a/chat-plugins/info.js b/chat-plugins/info.js index e45ab01694..a5eab14989 100644 --- a/chat-plugins/info.js +++ b/chat-plugins/info.js @@ -372,97 +372,6 @@ exports.commands = { detailshelp: ["/details [pokemon] - Get additional details on this pokemon/item/move/ability/nature.", "!details [pokemon] - Show everyone these details. Requires: + % @ # & ~"], - learnset: 'learn', - learnall: 'learn', - learn5: 'learn', - g6learn: 'learn', - rbylearn: 'learn', - gsclearn: 'learn', - advlearn: 'learn', - dpplearn: 'learn', - bw2learn: 'learn', - learn: function (target, room, user, connection, cmd) { - if (!target) return this.parse('/help learn'); - - if (!this.canBroadcast()) return; - - let lsetData = {set:{}}; - let targets = target.split(','); - let template = Tools.getTemplate(targets[0]); - let move = {}; - let problem; - let gen = ({rby:1, gsc:2, adv:3, dpp:4, bw2:5}[cmd.substring(0, 3)] || 6); - let format = 'gen' + gen + 'ou'; - let all = (cmd === 'learnall'); - if (cmd === 'learn5') lsetData.set.level = 5; - if (cmd === 'g6learn') lsetData.format = {noPokebank: true}; - - if (!template.exists) { - return this.errorReply("Pok\u00e9mon '" + template.id + "' not found."); - } - - if (targets.length < 2) { - return this.errorReply("You must specify at least one move."); - } - - for (let i = 1, len = targets.length; i < len; i++) { - move = Tools.getMove(targets[i]); - if (!move.exists) { - return this.errorReply("Move '" + move.id + "' not found."); - } - problem = TeamValidator(format).checkLearnset(move, template.species, lsetData); - if (problem) break; - } - let buffer = ""; - if (format) buffer += "In Gen " + gen + ", "; - buffer += "" + template.name + (problem ? " learn " : " learn ") + (targets.length > 2 ? "these moves" : move.name); - if (!problem) { - let sourceNames = {E:"egg", S:"event", D:"dream world", X:"egg, traded back", Y: "event, traded back"}; - let sourcesBefore = lsetData.sourcesBefore; - if (lsetData.sources || sourcesBefore < gen) buffer += " only when obtained"; - buffer += " from:"; - } - this.sendReplyBox(buffer); - }, - learnhelp: ["/learn [pokemon], [move, move, ...] - Displays how a Pok\u00e9mon can learn the given moves, if it can at all.", - "!learn [pokemon], [move, move, ...] - Show everyone that information. Requires: + % @ # & ~"], - weaknesses: 'weakness', weak: 'weakness', resist: 'weakness',