Skip to content

Commit

Permalink
Merge pull request #43 from bepolytech/fix-numbers-in-names
Browse files Browse the repository at this point in the history
fix #42 : filter names to remove unwanted characters
  • Loading branch information
LucasPlacentino authored Apr 1, 2024
2 parents 30eea13 + 1f5eed9 commit d33c40a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion classes/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Dict
from typing import List
from typing import Tuple
from string import ascii_letters

import disnake
from disnake.ext import commands
Expand Down Expand Up @@ -519,7 +520,10 @@ async def _register_user_step(self, inter: disnake.ModalInteraction) -> None:
The modal interaction that triggered the step
"""
# Extract name and store the user
name = " ".join([name.title() for name in self.email.split("@")[0].split(".")])
allowed_chars = set(ascii_letters + " ") # or set('abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ')
unfiltered_name = " ".join([name.title() for name in self.email.split("@")[0].split(".")])
name = "".join(filter(allowed_chars.__contains__, unfiltered_name)) # remove all characters that aren't ASCII letters or a space

logging.trace(f"[RegistrationForm] [User:{self.target.id}] Extracted name from email= {name}")
Database.set_user(self.target, name, self.email)
await self._stop()
Expand Down

0 comments on commit d33c40a

Please sign in to comment.