Pinging discord users #2

Open
opened 2025-02-22 14:14:37 -08:00 by jshiffer · 1 comment
Owner

If XMPP users ping discord users, and it's followed by punctuation, it won't work
e.g. @scoliono,

If XMPP users ping discord users, and it's followed by punctuation, it won't work e.g. `@scoliono,`

Pinging also does not work if a ping is preceded by punctuation, as in (@example).

The problem how the Matterbridge uses regular expressions to scan for a Discord username. The relevant functions and definitions are contained in bridge/discord/helpers.go.

Line 163:

userMentionRE    = regexp.MustCompile("@[^@\n]{1,32}")

The regex will only compile if it encounters a string that is precisely a username. A more reasonable regex may look like:

userMentionRE    = regexp.MustCompile("\(*@[^@\n]{1,32}(\'s)?(\,|\:|;|\))*")

Which matches @example, @example;, @example:, @example's, (@example), and (@example's). It may be mechanically explained as (courtesy of this online tool)

- Exactly once: All of:
  -1. Zero or more times: Match '('
  -2. Exactly once: Match '@'
  -3. {1,32} times: Match '[^@\n]'
  -4. Optional: Subexpression: Exactly once: All of:
      1. Exactly once: Match '''
      2. Exactly once: Match 's'
  -5. Zero or more times: Subexpression: Exactly once: One of:
      1. Exactly once: Match ','
      2. Exactly once: Match ':'
      3. Exactly once: Match ';'
      4. Exactly once: Match ')'

This, however, only finds strings that are syntactically valid for adding a ping. The code will also have to extract the username from the string and use that to provide a ping.

Pinging also does not work if a ping is preceded by punctuation, as in `(@example)`. The problem how the Matterbridge uses regular expressions to scan for a Discord username. The relevant functions and definitions are contained in `bridge/discord/helpers.go`. Line 163: ```go userMentionRE = regexp.MustCompile("@[^@\n]{1,32}") ``` The regex will only compile if it encounters a string that is _precisely_ a username. A more reasonable regex may look like: ```go userMentionRE = regexp.MustCompile("\(*@[^@\n]{1,32}(\'s)?(\,|\:|;|\))*") ``` Which matches `@example`, `@example;`, `@example:`, `@example's`, `(@example)`, and `(@example's)`. It may be mechanically explained as (courtesy of [this online tool](https://www.mobzystems.com/online/explain-regular-expression/)) ``` - Exactly once: All of: -1. Zero or more times: Match '(' -2. Exactly once: Match '@' -3. {1,32} times: Match '[^@\n]' -4. Optional: Subexpression: Exactly once: All of: 1. Exactly once: Match ''' 2. Exactly once: Match 's' -5. Zero or more times: Subexpression: Exactly once: One of: 1. Exactly once: Match ',' 2. Exactly once: Match ':' 3. Exactly once: Match ';' 4. Exactly once: Match ')' ``` This, however, only finds strings that are syntactically valid for adding a ping. The code will also have to extract the username from the string and use that to provide a ping.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: lug/matterbridge#2
No description provided.