2020-03-15 22:48:22 +08:00
|
|
|
from aiocqhttp import Event as CQEvent
|
|
|
|
|
2018-07-04 09:28:31 +08:00
|
|
|
from . import NoneBot
|
2018-12-22 12:44:10 +08:00
|
|
|
from .helpers import send
|
2020-03-15 22:48:22 +08:00
|
|
|
from .typing import Message_T
|
2018-06-27 22:05:12 +08:00
|
|
|
|
|
|
|
|
|
|
|
class BaseSession:
|
2020-03-15 22:48:22 +08:00
|
|
|
__slots__ = ('bot', 'event')
|
2018-06-27 22:05:12 +08:00
|
|
|
|
2020-03-15 22:48:22 +08:00
|
|
|
def __init__(self, bot: NoneBot, event: CQEvent):
|
2018-06-27 22:05:12 +08:00
|
|
|
self.bot = bot
|
2020-03-15 22:48:22 +08:00
|
|
|
self.event = event
|
|
|
|
|
|
|
|
@property
|
|
|
|
def ctx(self) -> CQEvent:
|
|
|
|
return self.event
|
|
|
|
|
|
|
|
@ctx.setter
|
|
|
|
def ctx(self, val: CQEvent) -> None:
|
|
|
|
self.event = val
|
2018-06-27 22:05:12 +08:00
|
|
|
|
2019-01-05 22:36:47 +08:00
|
|
|
@property
|
|
|
|
def self_id(self) -> int:
|
2020-03-15 22:48:22 +08:00
|
|
|
return self.event.self_id
|
2019-01-05 22:36:47 +08:00
|
|
|
|
2018-10-16 01:03:50 +08:00
|
|
|
async def send(self, message: Message_T, *,
|
2018-12-23 20:20:40 +08:00
|
|
|
at_sender: bool = False,
|
|
|
|
ensure_private: bool = False,
|
|
|
|
ignore_failure: bool = True,
|
|
|
|
**kwargs) -> None:
|
|
|
|
"""
|
|
|
|
Send a message ignoring failure by default.
|
|
|
|
|
|
|
|
:param message: message to send
|
|
|
|
:param at_sender: @ the sender if in group or discuss chat
|
|
|
|
:param ensure_private: ensure the message is sent to private chat
|
|
|
|
:param ignore_failure: if any CQHttpError raised, ignore it
|
|
|
|
:return: the result returned by CQHTTP
|
|
|
|
"""
|
2020-03-15 22:48:22 +08:00
|
|
|
return await send(self.bot, self.event, message,
|
2018-12-23 20:20:40 +08:00
|
|
|
at_sender=at_sender,
|
|
|
|
ensure_private=ensure_private,
|
|
|
|
ignore_failure=ignore_failure, **kwargs)
|