Skip to content

Commit

Permalink
[ns] simply card rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyrkul committed May 11, 2024
1 parent d03ce50 commit 6003cbc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -11,7 +11,7 @@ repos:
- id: check-json
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
rev: v0.4.4
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
Expand Down
20 changes: 5 additions & 15 deletions nationstates/nationstates.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,37 +613,27 @@ async def card(
max_len = max(len(buyers), len(sellers))
max_len = min(max_len, max_listed + 1)
for is_buyers, arr in enumerate((sellers, buyers)):
pad = "\n\u200b" * max(0, max_len - len(arr))
if not arr:
embed.add_field(name="Buyers" if is_buyers else "Sellers", value=box(pad))
embed.add_field(name="Buyers" if is_buyers else "Sellers", value=box("\u200b"))
embed.overwrites.set_field_at(
is_buyers + 1,
name=embed.fields[is_buyers + 1].name,
value=box("\u200b", lang="swift"),
)
continue
tarr = [
f"{price:.02f}\xa0{nation}" if is_buyers else f"{nation}\xa0{-price:.02f}"
f"{abs(price):.02f}\xa0{nation}"
for price, _timestamp, nation in heapq.nlargest(max_listed, arr)
]
if len(arr) > max_listed:
num = len(arr) - max_listed
tarr.append(
f"+ {num} more {'bid' if is_buyers else 'ask'}{'' if num == 1 else 's'}\N{HORIZONTAL ELLIPSIS}"
)
raw_text = "\n".join(tarr)
if not is_buyers:
width = max(map(len, tarr))
for i, t in enumerate(tarr):
tarr[i] = t.rjust(width)
text = "\n".join(tarr) + pad
embed.add_field(
name="Buyers" if is_buyers else "Sellers", value=box(text, lang="swift")
)
text = box("\n".join(tarr), lang="swift")
embed.add_field(name="Buyers" if is_buyers else "Sellers", value=text)
embed.overwrites.set_field_at(
is_buyers + 1,
name=embed.fields[is_buyers + 1].name,
value=box(raw_text, lang="swift"),
is_buyers + 1, name=embed.fields[is_buyers + 1].name, value=text
)
await embed.send_to(ctx)

Expand Down

0 comments on commit 6003cbc

Please sign in to comment.