Improve code docs

This commit is contained in:
Richard Chien
2018-07-01 20:01:05 +08:00
parent 6ec3ac66f7
commit 026d83e507
9 changed files with 100 additions and 39 deletions

View File

@ -5,7 +5,10 @@ from aiocqhttp import CQHttp, Error as CQHttpError
from . import expression
def context_source(ctx: Dict[str, Any]) -> str:
def context_id(ctx: Dict[str, Any]) -> str:
"""
Calculate a unique id representing the current user.
"""
src = ''
if ctx.get('group_id'):
src += f'/group/{ctx["group_id"]}'
@ -19,6 +22,9 @@ def context_source(ctx: Dict[str, Any]) -> str:
async def send(bot: CQHttp, ctx: Dict[str, Any],
message: Union[str, Dict[str, Any], List[Dict[str, Any]]],
*, ignore_failure: bool = True) -> None:
"""
Send a message ignoring failure by default.
"""
try:
if ctx.get('post_type') == 'message':
await bot.send(ctx, message)
@ -40,4 +46,7 @@ async def send(bot: CQHttp, ctx: Dict[str, Any],
async def send_expr(bot: CQHttp, ctx: Dict[str, Any],
expr: Union[str, Sequence[str], Callable],
**kwargs):
"""
Sending a expression message ignoring failure by default.
"""
return await send(bot, ctx, expression.render(expr, **kwargs))