Skip to content

Commit d95659d

Browse files
committed
Fix invoice ID truncation bug in Discord autocomplete
Fixed a bug where truncating app_commands.Choice.value broke subsequent invoice lookups. Now overlong IDs are skipped entirely, and display names are gracefully truncated with ellipses.
1 parent 3406e0d commit d95659d

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

  • apps/discord_bot/src/five08/discord_bot/cogs

apps/discord_bot/src/five08/discord_bot/cogs/erpnext.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,25 @@ async def invoice_name_autocomplete(
222222
)
223223
choices = []
224224
for inv in invoices[:25]:
225+
inv_name = inv.get("name")
226+
# Ensure inv_name is a valid string and within Discord's 100-char limit
227+
if not isinstance(inv_name, str) or len(inv_name) > 100:
228+
continue # Skip invalid or overlong IDs to prevent lookup/API failures
229+
225230
try:
226231
status_int = int(inv.get("docstatus", 0))
227232
except (TypeError, ValueError):
228233
status_int = -1
229-
label = f"[{STATUS_LABEL.get(status_int, '?')}] {inv['name']} · {inv.get('owner', '')} · {inv.get('posting_date', '')}"
234+
235+
label = f"[{STATUS_LABEL.get(status_int, '?')}] {inv_name} · {inv.get('owner', '')} · {inv.get('posting_date', '')}"
236+
237+
# If label exceeds 100 chars, truncate gracefully with trailing dots
238+
display_name = label if len(label) <= 100 else f"{label[:97]}..."
239+
230240
choices.append(
231241
app_commands.Choice(
232-
name=label[:100],
233-
value=inv["name"][:100],
242+
name=display_name,
243+
value=inv_name,
234244
)
235245
)
236246
return choices

0 commit comments

Comments
 (0)