Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add requester tracking #78

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion discord_sound_streamer/datastore/models/commands.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from dataclasses import dataclass
from datetime import datetime

from hikari import Snowflake
from hikari import Snowflake, User


@dataclass
class LastCommandValue:
executed_at: datetime
channel_id: Snowflake
triggered_by: User
6 changes: 5 additions & 1 deletion discord_sound_streamer/services/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ async def update_last_command_time(ctx: tanjun.abc.Context) -> None:
if ctx.guild_id:
commands_operations.set_last_command(
ctx.guild_id,
LastCommandValue(executed_at=datetime.now(UTC), channel_id=ctx.channel_id),
LastCommandValue(
executed_at=datetime.now(UTC),
channel_id=ctx.channel_id,
triggered_by=ctx.author,
),
)
logger.info(f"Updated last command time for guild {ctx.guild_id}")

Expand Down
13 changes: 12 additions & 1 deletion discord_sound_streamer/services/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
}


def _mention(user_id: int) -> str:
return f"<@{user_id}>"


def _format_timedelta(ms: int) -> str:
if ms > 2**31 - 1:
return "∞"
Expand Down Expand Up @@ -48,7 +52,12 @@ def _apply_track_list_to_embed(embed: Embed, tracks: List[AudioTrack]) -> None:
value=_build_track_link(track),
inline=True,
)
embed.add_field(name="Uploader", value=track.author, inline=True)
if track.requester:
embed.add_field(
name=track.author, value=_mention(track.requester), inline=True
)
else:
embed.add_field(name="Uploader", value=track.author, inline=True)
embed.add_field(
name="Length",
value=_format_timedelta(track.duration),
Expand Down Expand Up @@ -77,6 +86,8 @@ def build_track_embed(
inline=True,
)
embed.add_field(name="Link", value=_build_track_link(track), inline=True)
if track.requester != 0:
embed.add_field(name="Requester", value=_mention(track.requester), inline=True)
return embed


Expand Down
2 changes: 1 addition & 1 deletion discord_sound_streamer/services/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async def _play_tracks(
# wait=wait_fixed(0.25),
# ):
# with attempt:
player.add(track)
player.add(track, requester=author_id)
# except RetryError as re:
# logger.exception(re)

Expand Down