Skip to content

Commit

Permalink
Tour-cmd: Add command: 'tourformatalias'
Browse files Browse the repository at this point in the history
New command to configure format aliases
  • Loading branch information
AgustinSRG committed Dec 16, 2024
1 parent 00c59aa commit 4ebde92
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 8 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "showdown-chatbot",
"version": "2.12.1",
"version": "2.12.2",
"author": {
"name": "Agustin San Roman",
"email": "[email protected]",
Expand Down
3 changes: 3 additions & 0 deletions src/bot-modules/tour-cmd/botmodule.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
},
"tourcustomformat": {
"excepted": true
},
"tourformatalias": {
"excepted": true
}
},
"langfiles": [
Expand Down
116 changes: 114 additions & 2 deletions src/bot-modules/tour-cmd/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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') }));
}

Expand Down Expand Up @@ -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') }));
}

Expand All @@ -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' }));
}
}
};
26 changes: 25 additions & 1 deletion src/bot-modules/tour-cmd/commands.translations
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 6 additions & 2 deletions src/bot-modules/tour-cmd/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -87,7 +91,7 @@ exports.setup = function (App) {
}

formatIsAvailable(name) {
const customFormat = this.findCustomFormat(name);
const customFormat = Config.customFormats[Text.toId(name)];

let format = "";

Expand All @@ -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;
Expand Down

0 comments on commit 4ebde92

Please sign in to comment.