2023-01-27 12:36:41 +00:00
|
|
|
from typing import Optional, Union
|
2022-12-24 08:31:16 +00:00
|
|
|
|
2023-01-27 12:36:41 +00:00
|
|
|
from mipac import File
|
2022-12-24 08:31:16 +00:00
|
|
|
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
|
|
|
|
2023-01-27 12:36:41 +00:00
|
|
|
from misskey_init import get_misskey_bot
|
2022-12-24 08:31:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ReadySend:
|
|
|
|
def __init__(
|
2023-07-03 14:39:52 +00:00
|
|
|
self,
|
|
|
|
content: str,
|
|
|
|
reply_id: Optional[str] = None,
|
|
|
|
files: Optional[list[Union[str, File]]] = None,
|
2022-12-24 08:31:16 +00:00
|
|
|
):
|
|
|
|
self.content = content
|
|
|
|
self.reply_id = reply_id
|
|
|
|
self.files = files
|
|
|
|
|
|
|
|
async def confirm(self, msg: Message):
|
|
|
|
msg = await msg.reply(
|
|
|
|
"确认发送?",
|
|
|
|
quote=True,
|
|
|
|
reply_markup=InlineKeyboardMarkup(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
InlineKeyboardButton(text="发送", callback_data="send"),
|
2023-07-03 14:39:52 +00:00
|
|
|
InlineKeyboardButton(text="拒绝", callback_data="delete"),
|
2022-12-24 08:31:16 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
),
|
|
|
|
)
|
2023-01-27 12:36:41 +00:00
|
|
|
ready_send[(msg.chat.id, msg.id)] = self
|
2022-12-24 08:31:16 +00:00
|
|
|
|
2023-01-27 12:36:41 +00:00
|
|
|
async def send(self, msg: Message, user_id: int):
|
2022-12-24 08:31:16 +00:00
|
|
|
try:
|
2023-01-27 12:36:41 +00:00
|
|
|
misskey_bot = get_misskey_bot(user_id)
|
2022-12-24 08:31:16 +00:00
|
|
|
await misskey_bot.core.api.note.action.send(
|
2023-03-10 14:52:18 +00:00
|
|
|
content=self.content or None,
|
2022-12-24 08:31:16 +00:00
|
|
|
reply_id=self.reply_id,
|
|
|
|
files=self.files,
|
|
|
|
)
|
|
|
|
except Exception as e:
|
|
|
|
await msg.edit(f"发送失败:{e}")
|
|
|
|
else:
|
2023-01-17 17:11:26 +00:00
|
|
|
await msg.delete()
|
|
|
|
finally:
|
2023-01-27 12:36:41 +00:00
|
|
|
del ready_send[(msg.chat.id, msg.id)]
|
2023-01-17 17:11:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ReadySendMessage:
|
|
|
|
def __init__(
|
2023-07-03 14:39:52 +00:00
|
|
|
self,
|
|
|
|
text: str,
|
|
|
|
group: bool = False,
|
|
|
|
uid: Optional[str] = None,
|
|
|
|
file_id: Optional[str] = None,
|
2023-01-17 17:11:26 +00:00
|
|
|
):
|
|
|
|
self.text = text
|
|
|
|
self.user_id = None if group else uid
|
|
|
|
self.group_id = uid if group else None
|
|
|
|
self.file_id = file_id
|
|
|
|
|
|
|
|
async def confirm(self, msg: Message):
|
|
|
|
msg = await msg.reply(
|
|
|
|
"确认发送?",
|
|
|
|
quote=True,
|
|
|
|
reply_markup=InlineKeyboardMarkup(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
InlineKeyboardButton(text="发送", callback_data="chat_send"),
|
2023-07-03 14:39:52 +00:00
|
|
|
InlineKeyboardButton(text="拒绝", callback_data="delete"),
|
2023-01-17 17:11:26 +00:00
|
|
|
]
|
|
|
|
]
|
|
|
|
),
|
|
|
|
)
|
2023-01-27 12:36:41 +00:00
|
|
|
ready_send[(msg.chat.id, msg.id)] = self
|
2023-01-17 17:11:26 +00:00
|
|
|
|
2023-01-27 12:36:41 +00:00
|
|
|
async def send(self, msg: Message, user_id: int):
|
2023-01-17 17:11:26 +00:00
|
|
|
try:
|
2023-01-27 12:36:41 +00:00
|
|
|
misskey_bot = get_misskey_bot(user_id)
|
2023-01-17 17:11:26 +00:00
|
|
|
await misskey_bot.core.api.chat.action.send(
|
2023-03-10 14:52:18 +00:00
|
|
|
text=self.text or None,
|
2023-01-17 17:11:26 +00:00
|
|
|
user_id=self.user_id,
|
|
|
|
group_id=self.group_id,
|
|
|
|
file_id=self.file_id,
|
|
|
|
)
|
|
|
|
except Exception as e:
|
|
|
|
await msg.edit(f"发送失败:{e}")
|
|
|
|
else:
|
|
|
|
await msg.delete()
|
2022-12-24 08:31:16 +00:00
|
|
|
finally:
|
2023-01-27 12:36:41 +00:00
|
|
|
del ready_send[(msg.chat.id, msg.id)]
|
2022-12-24 08:31:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
ready_send = {}
|