mirror of
https://github.com/Xtao-Labs/misskey2telegram.git
synced 2024-11-29 07:57:03 +00:00
feat: format at user
This commit is contained in:
parent
39809106d6
commit
e5a42359d3
@ -1,4 +1,5 @@
|
|||||||
import contextlib
|
import contextlib
|
||||||
|
import re
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from typing import Optional, List
|
from typing import Optional, List
|
||||||
|
|
||||||
@ -21,6 +22,8 @@ from defs.image import webp_to_png
|
|||||||
from init import bot, request
|
from init import bot, request
|
||||||
from models.services.scheduler import add_delete_file_job, delete_file
|
from models.services.scheduler import add_delete_file_job, delete_file
|
||||||
|
|
||||||
|
at_parse = re.compile(r"(?<!\S)@(\S+)\s")
|
||||||
|
|
||||||
|
|
||||||
def get_note_url(host: str, note: Note) -> str:
|
def get_note_url(host: str, note: Note) -> str:
|
||||||
return f"https://{host}/notes/{note.id}"
|
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")
|
return datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
|
||||||
|
def format_at(host: str, content: str) -> str:
|
||||||
|
replaced = rf'<a href="https://{host}/@\1">@\1</a> '
|
||||||
|
return at_parse.sub(replaced, content)
|
||||||
|
|
||||||
|
|
||||||
def get_content(host: str, note: Note) -> str:
|
def get_content(host: str, note: Note) -> str:
|
||||||
content = note.content or ""
|
content = note.content or ""
|
||||||
action = "发表"
|
action = "发表"
|
||||||
@ -95,7 +103,7 @@ def get_content(host: str, note: Note) -> str:
|
|||||||
f"\n{get_user_alink(host, note.reply.author)} "
|
f"\n{get_user_alink(host, note.reply.author)} "
|
||||||
f"发表于 {get_post_time(note.reply.created_at)}"
|
f"发表于 {get_post_time(note.reply.created_at)}"
|
||||||
)
|
)
|
||||||
content = content[:768]
|
content = format_at(host, content[:768])
|
||||||
return f"""<b>Misskey Timeline Update</b>
|
return f"""<b>Misskey Timeline Update</b>
|
||||||
|
|
||||||
{content}
|
{content}
|
||||||
|
Loading…
Reference in New Issue
Block a user