Skip to content

Commit b67443c

Browse files
authored
Merge pull request #2186 from lexicalunit/send-spellbot-deets-to-convoke
Send additional data to Convoke
2 parents 7ef4cb3 + ccd5df7 commit b67443c

File tree

7 files changed

+477
-15
lines changed

7 files changed

+477
-15
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1414
### Added
1515

1616
- More emojis in the messages that SpellBot sends.
17+
- Send additional data to Convoke when creating games.
1718

1819
## [v17.10.2](https://github.com/lexicalunit/spellbot/releases/tag/v17.10.2) - 2026-02-04
1920

src/spellbot/integrations/convoke.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class ConvokeGameTypes(Enum):
7575
Other = "other"
7676

7777

78-
def convoke_game_format(format: GameFormat) -> ConvokeGameTypes: # pragma: no cover
78+
def convoke_game_format(format: GameFormat) -> ConvokeGameTypes:
7979
match format:
8080
case (
8181
GameFormat.COMMANDER
@@ -101,13 +101,13 @@ def convoke_game_format(format: GameFormat) -> ConvokeGameTypes: # pragma: no c
101101
return ConvokeGameTypes.Other
102102

103103

104-
def passphrase() -> str | None: # pragma: no cover
104+
def passphrase() -> str | None:
105105
if USE_PASSWORD:
106106
return f"{random.choice(ADJECTIVES)} {random.choice(NOUNS)}" # noqa: S311
107107
return None
108108

109109

110-
async def fetch_convoke_link( # pragma: no cover
110+
async def fetch_convoke_link(
111111
client: httpx.AsyncClient,
112112
game: GameDict,
113113
key: str | None,
@@ -120,11 +120,14 @@ async def fetch_convoke_link( # pragma: no cover
120120
"apiKey": settings.CONVOKE_API_KEY,
121121
"isPublic": False,
122122
"name": name,
123+
"spellbotGameId": game["id"],
123124
"seatLimit": game["seats"],
124125
"format": format,
125126
"discordGuild": str(game["guild_xid"]),
126127
"discordChannel": str(game["channel_xid"]),
127-
"discordPlayers": [{"id": str(p["xid"]), "name": p["name"]} for p in players],
128+
"discordPlayers": [
129+
{"id": str(p["xid"]), "name": p["name"], "pin": p["pin"]} for p in players
130+
],
128131
}
129132
if game["bracket"] != GameBracket.NONE.value:
130133
payload["bracketLevel"] = f"B{game['bracket'] - 1}"
@@ -137,9 +140,7 @@ async def fetch_convoke_link( # pragma: no cover
137140
return resp.json()
138141

139142

140-
async def generate_link(
141-
game: GameDict,
142-
) -> tuple[str | None, str | None]: # pragma: no cover
143+
async def generate_link(game: GameDict) -> tuple[str | None, str | None]:
143144
if not settings.CONVOKE_API_KEY:
144145
return None, None
145146

@@ -160,6 +161,7 @@ async def generate_link(
160161
attempt + 1,
161162
exc_info=True,
162163
)
164+
continue
163165

164166
if not data:
165167
return None, None

src/spellbot/models/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def import_models() -> None: # pragma: no cover
2727
from .post import Post, PostDict # noqa: E402
2828
from .queue import Queue, QueueDict # noqa: E402
2929
from .token import Token, TokenDict # noqa: E402
30-
from .user import User, UserDict # noqa: E402
30+
from .user import PlayerDataDict, User, UserDict # noqa: E402
3131
from .verify import Verify, VerifyDict # noqa: E402
3232
from .watch import Watch, WatchDict # noqa: E402
3333

@@ -51,6 +51,7 @@ def import_models() -> None: # pragma: no cover
5151
"NotificationDict",
5252
"Play",
5353
"PlayDict",
54+
"PlayerDataDict",
5455
"Post",
5556
"PostDict",
5657
"Queue",

src/spellbot/models/user.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ class UserDict(TypedDict):
2121
banned: bool
2222

2323

24+
class PlayerDataDict(TypedDict):
25+
xid: int
26+
name: str
27+
pin: str | None
28+
29+
2430
class User(Base):
2531
"""Represents a Discord user."""
2632

src/spellbot/services/games.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
GameDict,
2020
GameStatus,
2121
Play,
22+
PlayerDataDict,
2223
Post,
2324
Queue,
2425
QueueDict,
2526
User,
2627
UserAward,
27-
UserDict,
2828
Watch,
2929
)
3030
from spellbot.settings import settings
@@ -579,10 +579,11 @@ def select_last_game(self, user_xid: int, guild_xid: int) -> GameDict | None:
579579

580580
@sync_to_async()
581581
@tracer.wrap()
582-
def player_data(self, game_id: int) -> list[UserDict]:
582+
def player_data(self, game_id: int) -> list[PlayerDataDict]:
583583
game = DatabaseSession.query(Game).filter(Game.id == game_id).first()
584584
if not game:
585585
return []
586-
player_xids = game.player_xids
587-
players = DatabaseSession.query(User).filter(User.xid.in_(player_xids)).all()
588-
return [p.to_dict() for p in players]
586+
587+
player_pins = game.player_pins
588+
players = DatabaseSession.query(User).filter(User.xid.in_(game.player_xids)).all()
589+
return [PlayerDataDict(xid=p.xid, name=p.name, pin=player_pins.get(p.xid)) for p in players]

0 commit comments

Comments
 (0)