misskey2telegram/modules/delete.py

32 lines
1.1 KiB
Python
Raw Normal View History

2022-12-24 13:06:37 +00:00
from mipac.errors import APIError, NoSuchNoteError
2022-12-22 14:18:43 +00:00
from pyrogram import Client, filters
from pyrogram.types import Message
2023-01-27 12:36:41 +00:00
from misskey_init import get_misskey_bot
from models.filters import timeline_filter
2022-12-22 14:18:43 +00:00
2023-01-27 15:24:41 +00:00
@Client.on_message(filters.incoming & filters.text & filters.reply & timeline_filter &
filters.command("delete"))
2022-12-22 14:18:43 +00:00
async def delete_command(_: Client, message: Message):
"""
删除
"""
if not message.reply_to_message:
return
if not message.reply_to_message.reply_markup:
return
try:
url = message.reply_to_message.reply_markup.inline_keyboard[0][0].url
note_id = url.split("/")[-1]
except (IndexError, AttributeError):
return
try:
2023-01-27 12:36:41 +00:00
misskey_bot = get_misskey_bot(message.from_user.id)
2022-12-22 14:18:43 +00:00
await misskey_bot.core.api.note.action.delete(note_id)
await message.reply("删除成功", quote=True)
2022-12-24 13:06:37 +00:00
except NoSuchNoteError:
await message.reply("该嘟文不存在", quote=True)
2022-12-22 14:18:43 +00:00
except APIError as e:
await message.reply(f"删除失败 {e}", quote=True)