diff options
author | Kyomotoi <[email protected]> | 2020-11-07 13:54:57 +0800 |
---|---|---|
committer | Kyomotoi <[email protected]> | 2020-11-07 13:54:57 +0800 |
commit | 7cae371b51a14c626ce184987eea2392e15430b9 (patch) | |
tree | a35aa21a64dad59a8dc91270d78f781dbed8953d /ATRI/plugins/plugin_chat/__init__.py | |
parent | 11e4632aaf2be56c776dbc4e9f0ad5065bb60b5f (diff) | |
download | ATRI-7cae371b51a14c626ce184987eea2392e15430b9.tar.gz ATRI-7cae371b51a14c626ce184987eea2392e15430b9.tar.bz2 ATRI-7cae371b51a14c626ce184987eea2392e15430b9.zip |
[Update]
Diffstat (limited to 'ATRI/plugins/plugin_chat/__init__.py')
-rw-r--r-- | ATRI/plugins/plugin_chat/__init__.py | 192 |
1 files changed, 97 insertions, 95 deletions
diff --git a/ATRI/plugins/plugin_chat/__init__.py b/ATRI/plugins/plugin_chat/__init__.py index d30bd2e..0a718b0 100644 --- a/ATRI/plugins/plugin_chat/__init__.py +++ b/ATRI/plugins/plugin_chat/__init__.py @@ -20,16 +20,20 @@ from nonebot.adapters.cqhttp import Bot, Event from nonebot.plugin import on_command, on_message, on_notice from utils.utils_times import countX +from utils.utils_yml import load_yaml from utils.utils_error import errorRepo -from utils.utils_banList import banList +from utils.utils_rule import check_banlist from utils.utils_history import saveMessage from utils.utils_request import request_api_text +CONFIG_PATH = Path('.') / 'config.yml' +config = load_yaml(CONFIG_PATH)['bot'] # 收集 bot 所在群的聊天记录 MessageSave = on_message() [email protected]() # type: ignore + [email protected]() # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: user = str(event.user_id) group = str(event.group_id) @@ -40,148 +44,146 @@ async def _(bot: Bot, event: Event, state: dict) -> None: saveMessage(message_id, message, user) else: saveMessage(message_id, message, user, group) - - logger.opt(colors=True).info(f"[<yellow>{group}</yellow>]-U: (<blue>{user}</blue>) | Message: (<green>{message}</green>) Saved successfully") + + logger.opt(colors=True).info( + f"[<yellow>{group}</yellow>]-U: (<blue>{user}</blue>) | Message: (<green>{message}</green>) Saved successfully" + ) # Call bot -callMe = on_message() +callMe = on_message(rule=check_banlist()) [email protected]() # type: ignore + [email protected]() # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: - user = str(event.user_id) - group = str(event.group_id) + msg = str(event.message) + + if msg in config['nickname']: + await callMe.finish("叫咱有啥事吗w") - if banList(user, group): - msg = str(event.message) + elif "萝卜子" in msg: + await bot.send(event, "萝卜子是对咱的蔑称!!") - if "ATRI" == msg or "亚托莉" == msg or "アトリ" == msg: - await callMe.finish("叫我有啥事吗w") - - elif "萝卜子" in msg: - await bot.send(event, "萝卜子是对咱的蔑称!!") - - else: - pass + else: + pass # 戳 一 戳 -pokehah = on_command("戳一戳", rule=to_me()) +pokehah = on_command("戳一戳", rule=to_me() & check_banlist()) [email protected]() # type: ignore -async def _poke(bot: Bot, event: Event, state: dict) -> None: - user = str(event.user_id) - group = str(event.group_id) - if banList(user, group): - msg = choice( - [ - "你再戳!", - "?再戳试试?", - "别戳了别戳了再戳就坏了555", - "我爪巴爪巴,球球别再戳了", - "你戳你🐎呢?!", - "那...那里...那里不能戳...绝对...", - "(。´・ω・)ん?", - "有事恁叫我,别天天一个劲戳戳戳!", - "欸很烦欸!你戳🔨呢", - "?" - ]) [email protected]() # type: ignore +async def _poke(bot: Bot, event: Event, state: dict) -> None: + msg = choice([ + "你再戳!", "?再戳试试?", "别戳了别戳了再戳就坏了555", "我爪巴爪巴,球球别再戳了", "你戳你🐎呢?!", + "那...那里...那里不能戳...绝对...", "(。´・ω・)ん?", "有事恁叫我,别天天一个劲戳戳戳!", "欸很烦欸!你戳🔨呢", + "?" + ]) - await pokehah.finish(msg) + await pokehah.finish(msg) 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"]) + return (event.detail_type == "notify" + and event.raw_event["sub_type"] == "poke" # type: ignore + and event.sub_type == "notice" and int( + event.self_id) == event.raw_event["target_id"] # type: ignore + ) + poke = on_notice(poke_, block=True) poke.handle()(_poke) - # 处理 进 / 退 群事件 -groupEvent = on_notice() +groupEvent = on_notice(rule=check_banlist()) [email protected]() # type: ignore -async def _(bot: Bot, event: Event, state: dict) -> None: - group = str(event.group_id) - if banList(group): - if event.raw_event["notice_type"] == "group_increase": - await groupEvent.finish(f'好欸!事新人[CQ:at,qq={event.raw_event["user_id"]}]') - await groupEvent.finish(f"在下 ATRI,你可以叫我 亚托莉 或 アトリ !~w") [email protected]() # type: ignore +async def _(bot: Bot, event: Event, state: dict) -> None: + if event.raw_event["notice_type"] == "group_increase": # type: ignore + await groupEvent.finish( + f'好欸!事新人[CQ:at,qq={event.raw_event["user_id"]}]' # type: ignore + ) # type: ignore + await groupEvent.finish(f"在下 ATRI,你可以叫我 亚托莉 或 アトリ !~w") - elif event.raw_event["notice_type"] == "group_decrease": - await groupEvent.finish(f'[{event.raw_event["operator_id"]}] 离开了我们...') + elif event.raw_event[ # type: ignore + "notice_type"] == "group_decrease": + await groupEvent.finish( + f'[{event.raw_event["operator_id"]}] 离开了我们...' # type: ignore + ) # 舆情监听系统 listenPublicOpinion = on_message() -file_PO = Path('.') / 'ATRI' / 'plugins' / 'plugin_chat' / 'public_opinion.json' +file_PO = Path( + '.') / 'ATRI' / 'plugins' / 'plugin_chat' / 'public_opinion.json' + [email protected]() # type: ignore [email protected]() # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: with open(file_PO, 'r') as f: data = json.load(f) # 口臭一下 -fxxkMe = on_command('口臭一下', aliases={'口臭', '骂我'}, rule=to_me()) +fxxkMe = on_command('口臭一下', + aliases={'口臭', '骂我'}, + rule=to_me() & check_banlist()) list_M = [] [email protected]() # type: ignore + [email protected]() # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: user = str(event.user_id) - group = str(event.group_id) global list_M - if banList(user, group): - if countX(list_M, user) >= 3: - await fxxkMe.finish("不是??你这么想被咱骂的嘛??被咱骂就这么舒服的吗?!该......你该不会是.....M吧!") - - elif countX(list_M, user) >= 6: - await fxxkMe.finish("给我适可而止阿!?") - list_M = list(set(list_M)) + if countX(list_M, user) >= 3: + await fxxkMe.finish("不是??你这么想被咱骂的嘛??被咱骂就这么舒服的吗?!该......你该不会是.....M吧!") + + elif countX(list_M, user) >= 6: + await fxxkMe.finish("给我适可而止阿!?") + list_M = list(set(list_M)) + + else: + list_M.append(user) + URL = "https://nmsl.shadiao.app/api.php?level=min&lang=zh_cn" + msg = "" - else: - list_M.append(user) - URL = "https://nmsl.shadiao.app/api.php?level=min&lang=zh_cn" - msg = "" + try: + msg = request_api_text(URL) + except: + await fxxkMe.finish(errorRepo("请求错误")) - try: - msg = request_api_text(URL) - except: - await fxxkMe.finish(errorRepo("请求错误")) - - await fxxkMe.finish(msg) + await fxxkMe.finish(msg) # Hitokoto -hitokoto = on_command('一言', aliases={'抑郁一下', '网抑云'}, rule=to_me()) +hitokoto = on_command('一言', + aliases={'抑郁一下', '网抑云'}, + rule=to_me() & check_banlist()) list_Y = [] [email protected]() # type: ignore + [email protected]() # type: ignore async def _(bot: Bot, event: Event, state: dict) -> None: user = str(event.user_id) - group = str(event.group_id) global list_Y - if banList(user, group): - if countX(list_Y, user) >= 3: - await hitokoto.finish("额......需要咱安慰一下嘛~?") - - elif countX(list_Y, user) >= 6: - await hitokoto.finish("如果心里感到难受就赶快去睡觉奥!别再憋自己了!") - list_Y = list(set(list_Y)) - - else: - list_Y.append(user) - URL = "https://api.imjad.cn/hitokoto/?cat=a&charset=utf-8&length=50&encode=json&fun=sync&source=" - info = {} - - try: - info = json.loads(request_api_text(URL)) - except: - await hitokoto.finish(errorRepo("请求错误")) - - await hitokoto.finish(info["hitokoto"]) + if countX(list_Y, user) >= 3: + await hitokoto.finish("额......需要咱安慰一下嘛~?") + + elif countX(list_Y, user) >= 6: + await hitokoto.finish("如果心里感到难受就赶快去睡觉奥!别再憋自己了!") + list_Y = list(set(list_Y)) + + else: + list_Y.append(user) + URL = "https://api.imjad.cn/hitokoto/?cat=a&charset=utf-8&length=50&encode=json&fun=sync&source=" + info = {} + + try: + info = json.loads(request_api_text(URL)) + except: + await hitokoto.finish(errorRepo("请求错误")) + + await hitokoto.finish(info["hitokoto"]) |