Skip to content

Commit

Permalink
fix: fix domain name regex
Browse files Browse the repository at this point in the history
  • Loading branch information
bolinocroustibat committed Jun 11, 2024
1 parent 53fce1a commit 0c3c6cb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/matrix_bot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class BotLibConfig(BaseSettings):


bot_lib_config = BotLibConfig()
print(bot_lib_config.dict())
structlog.configure(
wrapper_class=structlog.make_filtering_bound_logger(bot_lib_config.log_level),
)
Expand Down
6 changes: 3 additions & 3 deletions app/matrix_bot/eventparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def sender_username(self) -> str:
def sender_domain(self) -> str | None:
"""
Sender IDs are formatted like this: "@<mail_username>-<mail_domain>:<matrix_server>
e.g. @john.doe-ministere_example.gouv.fr1:agent.ministere_example.tchap.gouv.fr
e.g. @john.doe-ministere_example.gouv.fr1:agent.ministere_example.tchap.gouv.frmerci
"""
match: re.Match[str] | None = re.search(
r"(?<=\-)(.*?)[0-9]*(?=\:)", self.event.sender
) # match the domain name (between the first "-" and ":", with optional numbers to ignore at the end)
r"(?<=\-)[^\-\:]+[0-9]*(?=\:)", self.event.sender
) # match the domain name (between the last "-" and ":", with optional numbers to ignore at the end of the domain) WARNING: this regex is not perfect and doesn't work for domain names with dashes in it like "developpement-durable.gouv.fr"
if match:
return match.group(0)
logger.warning("Could not extract domain from sender ID", sender_id=self.sender_id)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "albert-tchapbot"
version = "0.1.6"
version = "0.1.7"
description = "Albert Tchap Bot"
authors = [
{ name = "Pôle d'Expertise de la Régulation Numérique", email = "[email protected]" },
Expand Down

0 comments on commit 0c3c6cb

Please sign in to comment.