diff --git a/package-lock.json b/package-lock.json index 86bbb56..25608fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "showdown-chatbot", - "version": "2.12.1", + "version": "2.12.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "showdown-chatbot", - "version": "2.12.1", + "version": "2.12.2", "license": "MIT", "dependencies": { "busboy": "1.6.0", diff --git a/package.json b/package.json index f3d0578..2252d61 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "showdown-chatbot", - "version": "2.12.1", + "version": "2.12.2", "author": { "name": "Agustin San Roman", "email": "agustinsanromanguzman@gmail.com", diff --git a/src/bot-modules/tour-cmd/botmodule.json b/src/bot-modules/tour-cmd/botmodule.json index e8e84e5..a0caa4b 100644 --- a/src/bot-modules/tour-cmd/botmodule.json +++ b/src/bot-modules/tour-cmd/botmodule.json @@ -20,6 +20,9 @@ }, "tourcustomformat": { "excepted": true + }, + "tourformatalias": { + "excepted": true } }, "langfiles": [ diff --git a/src/bot-modules/tour-cmd/commands.js b/src/bot-modules/tour-cmd/commands.js index 315938d..703ddeb 100644 --- a/src/bot-modules/tour-cmd/commands.js +++ b/src/bot-modules/tour-cmd/commands.js @@ -5,6 +5,7 @@ * tourlog: Gets a register of the must recent tournaments * tourpollset: Configures the sets for the tournament polls * tourcustomformat: Configures custom formats for tournaments + * tourformatalias: Configures format aliases */ 'use strict'; @@ -577,7 +578,7 @@ module.exports = { case "remove": case "rm": { - if (this.args.length < 2) { + if (this.args.length !== 2) { return this.errorReply(this.usage({ desc: 'delete' }, { desc: this.mlt('name') })); } @@ -693,7 +694,7 @@ module.exports = { case "remove": case "rm": { - if (this.args.length < 2) { + if (this.args.length !== 2) { return this.errorReply(this.usage({ desc: 'delete' }, { desc: this.mlt('name') })); } @@ -720,5 +721,116 @@ module.exports = { default: return this.errorReply(this.usage({ desc: 'list | add | delete' })); } + }, + + tourformatalias: function (App) { + this.setLangFile(Lang_File); + + if (!this.can('tourformatalias', this.room)) return this.replyAccessDenied('tourformatalias'); + + const Config = App.config.modules.tourcmd; + const Mod = App.modules.tourcmd.system; + + const subCommand = Text.toId(this.args[0] || ""); + + switch (subCommand) { + case "list": + { + const aliases = Object.keys(Config.aliases); + + if (aliases.length === 0) { + return this.errorReply(this.mlt("aliaseslistempty")); + } + + let text = "" + this.mlt("aliaseslist") + ":\n\n"; + + for (let alias of aliases) { + const formatName = Mod.getFormatName(Config.aliases[alias]); + + text += alias + " = " + formatName + "\n"; + } + + this.replyCommand("!code " + text); + } + break; + case "add": + case "set": + { + if (this.args.length !== 3) { + return this.errorReply(this.usage({ desc: 'add' }, { desc: this.mlt('alias') }, { desc: this.mlt('format') })); + } + + const name = (this.args[1] + "").trim(); + const id = Text.toId(name); + + if (!id) { + return this.errorReply(this.usage({ desc: 'add' }, { desc: this.mlt('alias') }, { desc: this.mlt('format') })); + } + + let format = Text.toId(this.args[2]); + + const customFormat = Mod.findCustomFormat(format); + + if (customFormat) { + format = customFormat.name || format; + } else { + format = parseAliases(Text.toId(format), App); + + const formatData = App.bot.formats[format]; + + if (!formatData) { + return this.errorReply(this.mlt('e31') + ' ' + Chat.italics(format) + + ' ' + this.mlt('e32')); + } + + if (!formatData.chall || formatData.disableTournaments) { + return this.errorReply(this.mlt('e31') + ' ' + Chat.italics(formatData.name) + + ' ' + this.mlt('e32')); + } + + format = formatData.name; + } + + Config.aliases[id] = Text.toId(format); + + App.db.write(); + + this.addToSecurityLog(); + + this.reply(this.mlt('aliassetok1') + " " + Chat.italics(name) + " " + this.mlt("aliassetok2")); + } + break; + case "delete": + case "del": + case "remove": + case "rm": + { + if (this.args.length !== 2) { + return this.errorReply(this.usage({ desc: 'delete' }, { desc: this.mlt('name') })); + } + + const name = (this.args[1] + "").trim(); + const id = Text.toId(name); + + if (!id) { + return this.errorReply(this.usage({ desc: 'delete' }, { desc: this.mlt('name') })); + } + + if (!Config.aliases[id]) { + return this.errorReply(this.mlt('aliasnotfound')); + } + + delete Config.aliases[id]; + + App.db.write(); + + this.addToSecurityLog(); + + this.reply(this.mlt('aliasdelok1') + " " + Chat.italics(name) + " " + this.mlt("aliasdelok2")); + } + break; + default: + return this.errorReply(this.usage({ desc: 'list | add | delete' })); + } } }; diff --git a/src/bot-modules/tour-cmd/commands.translations b/src/bot-modules/tour-cmd/commands.translations index 6c13ba2..7986e43 100644 --- a/src/bot-modules/tour-cmd/commands.translations +++ b/src/bot-modules/tour-cmd/commands.translations @@ -82,11 +82,23 @@ $rule = Rule $formatsetok1 = The custom format $formatsetok2 = has been successfully configured -$formatnotfound = The specified custom format does not exists or cannot be deleted +$formatnotfound = The specified custom format does not exist $formatdelok1 = The custom format $formatdelok2 = has been successfully deleted +$aliaseslist = List of format aliases for tournaments + +$aliaseslistempty = There are not any format aliases in the list yet + +$aliassetok1 = The format alias +$aliassetok2 = has been successfully configured + +$aliasnotfound = The specified format alias does not exist + +$aliasdelok1 = The format alias +$aliasdelok2 = has been successfully deleted + %spanish $nochat = Este comando solo está disponible para las salas de chat @@ -169,3 +181,15 @@ $formatnotfound = El formato personalizado especificado no existe $formatdelok1 = El formato personalizado $formatdelok2 = ha sido eliminado correctamente + +$aliaseslist = Lista de alias de formatos para torneos + +$aliaseslistempty = La lista de alias de formatos para torneos se encuentra vacía + +$aliassetok1 = El alias de formato +$aliassetok2 = ha sido configurado correctamente + +$aliasnotfound = El alias de formato especificado no existe + +$aliasdelok1 = El alias de formato +$aliasdelok2 = ha sido eliminado correctamente diff --git a/src/bot-modules/tour-cmd/main.js b/src/bot-modules/tour-cmd/main.js index 93948f4..29e477d 100644 --- a/src/bot-modules/tour-cmd/main.js +++ b/src/bot-modules/tour-cmd/main.js @@ -34,6 +34,10 @@ exports.setup = function (App) { const Config = App.config.modules.tourcmd; + if (!Config.aliases) { + Config.aliases = Object.create(null); + } + if (!Config.pollSets) { Config.pollSets = Object.create(null); } @@ -87,7 +91,7 @@ exports.setup = function (App) { } formatIsAvailable(name) { - const customFormat = this.findCustomFormat(name); + const customFormat = Config.customFormats[Text.toId(name)]; let format = ""; @@ -111,7 +115,7 @@ exports.setup = function (App) { } getFormatName(name) { - const customFormat = this.findCustomFormat(name); + const customFormat = Config.customFormats[Text.toId(name)]; if (customFormat) { return customFormat.name;