mirror of
https://github.com/Rongronggg9/SlashBot.git
synced 2025-02-07 01:23:29 +08:00
[+] Detect mentions
This commit is contained in:
parent
85d3dd6a6c
commit
cad4ded9f1
17
SlashBot.py
17
SlashBot.py
@ -40,8 +40,25 @@ def get_users(msg):
|
|||||||
else:
|
else:
|
||||||
msg_rpl = msg_from.copy()
|
msg_rpl = msg_from.copy()
|
||||||
from_user, rpl_user = get_user(msg_from), get_user(msg_rpl)
|
from_user, rpl_user = get_user(msg_from), get_user(msg_rpl)
|
||||||
|
|
||||||
|
# Not replying to anything
|
||||||
if rpl_user == from_user:
|
if rpl_user == from_user:
|
||||||
|
|
||||||
|
# Detect if the message contains a mention. If it has, use the mentioned user.
|
||||||
|
entities: List[Dict[str, Union[str, int]]] = msg['entities']
|
||||||
|
mentions = [e for e in entities if e['type'] == 'mention']
|
||||||
|
if mentions:
|
||||||
|
|
||||||
|
# Find username
|
||||||
|
offset = mentions[0]['offset']
|
||||||
|
length = mentions[0]['length']
|
||||||
|
text = msg['text']
|
||||||
|
username = text[offset : offset + length]
|
||||||
|
rpl_user = {'first_name': find_name_by_username(username), 'username': username}
|
||||||
|
|
||||||
|
else:
|
||||||
rpl_user = {'first_name': '自己', 'id': rpl_user['id']}
|
rpl_user = {'first_name': '自己', 'id': rpl_user['id']}
|
||||||
|
|
||||||
return from_user, rpl_user
|
return from_user, rpl_user
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user