Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #42 : filter names to remove unwanted characters #43

Merged
merged 1 commit into from
Apr 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading