diff options
author | Kyomotoi <[email protected]> | 2020-11-09 14:29:09 +0800 |
---|---|---|
committer | Kyomotoi <[email protected]> | 2020-11-09 14:29:09 +0800 |
commit | e1db381d2a331ebcbf308490ee2d53fb8a8fc0a1 (patch) | |
tree | 5d3a85489fa5d32b9d05fcb67b40859adbe1b625 /ATRI/plugins/plugin_chat/__init__.py | |
parent | b2ea4e6e378f4aa96dc2c4ffde8b3543ed478a41 (diff) | |
download | ATRI-e1db381d2a331ebcbf308490ee2d53fb8a8fc0a1.tar.gz ATRI-e1db381d2a331ebcbf308490ee2d53fb8a8fc0a1.tar.bz2 ATRI-e1db381d2a331ebcbf308490ee2d53fb8a8fc0a1.zip |
[Update]
调整文件结构;
修复文件读取、创建问题;
重构部分代码;
修复:
- 涩图插件名读取错误
- 私聊消息无法发送
新增:
- 好友请求处理
- 邀请请求处理
Diffstat (limited to 'ATRI/plugins/plugin_chat/__init__.py')
-rw-r--r-- | ATRI/plugins/plugin_chat/__init__.py | 153 |
1 files changed, 131 insertions, 22 deletions
diff --git a/ATRI/plugins/plugin_chat/__init__.py b/ATRI/plugins/plugin_chat/__init__.py index b8f3c2a..ec6738f 100644 --- a/ATRI/plugins/plugin_chat/__init__.py +++ b/ATRI/plugins/plugin_chat/__init__.py @@ -10,16 +10,16 @@ ''' __author__ = 'kyomotoi' -import re import json from pathlib import Path from random import choice +from nonebot.permission import SUPERUSER from requests import exceptions from nonebot.log import logger from nonebot.rule import to_me from nonebot.adapters.cqhttp import Bot, Event -from nonebot.plugin import on_command, on_message, on_notice +from nonebot.plugin import on_command, on_message, on_notice, on_request from utils.utils_times import countX from utils.utils_yml import load_yaml @@ -31,6 +31,8 @@ from utils.utils_request import request_api_text CONFIG_PATH = Path('.') / 'config.yml' config = load_yaml(CONFIG_PATH)['bot'] +master = config['superusers'] + # 收集 bot 所在群的聊天记录 MessageSave = on_message() @@ -58,14 +60,14 @@ callMe = on_message(rule=check_banlist()) @callMe.handle() # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: - msg = str(event.message) - - if msg in config['nickname']: - await callMe.finish("叫咱有啥事吗w") + msg = str(event.raw_event['raw_message']).strip() - elif "萝卜子" in msg: + if "萝卜子" in msg: await bot.send(event, "萝卜子是对咱的蔑称!!") + elif msg in config['nickname']: + await callMe.finish("叫咱有啥事吗w") + # 戳 一 戳 pokehah = on_command("戳一戳", rule=to_me() & check_banlist()) @@ -83,11 +85,12 @@ async def _poke(bot: Bot, event: Event, state: dict) -> None: async def poke_(bot: Bot, event: Event, state: dict) -> bool: - return (event.detail_type == "notify" - and event.raw_event["sub_type"] == "poke" - and event.sub_type == "notice" and int( - event.self_id) == event.raw_event["target_id"] - ) + try: + return (event.raw_event['sub_type'] == 'poke' + and event.raw_event['target_id'] == int(event.self_id) + and event.raw_event['notice_type'] == 'notify') + except: + return False poke = on_notice(rule=check_banlist() & poke_, block=True) @@ -99,17 +102,106 @@ groupEvent = on_notice() @groupEvent.handle() # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: - if event.raw_event["notice_type"] == "group_increase": - await groupEvent.finish( - f'好欸!事新人[CQ:at,qq={event.raw_event["user_id"]}]' - ) - await groupEvent.finish("在下 ATRI,你可以叫我 亚托莉 或 アトリ !~w") + if event.raw_event['notice_type'] == 'group_increase': + if event.user_id != int(event.self_id): + await groupEvent.finish( + f'好欸!事新人[CQ:at,qq={event.raw_event["user_id"]}]') + elif event.user_id == int(event.self_id): + await groupEvent.finish("在下 ATRI,你可以叫我 亚托莉 或 アトリ !~w") + + if event.raw_event['notice_type'] == 'group_decrease': + if event.user_id != int(event.self_id): + await groupEvent.finish(f'[{event.user_id}] 离开了我们...') + elif event.user_id == int(event.self_id): + for sup in master: + await bot.send_private_msg( + user_id=sup, + message=f'呜呜呜,主人,咱被群[{event.group_id}]扔出来了...') + + +# 处理 加好友 / 拉群 事件 +selfEvent = on_request(rule=check_banlist()) +FRIEND_ADD = 0 +GROUP_INVITE = 0 + + [email protected]() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: + print(event.raw_event) + flag = event.raw_event['flag'] + req_type = event.raw_event['request_type'] + + if req_type == 'friend': + for sup in master: + msg0 = '主人,收到一条好友请求:\n' + msg0 += f"请求人:{event.raw_event['user_id']}\n" + msg0 += f"申请信息:{event.raw_event['comment']}\n" + + if FRIEND_ADD == 0: + msg0 += '由于主人未允许咱添加好友,已回拒' + await bot.set_friend_add_request(flag=flag, approve=False) + else: + msg0 += '由于主人已同意咱添加好友,已通过' + await bot.set_friend_add_request(flag=flag, approve=True) + + await bot.send_private_msg(user_id=sup, message=msg0) + + elif req_type == 'group' and event.raw_event['sub_type'] == 'invite': + for sup in master: + msg0 = '主人,收到一条群邀请:\n' + msg0 += f"邀请人:{event.raw_event['user_id']}\n" + msg0 += f"目标群:{event.raw_event['group_id']}\n" + + if GROUP_INVITE == 0: + msg0 += '由于主人未允许咱添加群聊,已回拒' + await bot.set_group_add_request( + flag=flag, + sub_type=event.raw_event['sub_type'], + approve=False, + reason=f'ねね..ごんめね...\n主人不允许咱添加其他群聊...\n如需寻求帮助,请联系维护者:{sup}' + ) + + else: + msg0 += '由于主人已允许咱添加群聊,已同意' + await bot.set_group_add_request( + flag=flag, + sub_type=event.raw_event['sub_type'], + approve=True) + + await bot.send_private_msg(user_id=sup, message=msg0) + + +# 控制 加好友 / 拉群 认证,默认关闭 +controlSelfEvent = on_command('selfevent', permission=SUPERUSER) + + [email protected]() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: + args = str(event.message).strip() + msg0 = '' + global FRIEND_ADD, GROUP_INVITE + + if not args: + msg0 = '-==ATRI INVITE Control System==-\n' + msg0 += 'Tips:\n' + msg0 += ' - For SUPERUSERS\n' + msg0 += ' - Normal all false\n' + msg0 += 'Usage:\n' + msg0 += ' - selfevent group-true/false\n' + msg0 += ' - selfevent friend-true/false\n' + + await controlSelfEvent.finish(msg0) + + if 'group-' in args: + if 'true' in args: + GROUP_INVITE = 1 + elif 'friend-' in args: + if 'true' in args: + FRIEND_ADD = 1 + else: + await controlSelfEvent.finish(msg0) - elif event.raw_event[ - "notice_type"] == "group_decrease": - await groupEvent.finish( - f'[{event.raw_event["operator_id"]}] 离开了我们...' - ) + await controlSelfEvent.finish('DONE!') # # 舆情监听系统 @@ -184,3 +276,20 @@ async def _(bot: Bot, event: Event, state: dict) -> None: await hitokoto.finish(errorRepo("请求错误")) await hitokoto.finish(info["hitokoto"]) + + +# laughFunny = on_command('来句笑话', rule=check_banlist()) + +# @laughFunny.handle() #type: ignore +# async def _(bot: Bot, event: Event, state: dict) -> None: +# name = event.sender['nickname'] +# result = [] + +# LAUGH_FILE = Path('.') / 'ATRI' / 'plugins' / 'plugin_chat' / 'laugh.txt' + +# with open(LAUGH_FILE, 'r', encoding='utf-8') as f: +# for line in f: +# result.append(line.strip('\n')) + +# resu = choice(result) +# print(resu%name)
\ No newline at end of file |