diff --git a/drb-server-discord-bot/app/commands/trips.py b/drb-server-discord-bot/app/commands/trips.py index a2826a9..f7ff076 100644 --- a/drb-server-discord-bot/app/commands/trips.py +++ b/drb-server-discord-bot/app/commands/trips.py @@ -181,8 +181,9 @@ class TripCommands(commands.Cog): f"{_fmt_date(t.get('end_date', ''))}" ) attendee_count = len(t.get("attendees", {})) + field_name = f"{t['name']} [{status}]"[:256] embed.add_field( - name=f"{t['name']} [{status}]", + name=field_name, value=f"{t.get('location', '?')}\n{dates}\n{attendee_count} going", inline=False, ) @@ -215,8 +216,8 @@ class TripCommands(commands.Cog): ) embed = discord.Embed( - title=data["name"], - description="\n".join(desc_lines), + title=data["name"][:256], + description="\n".join(desc_lines)[:4096], color=0x5865f2, ) @@ -225,19 +226,21 @@ class TripCommands(commands.Cog): for e in data.get("events", []): events_by_date.setdefault(e["date"], []).append(e) + # Track total embed chars (Discord limit: 6000) + embed_chars = len(embed.title or "") + len(embed.description or "") field_count = 0 for day_iso in _date_range(data["start_date"], data["end_date"]): day_events = events_by_date.get(day_iso) if not day_events: continue - if field_count >= 24: + if field_count >= 24 or embed_chars >= 5800: embed.add_field(name="...", value="More events not shown.", inline=False) break day_label = datetime.strptime(day_iso, "%Y-%m-%d").strftime("%A, %b %-d") lines = [] - for e in sorted(day_events, key=lambda x: x.get("time") or ""): - time_str = _fmt_time(e.get("time")) + for e in sorted(day_events, key=lambda x: x.get("start_time") or ""): + time_str = _fmt_time(e.get("start_time")) line = f"**{time_str}** {e['title']}" if time_str else f"- {e['title']}" loc = e.get("location") @@ -258,7 +261,12 @@ class TripCommands(commands.Cog): lines.append(line) - embed.add_field(name=f"— {day_label} —", value="\n".join(lines), inline=False) + field_name = f"— {day_label} —" + field_value = "\n".join(lines) + if len(field_value) > 1024: + field_value = field_value[:1021] + "…" + embed.add_field(name=field_name, value=field_value, inline=False) + embed_chars += len(field_name) + len(field_value) field_count += 1 if not events_by_date: