mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-10-21 16:27:15 +08:00
commit
5c35e06065
@ -10,7 +10,8 @@ from nonebot.params import CommandArg, ArgPlainText
|
|||||||
from nonebot.adapters.onebot.v11 import Bot, Message, MessageEvent, PrivateMessageEvent, FriendRequestEvent, \
|
from nonebot.adapters.onebot.v11 import Bot, Message, MessageEvent, PrivateMessageEvent, FriendRequestEvent, \
|
||||||
GroupRequestEvent, \
|
GroupRequestEvent, \
|
||||||
RequestEvent, NoticeEvent, \
|
RequestEvent, NoticeEvent, \
|
||||||
GroupIncreaseNoticeEvent, FriendAddNoticeEvent, GroupMessageEvent
|
GroupIncreaseNoticeEvent, FriendAddNoticeEvent, GroupMessageEvent, \
|
||||||
|
ActionFailed
|
||||||
from nonebot.typing import T_State
|
from nonebot.typing import T_State
|
||||||
|
|
||||||
from LittlePaimon.config import config as bot_config
|
from LittlePaimon.config import config as bot_config
|
||||||
@ -105,7 +106,10 @@ async def _(event: PrivateMessageEvent, bot: Bot, state: T_State, id_: str = Arg
|
|||||||
@requests.handle()
|
@requests.handle()
|
||||||
async def _(bot: Bot, event: FriendRequestEvent):
|
async def _(bot: Bot, event: FriendRequestEvent):
|
||||||
done[f'add_friend_{event.user_id}'] = datetime.datetime.now()
|
done[f'add_friend_{event.user_id}'] = datetime.datetime.now()
|
||||||
|
try:
|
||||||
user_info = await bot.get_stranger_info(user_id=event.user_id)
|
user_info = await bot.get_stranger_info(user_id=event.user_id)
|
||||||
|
except ActionFailed:
|
||||||
|
user_info = {'nickname': '未知'}
|
||||||
base_msg = f'{user_info["nickname"]}({event.user_id})请求添加好友,验证信息为"{event.comment or "无"}"'
|
base_msg = f'{user_info["nickname"]}({event.user_id})请求添加好友,验证信息为"{event.comment or "无"}"'
|
||||||
if bot_config.auto_add_friend:
|
if bot_config.auto_add_friend:
|
||||||
await asyncio.sleep(random.randint(10, 20))
|
await asyncio.sleep(random.randint(10, 20))
|
||||||
@ -121,8 +125,14 @@ async def _(bot: Bot, event: FriendRequestEvent):
|
|||||||
@requests.handle()
|
@requests.handle()
|
||||||
async def _(bot: Bot, event: GroupRequestEvent):
|
async def _(bot: Bot, event: GroupRequestEvent):
|
||||||
done[f'add_group_{event.group_id}'] = datetime.datetime.now()
|
done[f'add_group_{event.group_id}'] = datetime.datetime.now()
|
||||||
|
try:
|
||||||
user_info = await bot.get_stranger_info(user_id=event.user_id)
|
user_info = await bot.get_stranger_info(user_id=event.user_id)
|
||||||
|
except ActionFailed:
|
||||||
|
user_info = {'nickname': '未知'}
|
||||||
|
try:
|
||||||
group_info = await bot.get_group_info(group_id=event.group_id)
|
group_info = await bot.get_group_info(group_id=event.group_id)
|
||||||
|
except ActionFailed:
|
||||||
|
group_info = {'group_name': '未知'}
|
||||||
base_msg = f'{user_info["nickname"]}({event.user_id})邀请{NICKNAME}加入群{group_info["group_name"]}({event.group_id})'
|
base_msg = f'{user_info["nickname"]}({event.user_id})邀请{NICKNAME}加入群{group_info["group_name"]}({event.group_id})'
|
||||||
if bot_config.auto_add_group or event.user_id in SUPERUSERS:
|
if bot_config.auto_add_group or event.user_id in SUPERUSERS:
|
||||||
await asyncio.sleep(random.randint(10, 20))
|
await asyncio.sleep(random.randint(10, 20))
|
||||||
|
@ -11,13 +11,13 @@ class logger:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def info(command: str, info: str = '', param: Dict[str, any] = None, result: str = '', result_type: bool = True):
|
def info(command: str, info: str = '', param: Dict[str, any] = None, result: str = '', result_type: bool = True):
|
||||||
param_str = ' '.join([f'{k}<m>{escape_tag(v)}</m>' for k, v in param.items()]) if param else ''
|
param_str = ' '.join([f'{k}<m>{escape_tag(str(v))}</m>' for k, v in param.items()]) if param else ''
|
||||||
result_str = f'<g>{escape_tag(result)}</g>' if result_type else f'<r>{escape_tag(result)}</r>' if result else ''
|
result_str = f'<g>{escape_tag(result)}</g>' if result_type else f'<r>{escape_tag(result)}</r>' if result else ''
|
||||||
nb_logger.opt(colors=True).info(f'<u><y>[{command}]</y></u>{info}{param_str}{result_str}')
|
nb_logger.opt(colors=True).info(f'<u><y>[{command}]</y></u>{info}{param_str}{result_str}')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def success(command: str, info: str = '', param: Dict[str, any] = None, result: str = ''):
|
def success(command: str, info: str = '', param: Dict[str, any] = None, result: str = ''):
|
||||||
param_str = ' '.join([f'{k}<m>{escape_tag(v)}</m>' for k, v in param.items()]) if param else ''
|
param_str = ' '.join([f'{k}<m>{escape_tag(str(v))}</m>' for k, v in param.items()]) if param else ''
|
||||||
result_str = f'<g>{escape_tag(result)}</g>' if result else ''
|
result_str = f'<g>{escape_tag(result)}</g>' if result else ''
|
||||||
nb_logger.opt(colors=True).success(f'<u><y>[{command}]</y></u>{info}{param_str}{result_str}')
|
nb_logger.opt(colors=True).success(f'<u><y>[{command}]</y></u>{info}{param_str}{result_str}')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user