sfan5 2020-09-02 17:52:08 +02:00
parent cb4c974631
commit 4a09534362
1 changed files with 5 additions and 3 deletions

View File

@ -201,13 +201,11 @@ def handle_private(ev):
# refresh user in db # refresh user in db
now = datetime.now() now = datetime.now()
was_new_user = False
with db_modify_user(ev.chat.id, allow_new=True) as user: with db_modify_user(ev.chat.id, allow_new=True) as user:
if user.id is None: if user.id is None:
user.defaults() user.defaults()
user.id = ev.chat.id user.id = ev.chat.id
assert ev.chat.id == ev.from_user.id assert ev.chat.id == ev.from_user.id
was_new_user = True
user.username = ev.from_user.username user.username = ev.from_user.username
user.realname = ev.from_user.first_name user.realname = ev.from_user.first_name
if ev.from_user.last_name: if ev.from_user.last_name:
@ -264,6 +262,10 @@ def handle_private_command(ev, user, c):
### Helpers ### Helpers
def str_is_printable(s):
NOT_PRINTABLE = (0x20, 0x115f, 0x1160, 0x3164, 0xffa0)
return any((c.isprintable() and ord(c) not in NOT_PRINTABLE) for c in s)
def parse_timedelta(s): def parse_timedelta(s):
if len(s) < 2 or not s[:-1].isdigit(): if len(s) < 2 or not s[:-1].isdigit():
return return
@ -286,7 +288,7 @@ def format_datetime(dt):
def format_user_info(user): def format_user_info(user):
realname = user.realname realname = user.realname
if not any(c.isprintable() for c in realname): if not str_is_printable(realname):
realname = "<empty name>" realname = "<empty name>"
s = "User: <a href=\"tg://user?id=%d\">%s</a>" % ( s = "User: <a href=\"tg://user?id=%d\">%s</a>" % (
user.id, escape_html(realname)) user.id, escape_html(realname))