From e5a42359d339a7a815194d1d2a3f255392430ef4 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Sat, 22 Jul 2023 10:44:28 +0800 Subject: [PATCH] feat: format at user --- defs/misskey.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/defs/misskey.py b/defs/misskey.py index 8e4cba3..49b43ba 100644 --- a/defs/misskey.py +++ b/defs/misskey.py @@ -1,4 +1,5 @@ import contextlib +import re from datetime import datetime, timedelta, timezone from typing import Optional, List @@ -21,6 +22,8 @@ from defs.image import webp_to_png from init import bot, request from models.services.scheduler import add_delete_file_job, delete_file +at_parse = re.compile(r"(? str: return f"https://{host}/notes/{note.id}" @@ -73,6 +76,11 @@ def get_post_time(date: datetime) -> str: return datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S") +def format_at(host: str, content: str) -> str: + replaced = rf'@\1 ' + return at_parse.sub(replaced, content) + + def get_content(host: str, note: Note) -> str: content = note.content or "" action = "发表" @@ -95,7 +103,7 @@ def get_content(host: str, note: Note) -> str: f"\n{get_user_alink(host, note.reply.author)} " f"发表于 {get_post_time(note.reply.created_at)}" ) - content = content[:768] + content = format_at(host, content[:768]) return f"""Misskey Timeline Update {content}