Check username for party chat bot
This commit is contained in:
parent
db688ab0d6
commit
d48db4e659
|
|
@ -34,6 +34,12 @@ def check_banned(r, userhash):
|
|||
return True
|
||||
|
||||
|
||||
def check_name(username: str) -> bool:
|
||||
if len(username) >= 16:
|
||||
return False
|
||||
return all(map(lambda c: c.isalnum(), username))
|
||||
|
||||
|
||||
def handle_login(msg, r, from_known_sender):
|
||||
def login_usage():
|
||||
msg.reply("Usage: `/login [NICK] [PASSWORD]`")
|
||||
|
|
@ -45,6 +51,9 @@ def handle_login(msg, r, from_known_sender):
|
|||
if not check_password(parts[2]):
|
||||
ban_sender(r, msg.sender, monotonic() + WRONG_LOGIN_BAN_DURATION)
|
||||
return
|
||||
if not check_name(parts[1]):
|
||||
msg.reply("Name can only consist of alphanumeric characters.")
|
||||
return
|
||||
r.rpush("hswroconference:users", str(json.dumps({
|
||||
"hash": msg.sender,
|
||||
"nick": parts[1],
|
||||
|
|
|
|||
Loading…
Reference in New Issue