From 1a576e2be7b7d145aa9b1f725b9be937269d7a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=BA=E5=99=A8=E4=BA=BA=E6=80=BB=E5=8A=A8=E5=91=98?= <73592731+devourbots@users.noreply.github.com> Date: Fri, 7 May 2021 07:31:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E5=90=8D=E4=BC=98=E5=85=88=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=94=A8=E6=88=B7=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- func.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/func.py b/func.py index f641b69..467c799 100644 --- a/func.py +++ b/func.py @@ -41,6 +41,25 @@ def chat_content_exec(update, context): username = update.effective_user.username except Exception as e: username = update.effective_user.id + user = update.message.from_user + try: + firstname = user["firstname"] + except Exception as e: + print("用户没有设置 firstname") + firstname = "" + try: + last_name = user["last_name"] + except Exception as e: + print("用户没有设置 last_name") + last_name = "" + if len(firstname) == 0 and len(last_name) == 0: + name = username + elif len(firstname) == 0 and len(last_name) != 0: + name = last_name + elif len(firstname) != 0 and len(last_name) == 0: + name = firstname + elif len(firstname) != 0 and len(last_name) != 0: + name = firstname + " " + last_name print("\n---------------------------") print("内容: " + text[:10]) print("群组类型: " + str(chat_type)) @@ -55,7 +74,7 @@ def chat_content_exec(update, context): else: r.append("{}_chat_content".format(chat_id), text) r.incrby("{}_total_message_amount".format(chat_id)) - r.hincrby("{}_user_message_amount".format(chat_id), username) + r.hincrby("{}_user_message_amount".format(chat_id), name) print("---------------------------")