Skip to content

Commit 85d583f

Browse files
committed
Improve 'listteams' command
- Add default aliases - Add HTML response
1 parent 6072ec1 commit 85d583f

File tree

4 files changed

+77
-8
lines changed

4 files changed

+77
-8
lines changed

src/bot-modules/battle/commands-teams.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ module.exports = {
209209
this.reply(this.mlt(15) + ' ' + App.server.getControlPanelLink('/temp/' + key));
210210
},
211211

212+
teams: "listteams",
213+
getteams: "listteams",
212214
listteams: function (App) {
213215
this.setLangFile(Lang_File);
214216

215217
if (!this.can('teams', this.room)) return this.replyAccessDenied('teams');
216218

217-
const canCode = this.getRoomType(this.room) === 'chat' && botCanUseCode(this.room, App);
218-
219219
const mod = App.modules.battle.system;
220220

221221
const Teams = mod.TeamBuilder.tools;
@@ -251,13 +251,35 @@ module.exports = {
251251
return " - " + t.name + ": " + Teams.teamOverview(t.packed);
252252
}).join("\n");
253253

254-
if (canCode) {
255-
this.replyCommand(code);
256-
} else {
257-
this.pmReply(code);
258-
}
254+
let html = '';
255+
256+
html += '<div style="overflow: auto; max-height: 300px; width: 100%;">';
257+
258+
html += '<p>' + Text.escapeHTML(this.mlt(14)) + " " + Text.escapeHTML(formatName) + ':</p>';
259+
260+
html += '<table border="1" cellspacing="0" cellpadding="3" style="min-width:100%;">';
261+
262+
html += '<tr>';
263+
html += '<th>' + Text.escapeHTML(this.mlt("teamname")) + '</th>';
264+
html += '<th>' + Text.escapeHTML(this.mlt("pokemon")) + '</th>';
265+
html += '</tr>';
266+
267+
teams.forEach(t => {
268+
const exportedTeam = Teams.exportTeam(t.packed);
269+
html += '<tr>';
270+
html += '<td><b>' + Text.escapeHTML(t.name) + '</b></td>';
271+
html += '<td><details><summary>' + Teams.teamOverviewShowdownHTML(t.packed) + '</summary><pre>' + Text.escapeHTML(exportedTeam) + '</pre></details></td>';
272+
html += '</tr>';
273+
});
274+
275+
html += '</table>';
276+
277+
html += '</div>';
278+
279+
this.htmlRestrictReply(html, "teams", code);
259280
},
260281

282+
team: "getteam",
261283
getteam: function (App) {
262284
this.setLangFile(Lang_File);
263285

src/bot-modules/battle/commands-teams.translations

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ $15 = Teams available for the bot:
3434

3535
$16 = No available teams for format:
3636

37+
$teamname = Team Name
38+
$pokemon = Pokemon
39+
3740
%spanish
3841

3942
$0 = Nombre del equipo
@@ -60,8 +63,11 @@ $12 = Equipo eliminado:
6063

6164
$13 = No poseo equipos para jugar en ningún formato.
6265

63-
$14 = Equipos para el formato:
66+
$14 = Equipos disponibles para el formato:
6467

6568
$15 = Equipos disponibles del bot:
6669

6770
$16 = No poseo equipos para jugar en el formato:
71+
72+
$teamname = Nombre del equipo
73+
$pokemon = Pokemon

src/bot-modules/battle/sprites.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ function getPiconSpan(num) {
497497
return `<span class="picon" style="background:transparent url(${POKE_SPRITES_URL}sprites/pokemonicons-sheet.png?v19) no-repeat scroll -${left}px -${top}px"></span>`;
498498
}
499499

500+
function getPsPokeIcon(name) {
501+
name = Text.toId(name);
502+
return '<psicon pokemon="' + Text.escapeHTML(name) + '"/> ';
503+
}
504+
500505
exports.getPokemonIconAndName = function (poke, App) {
501506
poke = Text.toId(poke);
502507

@@ -524,3 +529,23 @@ exports.getPokemonIconAndName = function (poke, App) {
524529

525530
return getPiconSpan(num) + "&nbsp;" + Text.escapeHTML(name);
526531
};
532+
533+
exports.getPokemonIconAndNameForShowdown = function (poke, App) {
534+
poke = Text.toId(poke);
535+
536+
let pokedex;
537+
try {
538+
pokedex = App.data.getPokedex();
539+
} catch (err) {
540+
App.reportCrash(err);
541+
return getPsPokeIcon('notfound') + "&nbsp;" + poke;
542+
}
543+
544+
if (!pokedex[poke]) {
545+
return getPsPokeIcon('notfound') + "&nbsp;" + poke;
546+
}
547+
548+
let name = pokedex[poke].species || pokedex[poke].name || poke;
549+
550+
return getPsPokeIcon(poke) + "&nbsp;" + Text.escapeHTML(name);
551+
};

src/bot-modules/battle/teams.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,22 @@ exports.setup = function (App) {
423423
return pokes.join(', ');
424424
};
425425

426+
/**
427+
* Gets team HTML overview (pokemon names and icons)
428+
* @param {String} buf - Packed team
429+
* @returns {String} List of pokemon
430+
*/
431+
TeamsTools.teamOverviewShowdownHTML = function (buf) {
432+
let team = fastUnpackTeam(buf);
433+
if (!team) return '(empty)';
434+
let pokes = [];
435+
for (let i = 0; i < team.length; i++) {
436+
pokes.push(SpriteTools.getPokemonIconAndNameForShowdown(team[i].species, App));
437+
}
438+
if (!pokes.length) return '(empty)';
439+
return pokes.join(', ');
440+
};
441+
426442
/**
427443
* Transforms a JSON team to exportable format
428444
* @param {Object} team - JSON team

0 commit comments

Comments
 (0)