Skip to content

Commit 7d99fd2

Browse files
committed
fix messaging around subcommand limits
1 parent ff8a7b7 commit 7d99fd2

1 file changed

Lines changed: 32 additions & 5 deletions

File tree

customcommands/assets/customcommands-editcmd.html

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,8 @@ <h2 class="card-title">
441441
{{end}}
442442
</div>
443443
<button type="button" id="slash-option-add" class="btn btn-success btn-sm mt-1"><i class="fas fa-plus"></i> Add Option</button>
444-
<small class="form-text text-muted">Up to 25 Options. Required Options are automatically ordered before optional ones by discord</small>
444+
<small id="slash-option-limit-msg" class="form-text text-muted hidden">You've reached a maximum of 25 options.</small>
445+
<small class="form-text text-muted">Required Options are automatically ordered before optional ones by discord</small>
445446
</div>
446447
</div>
447448
</div>
@@ -474,13 +475,20 @@ <h2 class="card-title">
474475
{{end}}
475476
</div>
476477
<button type="button" class="btn btn-success btn-sm mt-1 slash-subcommand-option-add"><i class="fas fa-plus"></i> Add Option</button>
478+
<small class="form-text text-muted slash-subcommand-option-limit-msg hidden">You've reached a maximum of 25 options.</small>
477479
</div>
478480
</div>
479481
</div>
480482
{{end}}
481483
</div>
482-
<button type="button" id="slash-subcommand-add" class="btn btn-success btn-sm mt-1"><i class="fas fa-plus"></i> Add Subcommand</button>
483-
<small class="form-text text-muted">Up to <span id="slash-subcommand-limit">{{if .IsGuildPremium}}10{{else}}3{{end}}</span> subcommands, each with up to 25 options. Only one subcommand can be expanded at a time.</small>
484+
<button type="button" id="slash-subcommand-add" class="btn btn-success btn-sm mt-1" data-limit="{{if .IsGuildPremium}}10{{else}}3{{end}}"><i class="fas fa-plus"></i> Add Subcommand</button>
485+
<div id="slash-subcommand-limit-msg" class="hidden mt-1">
486+
{{if .IsGuildPremium}}
487+
<small class="form-text text-muted">You've reached the maximum of 10 subcommands.</small>
488+
{{else}}
489+
{{template "cp_premium_nudge" (dict "IsGuildPremium" .IsGuildPremium "Title" "You've reached the free limit of 3 subcommands. Premium servers can have up to 10.")}}
490+
{{end}}
491+
</div>
484492
</div>
485493
</div>
486494
<div class="row">
@@ -1206,6 +1214,12 @@ <h2 class="card-title">Custom Command Information</h2>
12061214

12071215
const count = document.getElementById('slash-options-count');
12081216
if (count) count.textContent = rows.length;
1217+
1218+
const atMax = rows.length >= 25;
1219+
const addBtn = document.getElementById('slash-option-add');
1220+
if (addBtn) addBtn.classList.toggle('hidden', atMax);
1221+
const maxMsg = document.getElementById('slash-option-limit-msg');
1222+
if (maxMsg) maxMsg.classList.toggle('hidden', !atMax);
12091223
}
12101224

12111225
// Show only the per-type extra fields relevant to the selected option type:
@@ -1275,8 +1289,8 @@ <h2 class="card-title">Custom Command Information</h2>
12751289
}
12761290

12771291
function slashSubcommandLimit() {
1278-
const el = document.getElementById('slash-subcommand-limit');
1279-
const n = el ? parseInt(el.textContent, 10) : 3;
1292+
const btn = document.getElementById('slash-subcommand-add');
1293+
const n = btn ? parseInt(btn.getAttribute('data-limit'), 10) : 3;
12801294
return isNaN(n) ? 3 : n;
12811295
}
12821296

@@ -1322,9 +1336,22 @@ <h2 class="card-title">Custom Command Information</h2>
13221336
});
13231337
const optCount = card.querySelector('.slash-subcommand-optcount');
13241338
if (optCount) optCount.textContent = rows.length;
1339+
const optAtMax = rows.length >= 25;
1340+
const optAdd = card.querySelector('.slash-subcommand-option-add');
1341+
if (optAdd) optAdd.classList.toggle('hidden', optAtMax);
1342+
const optMaxMsg = card.querySelector('.slash-subcommand-option-limit-msg');
1343+
if (optMaxMsg) optMaxMsg.classList.toggle('hidden', !optAtMax);
13251344
});
13261345
const count = document.getElementById('slash-subcommands-count');
13271346
if (count) count.textContent = cards.length;
1347+
1348+
// Disable the add button and surface the premium nudge / max-reached message
1349+
// once the subcommand limit (3 free / 10 premium) is hit.
1350+
const limit = slashSubcommandLimit();
1351+
const addBtn = document.getElementById('slash-subcommand-add');
1352+
if (addBtn) addBtn.disabled = cards.length >= limit;
1353+
const limitMsg = document.getElementById('slash-subcommand-limit-msg');
1354+
if (limitMsg) limitMsg.classList.toggle('hidden', cards.length < limit);
13281355
}
13291356

13301357
// Show the flat-options editor or the subcommands editor depending on the toggle.

0 commit comments

Comments
 (0)