misskey2telegram/modules/delete.py

31 lines
1015 B
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
2022-12-24 16:10:54 +00:00
from glover import admin
2022-12-22 14:18:43 +00:00
from misskey_init import misskey_bot
2023-01-17 03:26:10 +00:00
@Client.on_message(filters.incoming & filters.text & filters.reply & filters.user(admin) &
2022-12-22 14:18:43 +00:00
filters.command(["delete"]))
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:
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)