nonebot2/none/session.py

26 lines
886 B
Python
Raw Normal View History

2018-06-27 14:05:12 +00:00
from typing import Union, Callable, Dict, Any, List, Sequence
2018-07-04 01:28:31 +00:00
from . import NoneBot
2018-06-27 14:05:12 +00:00
from .helpers import send, send_expr
class BaseSession:
__slots__ = ('bot', 'ctx')
2018-07-04 01:28:31 +00:00
def __init__(self, bot: NoneBot, ctx: Dict[str, Any]):
2018-06-27 14:05:12 +00:00
self.bot = bot
self.ctx = ctx
async def send(self,
message: Union[str, Dict[str, Any], List[Dict[str, Any]]],
*, ignore_failure: bool = True) -> None:
2018-07-04 11:50:42 +00:00
"""Send a message ignoring failure by default."""
2018-06-27 14:05:12 +00:00
return await send(self.bot, self.ctx, message,
ignore_failure=ignore_failure)
async def send_expr(self,
expr: Union[str, Sequence[str], Callable],
**kwargs):
2018-07-04 11:50:42 +00:00
"""Sending a expression message ignoring failure by default."""
2018-06-27 14:05:12 +00:00
return await send_expr(self.bot, self.ctx, expr, **kwargs)