Oosie in /force

This commit is contained in:
Casey 2024-11-15 12:40:32 +03:00
parent fd6429ab05
commit 2b3f000e1a
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 7 additions and 6 deletions

View File

@ -77,14 +77,15 @@ async def on_dump(message: Message):
async def on_force(message: Message): async def on_force(message: Message):
if not message.reply_to_message: if not message.reply_to_message:
return return
reply = message.reply_to_message
detected_links: list[tuple[str, float]] = [] detected_links: list[tuple[str, float]] = []
urls = [] urls = []
if message.link_preview_options: if reply.link_preview_options:
urls.append(message.link_preview_options.url) urls.append(reply.link_preview_options.url)
for entity in message.entities or []: for entity in reply.entities or []:
if entity.type in ("text_link", "url") and message.text: if entity.type in ("text_link", "url") and reply.text:
if entity.type == "url": if entity.type == "url":
entity.url = message.text[ entity.url = reply.text[
entity.offset : entity.offset + entity.length entity.offset : entity.offset + entity.length
] ]
if not entity.url: if not entity.url:
@ -98,7 +99,7 @@ async def on_force(message: Message):
n_links = len(detected_links) n_links = len(detected_links)
n_harmful = len(list(filter(lambda lnk: lnk[1] > 0.9, detected_links))) n_harmful = len(list(filter(lambda lnk: lnk[1] > 0.9, detected_links)))
if n_harmful > 0: if n_harmful > 0:
await message.reply_to_message.delete() await reply.delete()
await message.reply(f"Found {n_links} links, {n_harmful} of which look sus") await message.reply(f"Found {n_links} links, {n_harmful} of which look sus")
elif not detected_links: elif not detected_links:
await message.reply(f"No links found") await message.reply(f"No links found")