排名优先显示用户名字

This commit is contained in:
机器人总动员 2021-05-07 07:31:07 +08:00
parent 7f30b0434e
commit 1a576e2be7

21
func.py
View File

@ -41,6 +41,25 @@ def chat_content_exec(update, context):
username = update.effective_user.username username = update.effective_user.username
except Exception as e: except Exception as e:
username = update.effective_user.id 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("\n---------------------------")
print("内容: " + text[:10]) print("内容: " + text[:10])
print("群组类型: " + str(chat_type)) print("群组类型: " + str(chat_type))
@ -55,7 +74,7 @@ def chat_content_exec(update, context):
else: else:
r.append("{}_chat_content".format(chat_id), text) r.append("{}_chat_content".format(chat_id), text)
r.incrby("{}_total_message_amount".format(chat_id)) 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("---------------------------") print("---------------------------")