diff --git a/.gitignore b/.gitignore index 868382a..99f0220 100644 --- a/.gitignore +++ b/.gitignore @@ -148,6 +148,3 @@ nohup.out .history Paimon_exchange/* user_data/gacha_log_data/* -res/reliquaries/* -res/role_side_card/* -res/weapon/* diff --git a/Paimon_Plugins/__init__.py b/Paimon_Plugins/__init__.py index 4d91377..054c27e 100644 --- a/Paimon_Plugins/__init__.py +++ b/Paimon_Plugins/__init__.py @@ -1,12 +1,17 @@ from aiohttp import ClientSession from urllib.parse import quote -from nonebot import on_command -from nonebot.params import CommandArg from typing import Union -from nonebot.adapters.onebot.v11 import GroupMessageEvent, MessageEvent, MessageSegment +from nonebot import on_command, get_driver +from nonebot.params import CommandArg +from nonebot.message import event_preprocessor +from nonebot.adapters.onebot.v11 import Bot, GroupMessageEvent, MessageEvent, MessageSegment, FriendRequestEvent, \ + GroupRequestEvent from ..utils.util import FreqLimiter from ..utils.config import config -import random +from asyncio import sleep +from .chat import * + +superuser = int(list(get_driver().config.superusers)[0]) duilian = on_command('对联', aliases={'对对联'}, priority=15, block=True) cat_pic = on_command('猫图', aliases={'来点猫片', '看看猫猫', '来个猫猫'}, priority=15, block=True) @@ -91,3 +96,37 @@ async def ys_pic_handler(event: Union[GroupMessageEvent, MessageEvent]): res = await session.get(random.choice(urls)) res = await res.read() await ys_pic.finish(MessageSegment.image(res)) + + +@event_preprocessor +async def addFriend(bot: Bot, event: FriendRequestEvent): + superuser_msg = f'{event.user_id}请求添加派蒙为好友, 验证信息为:{event.comment}' + if config.paimon_add_friend == 1: + superuser_msg += ',已自动同意' + await event.approve() + await sleep(random.randint(3, 6)) + await bot.send_private_msg(user_id=event.user_id, message=f'旅行者你好呀,这里是小派蒙,发送/help查看帮助哦') + elif config.paimon_add_friend == 2: + superuser_msg += ',已自动拒绝' + await event.reject() + else: + superuser_msg += ',请主人自行处理哦' + await bot.send_private_msg(user_id=superuser, message=superuser_msg) + + +@event_preprocessor +async def addFriend(bot: Bot, event: GroupRequestEvent): + if event.sub_type != 'invite': + return + superuser_msg = f'{event.user_id}邀请派蒙加入群{event.group_id}' + if config.paimon_add_group == 1 or event.user_id == superuser: + superuser_msg += ',已自动同意' + await event.approve() + await sleep(random.randint(3, 6)) + await bot.send_group_msg(group_id=event.group_id, message=f'旅行者们大家好呀,这里是小派蒙,发送/help查看帮助哦') + elif config.paimon_add_group == 2: + superuser_msg += ',已自动拒绝' + await event.reject() + else: + superuser_msg += ',请主人自行处理哦' + await bot.send_private_msg(user_id=superuser, message=superuser_msg) diff --git a/Paimon_Plugins/chat.py b/Paimon_Plugins/chat.py new file mode 100644 index 0000000..491b0ad --- /dev/null +++ b/Paimon_Plugins/chat.py @@ -0,0 +1,68 @@ +from nonebot import on_regex, logger +from nonebot.exception import FinishedException +from nonebot.adapters.onebot.v11 import GroupMessageEvent, MessageSegment +from ..utils.util import FreqLimiter2 +from pathlib import Path +import random +import os + +chat_list = { + '确实': {'pattern': r'.*(雀食|确实).*', 'cooldown': 60, 'pro': 0.6, 'files': ['雀食', '确实']}, + '坏了': {'pattern': r'.*派蒙.*坏.*', 'cooldown': 60, 'pro': 0.6, 'files': ['你才坏!', '瞎说啥呢?', '派蒙怎么可能会坏!']}, + '诶嘿': {'pattern': r'.*(诶嘿|哎嘿|欸嘿).*', 'cooldown': 120, 'pro': 0.5, 'files': ['诶嘿.mp3', '诶嘿cn.mp3']}, + '进不去': {'pattern': r'.*进不?(来|去).*', 'cooldown': 180, 'pro': 0.5, 'files': ['进不去.mp3']}, + '派蒙是谁': {'pattern': r'.*(派蒙.*是(什么|谁))|((什么|谁)是?.*派蒙).*', 'cooldown': 240, 'pro': 1, + 'files': ['嘿嘿你猜.mp3', '中二派蒙.mp3', '伙伴.mp3']}, + '大佬': {'pattern': r'.*((大|巨)佬)|带带|帮帮|邦邦.*', 'cooldown': 240, 'pro': 0.6, 'files': ['大佬nb.mp3']}, + '好色': {'pattern': r'.*好色|变态(哦|噢)?', 'cooldown': 300, 'pro': 0.5, 'files': ['好色哦.mp3', '好变态.mp3']}, + '无语': {'pattern': r'.*(\.{3,9})|(\。{3,9})|无语|无话可说.*', 'cooldown': 300, 'pro': 0.6, 'files': ['无语.mp3', '冷淡反应.mp3']}, + '祝福': {'pattern': r'.*派蒙.*(祝福|吟唱|施法).*', 'cooldown': 360, 'pro': 1, 'files': ['来个祝福.mp3']}, + '相信': {'pattern': r'.*信?不信|信我.*', 'cooldown': 360, 'pro': 0.5, 'files': ['我信你个鬼.mp3', '真的假的.mp3']}, + '憨批': {'pattern': r'.*(憨批|傻(逼|B|b)).*', 'cooldown': 360, 'pro': 0.5, 'files': ['憨批.mp3']}, + '可爱': {'pattern': r'.*可爱|卡哇伊', 'cooldown': 360, 'pro': 0.5, 'files': ['真是个小可爱.mp3']}, + '绿茶': {'pattern': r'.*派蒙.*(giegie|绿茶).*', 'cooldown': 360, 'pro': 1, 'files': ['绿茶派.mp3']}, + '不是吧': {'pattern': r'不(是|会)吧', 'cooldown': 300, 'pro': 0.5, 'files': ['不是吧阿sir.mp3']}, + '好耶': {'pattern': r'好耶|太(好|棒)(了|啦)|好(\!|\!)', 'cooldown': 180, 'pro': 0.75, 'files': ['好耶.mp3', '太好啦.mp3']}, + '好听': {'pattern': r'(好|真|非常)?好听(\!|\!)?', 'cooldown': 360, 'pro': 0.4, 'files': ['好听.mp3']}, + '耽误时间': {'pattern': r'快{1,4}|gkd|搞?快点|赶紧的?|(.*耽误.*时间.*)', 'cooldown': 360, 'pro': 0.6, 'files': ['耽误时间.mp3']}, + '不可以': {'pattern': r'不(可以|行|能)(吧|的|噢)?', 'cooldown': 180, 'pro': 0.6, 'files': ['不可以.mp3']}, + '好意思': {'pattern': r'.*好意思.*', 'cooldown': 300, 'pro': 0.5, 'files': ['好意思.mp3']}, + '不要啊': {'pattern': r'不(好|要)(吧|啊)?', 'cooldown': 180, 'pro': 0.5, 'files': ['不要啊.mp3']}, + '羡慕': {'pattern': r'.*羡慕.*', 'cooldown': 180, 'pro': 0.5, 'files': ['羡慕.mp3']}, + '过分': {'pattern': r'.*过分.*', 'cooldown': 300, 'pro': 0.5, 'files': ['好过分.mp3']}, + '不明白': {'pattern': r'.*明白.*', 'cooldown': 300, 'pro': 0.5, 'files': ['不明白.mp3']}, + '哪里不对': {'pattern': r'(是|对)(吧|吗)', 'cooldown': 300, 'pro': 0.5, 'files': ['哪里不对.mp3']} +} + +res_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'res', 'voice') +chat_lmt = FreqLimiter2(60) + + +def create_matcher(chat_word: str, pattern: str, cooldown: int, pro: float, responses): + hammer = on_regex(pattern, priority=16, temp=True) + + @hammer.handle() + async def handler(event: GroupMessageEvent): + if not chat_lmt.check(event.group_id, chat_word): + return + else: + if not random.random() < pro: + return + else: + try: + chat_lmt.start_cd(event.group_id, chat_word, cooldown) + response = random.choice(responses) + if '.mp3' not in response: + await hammer.finish(response) + else: + print(os.path.join(res_path, response)) + await hammer.finish(MessageSegment.record(file=Path(os.path.join(res_path, response)))) + except FinishedException: + raise + except Exception as e: + logger.error('派蒙发送语音失败', e) + + +for k, v in chat_list.items(): + create_matcher(k, v['pattern'], v['cooldown'], v['pro'], v['files']) + diff --git a/README.md b/README.md index 1cf2953..cc2aa6c 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ nonebot2版本的小派蒙 * 来点猫片 * 来点二次元 * 来点原神壁纸 + * 派蒙聊天(关键词触发) 具体插件命令与hoshino版一致
nonebot2刚上手,测试时间较短,如有bug,请及时反馈。 diff --git a/res/voice/不可以.mp3 b/res/voice/不可以.mp3 new file mode 100644 index 0000000..f5fb8e2 Binary files /dev/null and b/res/voice/不可以.mp3 differ diff --git a/res/voice/不明白.mp3 b/res/voice/不明白.mp3 new file mode 100644 index 0000000..43c2e21 Binary files /dev/null and b/res/voice/不明白.mp3 differ diff --git a/res/voice/不是吧阿sir.mp3 b/res/voice/不是吧阿sir.mp3 new file mode 100644 index 0000000..a725448 Binary files /dev/null and b/res/voice/不是吧阿sir.mp3 differ diff --git a/res/voice/不要啊.mp3 b/res/voice/不要啊.mp3 new file mode 100644 index 0000000..dc0b196 Binary files /dev/null and b/res/voice/不要啊.mp3 differ diff --git a/res/voice/中二派蒙.mp3 b/res/voice/中二派蒙.mp3 new file mode 100644 index 0000000..f132430 Binary files /dev/null and b/res/voice/中二派蒙.mp3 differ diff --git a/res/voice/什么问题.mp3 b/res/voice/什么问题.mp3 new file mode 100644 index 0000000..9a5e8a9 Binary files /dev/null and b/res/voice/什么问题.mp3 differ diff --git a/res/voice/伙伴.mp3 b/res/voice/伙伴.mp3 new file mode 100644 index 0000000..d753e71 Binary files /dev/null and b/res/voice/伙伴.mp3 differ diff --git a/res/voice/冷淡反应.mp3 b/res/voice/冷淡反应.mp3 new file mode 100644 index 0000000..afc651d Binary files /dev/null and b/res/voice/冷淡反应.mp3 differ diff --git a/res/voice/前面的区域.mp3 b/res/voice/前面的区域.mp3 new file mode 100644 index 0000000..ae250a4 Binary files /dev/null and b/res/voice/前面的区域.mp3 differ diff --git a/res/voice/勉强自己.mp3 b/res/voice/勉强自己.mp3 new file mode 100644 index 0000000..6bc1599 Binary files /dev/null and b/res/voice/勉强自己.mp3 differ diff --git a/res/voice/哪里不对.mp3 b/res/voice/哪里不对.mp3 new file mode 100644 index 0000000..fb5a3aa Binary files /dev/null and b/res/voice/哪里不对.mp3 differ diff --git a/res/voice/嘿嘿你猜.mp3 b/res/voice/嘿嘿你猜.mp3 new file mode 100644 index 0000000..ae4fcea Binary files /dev/null and b/res/voice/嘿嘿你猜.mp3 differ diff --git a/res/voice/坏蛋.mp3 b/res/voice/坏蛋.mp3 new file mode 100644 index 0000000..07c0222 Binary files /dev/null and b/res/voice/坏蛋.mp3 differ diff --git a/res/voice/大佬nb.mp3 b/res/voice/大佬nb.mp3 new file mode 100644 index 0000000..0cef980 Binary files /dev/null and b/res/voice/大佬nb.mp3 differ diff --git a/res/voice/太好啦.mp3 b/res/voice/太好啦.mp3 new file mode 100644 index 0000000..0235f51 Binary files /dev/null and b/res/voice/太好啦.mp3 differ diff --git a/res/voice/好变态.mp3 b/res/voice/好变态.mp3 new file mode 100644 index 0000000..8a9b59e Binary files /dev/null and b/res/voice/好变态.mp3 differ diff --git a/res/voice/好听.mp3 b/res/voice/好听.mp3 new file mode 100644 index 0000000..2fc5f02 Binary files /dev/null and b/res/voice/好听.mp3 differ diff --git a/res/voice/好意思.mp3 b/res/voice/好意思.mp3 new file mode 100644 index 0000000..f8e7ffc Binary files /dev/null and b/res/voice/好意思.mp3 differ diff --git a/res/voice/好气哦.mp3 b/res/voice/好气哦.mp3 new file mode 100644 index 0000000..ce05318 Binary files /dev/null and b/res/voice/好气哦.mp3 differ diff --git a/res/voice/好生气.mp3 b/res/voice/好生气.mp3 new file mode 100644 index 0000000..c39c051 Binary files /dev/null and b/res/voice/好生气.mp3 differ diff --git a/res/voice/好耶.mp3 b/res/voice/好耶.mp3 new file mode 100644 index 0000000..862d6f4 Binary files /dev/null and b/res/voice/好耶.mp3 differ diff --git a/res/voice/好色哦.mp3 b/res/voice/好色哦.mp3 new file mode 100644 index 0000000..6322f0b Binary files /dev/null and b/res/voice/好色哦.mp3 differ diff --git a/res/voice/好过分.mp3 b/res/voice/好过分.mp3 new file mode 100644 index 0000000..d189425 Binary files /dev/null and b/res/voice/好过分.mp3 differ diff --git a/res/voice/憨批.mp3 b/res/voice/憨批.mp3 new file mode 100644 index 0000000..c3954d1 Binary files /dev/null and b/res/voice/憨批.mp3 differ diff --git a/res/voice/我信你个鬼.mp3 b/res/voice/我信你个鬼.mp3 new file mode 100644 index 0000000..fcdb517 Binary files /dev/null and b/res/voice/我信你个鬼.mp3 differ diff --git a/res/voice/无语.mp3 b/res/voice/无语.mp3 new file mode 100644 index 0000000..b507e8e Binary files /dev/null and b/res/voice/无语.mp3 differ diff --git a/res/voice/来个祝福.mp3 b/res/voice/来个祝福.mp3 new file mode 100644 index 0000000..b4d365f Binary files /dev/null and b/res/voice/来个祝福.mp3 differ diff --git a/res/voice/泪目.mp3 b/res/voice/泪目.mp3 new file mode 100644 index 0000000..deb700a Binary files /dev/null and b/res/voice/泪目.mp3 differ diff --git a/res/voice/生活小智慧.mp3 b/res/voice/生活小智慧.mp3 new file mode 100644 index 0000000..45c0af9 Binary files /dev/null and b/res/voice/生活小智慧.mp3 differ diff --git a/res/voice/真是个小可爱.mp3 b/res/voice/真是个小可爱.mp3 new file mode 100644 index 0000000..aa1049b Binary files /dev/null and b/res/voice/真是个小可爱.mp3 differ diff --git a/res/voice/真的假的.mp3 b/res/voice/真的假的.mp3 new file mode 100644 index 0000000..aa20e92 Binary files /dev/null and b/res/voice/真的假的.mp3 differ diff --git a/res/voice/给爷爬.mp3 b/res/voice/给爷爬.mp3 new file mode 100644 index 0000000..0b6c750 Binary files /dev/null and b/res/voice/给爷爬.mp3 differ diff --git a/res/voice/绿茶派.mp3 b/res/voice/绿茶派.mp3 new file mode 100644 index 0000000..40abe3d Binary files /dev/null and b/res/voice/绿茶派.mp3 differ diff --git a/res/voice/羡慕.mp3 b/res/voice/羡慕.mp3 new file mode 100644 index 0000000..6e882eb Binary files /dev/null and b/res/voice/羡慕.mp3 differ diff --git a/res/voice/耽误时间.mp3 b/res/voice/耽误时间.mp3 new file mode 100644 index 0000000..0aff369 Binary files /dev/null and b/res/voice/耽误时间.mp3 differ diff --git a/res/voice/诶嘿.mp3 b/res/voice/诶嘿.mp3 new file mode 100644 index 0000000..bb73992 Binary files /dev/null and b/res/voice/诶嘿.mp3 differ diff --git a/res/voice/诶嘿cn.mp3 b/res/voice/诶嘿cn.mp3 new file mode 100644 index 0000000..27746c4 Binary files /dev/null and b/res/voice/诶嘿cn.mp3 differ diff --git a/res/voice/这个仇.mp3 b/res/voice/这个仇.mp3 new file mode 100644 index 0000000..251891f Binary files /dev/null and b/res/voice/这个仇.mp3 differ diff --git a/res/voice/进不去.mp3 b/res/voice/进不去.mp3 new file mode 100644 index 0000000..d917e87 Binary files /dev/null and b/res/voice/进不去.mp3 differ diff --git a/utils/config.py b/utils/config.py index b840327..8b71e66 100644 --- a/utils/config.py +++ b/utils/config.py @@ -15,6 +15,8 @@ class PluginConfig(BaseModel): paimon_cat_cd: int = 12 paimon_ecy_cd: int = 6 paimon_ysp_cd: int = 10 + paimon_add_friend: int = 0 + paimon_add_group: int = 0 driver = get_driver() diff --git a/utils/util.py b/utils/util.py index be81e4a..bcd3d5f 100644 --- a/utils/util.py +++ b/utils/util.py @@ -14,7 +14,6 @@ from json import JSONDecodeError from aiohttp import ClientSession from nonebot import get_bot from nonebot import logger -from nonebot.matcher import Matcher from nonebot.exception import FinishedException from nonebot.adapters.onebot.v11 import MessageEvent, Message from nonebot.adapters.onebot.v11.exception import ActionFailed @@ -103,6 +102,22 @@ class FreqLimiter: return int(self.next_time[key] - time()) + 1 +# 双参数冷却时间限制器 +class FreqLimiter2: + def __init__(self, default_cd_seconds: int = 60): + self.next_time = defaultdict(lambda: defaultdict(float)) + self.default_cd = default_cd_seconds + + def check(self, key1, key2) -> bool: + return bool(time() >= self.next_time[key1][key2]) + + def start_cd(self, key1, key2, cd_time=0): + self.next_time[key1][key2] = time() + (cd_time if cd_time > 0 else self.default_cd) + + def left_time(self, key1, key2) -> int: + return int(self.next_time[key1][key2] - time()) + 1 + + # 获取可用的cookie async def get_use_cookie(user_id, uid='', mys_id='', action=''): cache_cookie = await get_cookie_cache(uid, 'uid')