Charcoal-SE / PulseMonitor

PulseMonitor is the chat interface to Halflife.
MIT License
4 stars 3 forks source link

Notifications don't normalize the displayname #23

Closed mjpieters closed 5 years ago

mjpieters commented 5 years ago

I get notified by halflife with @Martijn Pieters, with a space, so other @Martijn's in a room would get the same notification. Display names should really be normalized.

Chat notifications use the same rules as @comment reply notifications, so this post by Atwood should apply. Remove everything other than the regex.

This should suffice:

import re

def at_notification_name(username, _sub=re.compile(r"[^\w'.-]*").sub):
    """Produce the @DisplayName notification normazilation form"""
    return "@" + _sub('', username)

then use this function when generating notifications:

        if notifications:
            return ' '.join([post] + [
               at_notification_name(self.users[str(user)]) for user in notifications])