Skip to content

Commit 9ba0f58

Browse files
committed
🆕Add !party command
1 parent 7356328 commit 9ba0f58

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

docs/index.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@
152152
</td>
153153
<td><img src="./images/d2pt.png" alt="d2pt" width="1200"/></td>
154154
</tr>
155+
<tr>
156+
<td>Party Members</td>
157+
<td class="aliases-column">!party</td>
158+
<td>
159+
Show known members from the current party.
160+
</td>
161+
<td><img src="./images/party.png" alt="d2pt" width="1200"/></td>
162+
</tr>
155163
</table>
156164

157165
### Tip for merging 7tv emote sets

src/core/exc_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ async def register_error(self, error: BaseException, embed: discord.Embed, *, me
5050
traceback_string = (
5151
"".join(traceback.format_exception(error))
5252
# Just making code blocks shorter without losing information;
53-
.replace(str(Path.cwd()), "<IreBot>")
54-
.replace("<IreBot>/.venv/lib/python3.12/site-packages", "<venv>")
53+
.replace(f"{Path.cwd()}/src", "<src>")
54+
.replace(f"{Path.cwd()}/.venv/lib/python3.12/site-packages", "<venv>")
5555
)
5656

5757
async with self._lock:

src/modules/public/dota_rp_flow/component.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
from utils import errors, fmt, guards
2121

2222
from .enums import LobbyParam0, ScoreCategory, Status
23-
from .tools import SteamUserConverter, extract_hero_index, is_allowed_to_add_notable, rank_medal_display_name
23+
from .tools import (
24+
PARTY_MEMBERS_PATTERN,
25+
SteamUserConverter,
26+
extract_hero_index,
27+
is_allowed_to_add_notable,
28+
rank_medal_display_name,
29+
)
2430

2531
if TYPE_CHECKING:
2632
from collections.abc import Callable, Coroutine
@@ -1193,6 +1199,32 @@ async def process_pending_abandons(self) -> None:
11931199
# FRIEND PROFILE COMMANDS #
11941200
#################################
11951201

1202+
@commands.command()
1203+
async def party(self, ctx: IreContext) -> None:
1204+
"""Show notable players in the current party."""
1205+
friend = await self.find_friend_account(ctx.broadcaster.id)
1206+
party = friend.rich_presence.raw.get("party")
1207+
if party is None:
1208+
msg = "Streamer is not in a party."
1209+
await ctx.send(msg)
1210+
return
1211+
1212+
steam32_ids = [m.id for m in map(steam.ID, PARTY_MEMBERS_PATTERN.findall(party))]
1213+
1214+
query = """
1215+
SELECT nickname, friend_id
1216+
FROM ttv_dota_notable_players
1217+
WHERE friend_id = ANY($1);
1218+
"""
1219+
rows = await self.bot.pool.fetch(query, steam32_ids)
1220+
nickname_mapping = {row["friend_id"]: row["nickname"] for row in rows}
1221+
1222+
known_party_members = " \N{BULLET} ".join(nickname_mapping.values())
1223+
unknown_party_members = " \N{BULLET} ".join(str(id_) for id_ in steam32_ids if id_ not in nickname_mapping)
1224+
1225+
response = f"{known_party_members} | Unknown party members: {unknown_party_members}"
1226+
await ctx.send(response)
1227+
11961228
async def score_response_helper(self, broadcaster_id: str, stream_started_at: datetime.datetime | None = None) -> str:
11971229
"""Helper function to get !wl commands response."""
11981230
clause = "AND m.start_time > $2" if stream_started_at else ""

src/modules/public/dota_rp_flow/tools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import re
34
from typing import TYPE_CHECKING, Any, override
45

56
import steam
@@ -23,12 +24,14 @@
2324

2425

2526
__all__ = (
27+
"PARTY_MEMBERS_PATTERN",
2628
"SteamUserConverter",
2729
"SteamUserNotFound",
2830
"extract_hero_index",
2931
"rank_medal_display_name",
3032
)
3133

34+
PARTY_MEMBERS_PATTERN = re.compile(r"members\s{\ssteam_id:\s([0-9]+)")
3235

3336
# /* cSpell:disable */
3437
HERO_ALIASES = {

0 commit comments

Comments
 (0)