Add lots of comments and logs

This commit is contained in:
Richard Chien
2018-07-21 00:46:34 +08:00
parent 1c78eb1b80
commit 21db23168f
8 changed files with 94 additions and 34 deletions

View File

@ -9,6 +9,8 @@ from .natural_language import handle_natural_language
async def handle_message(bot: NoneBot, ctx: Dict[str, Any]) -> None:
_log_message(ctx)
if ctx['message_type'] != 'private':
# group or discuss
ctx['to_me'] = False
@ -23,10 +25,21 @@ async def handle_message(bot: NoneBot, ctx: Dict[str, Any]) -> None:
handled = await handle_command(bot, ctx)
if handled:
logger.debug('Message is handled as a command')
logger.info(f'Message {ctx["message_id"]} is handled as a command')
return
handled = await handle_natural_language(bot, ctx)
if handled:
logger.debug('Message is handled as natural language')
logger.info(f'Message {ctx["message_id"]} is handled '
f'as natural language')
return
def _log_message(ctx: Dict[str, Any]) -> None:
msg_from = f'{ctx["user_id"]}'
if ctx['message_type'] == 'group':
msg_from += f'@[群:{ctx["group_id"]}]'
elif ctx['message_type'] == 'discuss':
msg_from += f'@[讨论组:{ctx["discuss_id"]}]'
logger.info(f'Message {ctx["message_id"]} from {msg_from}: '
f'{ctx["message"]}')