Skip to content

Commit 306fdd9

Browse files
committed
显示@人的昵称而不是QQ号
1 parent 5ea073b commit 306fdd9

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
- [ ] 贴纸图片过大时自动压缩?
2626
- [ ] GIF转发
2727
- [ ] 显示具体表情而不是表情ID
28-
- [ ] 显示@人的昵称而不是QQ号
28+
- [x] 显示@人的昵称而不是QQ号
2929
- [ ] 双向转发Reply消息 这个可能需要做数据库
3030
- [ ] 在实现Reply消息后 实现转发模式双向转发
3131
...

src/nonebot_plugin_onebot2tg/forwarder.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,14 @@ async def _ob11_message_to_tg(
165165
elif seg.type == "face":
166166
caption_parts.append(f"[表情:{seg.data.get('id', '')}]")
167167
elif seg.type == "at":
168-
caption_parts.append(f"@{seg.data.get('qq', '')}")
168+
at_qq = seg.data.get("qq", "")
169+
at_name = at_qq
170+
try:
171+
stranger_info = await bot.get_stranger_info(user_id=int(at_qq))
172+
at_name = stranger_info.get("nickname", at_qq)
173+
except Exception:
174+
pass
175+
caption_parts.append(f"@{at_name}")
169176
elif seg.type == "reply":
170177
pass
171178
else:

0 commit comments

Comments
 (0)