Corrected NameChangedEvent assumptions and log output to match Owncast webhook payloads.
CI / Formatting (push) Successful in 6s
CI / Linting (push) Successful in 5s
CI / Tests (Python 3.12) (push) Successful in 2m47s
CI / Tests (Python 3.13) (push) Successful in 2m50s
CI / Tests (Python 3.14) (push) Successful in 2m42s
CI / Type Checking (push) Successful in 9s
CI / Spelling (push) Successful in 5s
CI / Formatting (push) Successful in 6s
CI / Linting (push) Successful in 5s
CI / Tests (Python 3.12) (push) Successful in 2m47s
CI / Tests (Python 3.13) (push) Successful in 2m50s
CI / Tests (Python 3.14) (push) Successful in 2m42s
CI / Type Checking (push) Successful in 9s
CI / Spelling (push) Successful in 5s
This commit is contained in:
@@ -224,7 +224,8 @@ class NameChangedEvent:
|
||||
def from_dict(cls, data: dict[str, Any]) -> NameChangedEvent:
|
||||
"""Create a NameChangedEvent from webhook JSON data.
|
||||
|
||||
Note: The user object contains the OLD display name in user.display_name.
|
||||
In Owncast webhook payloads, ``user.display_name`` already
|
||||
reflects the new display name.
|
||||
|
||||
:param data: The event data from the webhook payload.
|
||||
:return: A populated NameChangedEvent instance.
|
||||
@@ -444,9 +445,18 @@ def log_event(event_type: EventType, event: Event) -> None:
|
||||
case UserPartedEvent(user=user):
|
||||
logger.info("[%s] %s parted.", event_type, user.display_name)
|
||||
case NameChangedEvent(user=user, new_name=new_name):
|
||||
logger.info(
|
||||
"[%s] %s changed name to %s.", event_type, user.display_name, new_name
|
||||
# Owncast does not send the old name explicitly, so use the most
|
||||
# recent distinct entry from the user's name history when present.
|
||||
old_name = next(
|
||||
(
|
||||
name
|
||||
for name in reversed(user.previous_names)
|
||||
if name and name != new_name
|
||||
),
|
||||
None,
|
||||
)
|
||||
subject = old_name if old_name is not None else "Display name"
|
||||
logger.info("[%s] %s changed to %s.", event_type, subject, new_name)
|
||||
case StreamStartedEvent(stream_title=title):
|
||||
logger.info('[%s] Stream started: "%s"', event_type, title)
|
||||
case StreamStoppedEvent():
|
||||
|
||||
@@ -174,7 +174,8 @@ def make_name_changed_event(
|
||||
) -> NameChangedEvent:
|
||||
"""Build a NameChangedEvent with sensible test defaults.
|
||||
|
||||
:param user: The user changing names; defaults to ``make_user()``.
|
||||
:param user: The user changing names; defaults to a user whose
|
||||
``display_name`` matches ``new_name``.
|
||||
:param client_id: Client connection identifier.
|
||||
:param new_name: The new display name.
|
||||
:param event_id: Unique event identifier.
|
||||
@@ -182,7 +183,7 @@ def make_name_changed_event(
|
||||
:return: A populated NameChangedEvent instance.
|
||||
"""
|
||||
return NameChangedEvent(
|
||||
user=user if user is not None else make_user(),
|
||||
user=user if user is not None else make_user(display_name=new_name),
|
||||
client_id=client_id,
|
||||
new_name=new_name,
|
||||
event_id=event_id,
|
||||
|
||||
Reference in New Issue
Block a user