This commit is contained in:
2979302435 2022-06-16 19:13:11 +08:00
parent dbf3ee113f
commit 73123a8015
4 changed files with 158 additions and 9 deletions

View File

@ -11,7 +11,7 @@ from nonebot.typing import T_State
from nonebot.rule import keyword, to_me, Rule from nonebot.rule import keyword, to_me, Rule
from nonebot.adapters import Bot from nonebot.adapters import Bot
from nonebot.adapters.onebot.v11 import GroupMessageEvent from nonebot.adapters.onebot.v11 import GroupMessageEvent
from nonebot.permission import SUPERUSER
from nonebot.adapters.onebot.v11 import permission from nonebot.adapters.onebot.v11 import permission
from .model import Chat from .model import Chat
@ -20,6 +20,11 @@ from utils.config import config
message_id_lock = threading.Lock() message_id_lock = threading.Lock()
message_id_dict = {} message_id_dict = {}
#检测是否开启该群的机器学习
def checkGroup(event: GroupMessageEvent) -> bool:
if event.group_id in Chat.learningGroup:
return True
return False
async def check_accounts(event: GroupMessageEvent) -> bool: async def check_accounts(event: GroupMessageEvent) -> bool:
# 不响应其他nonebot_plugin_gocqhttp机器人账号的信息 # 不响应其他nonebot_plugin_gocqhttp机器人账号的信息
@ -35,6 +40,8 @@ async def get_answer(event: GroupMessageEvent, state: T_State) -> bool:
# 不响应被屏蔽的人的信息 # 不响应被屏蔽的人的信息
if event.user_id in config.paimon_chat_ban: if event.user_id in config.paimon_chat_ban:
return False return False
elif not checkGroup(event): # 判断群组
return False
chat: Chat = Chat(event) chat: Chat = Chat(event)
to_learn = True to_learn = True
# 多账号登陆,且在同一群中时;避免一条消息被处理多次 # 多账号登陆,且在同一群中时;避免一条消息被处理多次
@ -64,7 +71,7 @@ async def get_answer(event: GroupMessageEvent, state: T_State) -> bool:
any_msg = on_message( any_msg = on_message(
priority=20, priority=20,
block=False, block=False,
rule=Rule(check_accounts, get_answer), rule=Rule(check_accounts, get_answer, checkGroup),
permission=permission.GROUP # | permission.PRIVATE_FRIEND permission=permission.GROUP # | permission.PRIVATE_FRIEND
) )
@ -108,10 +115,10 @@ async def is_reply(bot: Bot, event: GroupMessageEvent) -> bool:
ban_msg = on_message( ban_msg = on_message(
rule=to_me() & keyword('不可以', '达咩', '不行', 'no') & Rule(is_reply), rule=to_me() & keyword('不可以', '达咩', '不行', 'no') & Rule(is_reply, checkGroup),
priority=5, priority=5,
block=True, block=True,
permission=permission.GROUP_OWNER | permission.GROUP_ADMIN permission=permission.GROUP_OWNER | permission.GROUP_ADMIN | SUPERUSER
) )
@ -142,10 +149,10 @@ async def message_is_ban(bot: Bot, event: GroupMessageEvent) -> bool:
ban_msg_latest = on_message( ban_msg_latest = on_message(
rule=to_me() & Rule(message_is_ban), rule=to_me() & Rule(message_is_ban, checkGroup),
priority=5, priority=5,
block=True, block=True,
permission=permission.GROUP_OWNER | permission.GROUP_ADMIN permission=permission.GROUP_OWNER | permission.GROUP_ADMIN | SUPERUSER
) )
@ -184,7 +191,7 @@ async def is_drink_msg(bot: Bot, event: GroupMessageEvent) -> bool:
drink_msg = on_message( drink_msg = on_message(
rule=Rule(is_drink_msg), rule=Rule(is_drink_msg, checkGroup),
priority=5, priority=5,
block=True, block=True,
permission=permission.GROUP_OWNER | permission.GROUP_ADMIN permission=permission.GROUP_OWNER | permission.GROUP_ADMIN
@ -212,3 +219,135 @@ async def _(bot: Bot, event: GroupMessageEvent):
def update_data(): def update_data():
Chat.clearup_context() Chat.clearup_context()
Chat.completely_sober() Chat.completely_sober()
#群组开启
onLearningGroup = on_message(
rule = to_me() & keyword("派蒙学习开启","说怪话"),
priority = 4,
block = True,
permission=permission.GROUP_ADMIN | permission.GROUP_OWNER | SUPERUSER
)
onLearningGroup.__paimon_help__ = {
"usage": "@派蒙 <说怪话>",
"introduce": "开启派蒙在该群的机器学习能力",
"priority": 99
}
@onLearningGroup.handle()
async def _(bot: Bot, event: GroupMessageEvent):
if checkGroup(event):
await onLearningGroup.finish("派蒙已经在学习群友的话了哦")
else:
Chat.learningGroup.append(event.group_id)
await onLearningGroup.finish("派蒙开始学习群友说怪话!")
#群组关闭
offLearningGroup = on_message(
rule = to_me() & keyword("派蒙学习关闭","不准说怪话"),
priority = 4,
block = True,
permission=permission.GROUP_ADMIN | permission.GROUP_OWNER | SUPERUSER
)
offLearningGroup.__paimon_help__ = {
"usage": "@派蒙 <不准说怪话>",
"introduce": "关闭派蒙在该群的机器学习能力",
"priority": 99
}
@offLearningGroup.handle()
async def _(bot: Bot, event: GroupMessageEvent):
if not checkGroup(event):
await offLearningGroup.finish("派蒙没有在学群友说话!")
else:
Chat.learningGroup.remove(event.group_id)
await offLearningGroup.finish("派蒙不学就是了TAT")
#发癫
fun_msg = on_message(
rule=to_me() & keyword('发癫','派蒙发癫','喝酒') & Rule(checkGroup),
priority=6,
block=True,
permission=permission.GROUP_ADMIN | permission.GROUP_OWNER | SUPERUSER
)
fun_msg.__paimon_help__ = {
"usage": "@派蒙 <发癫>",
"introduce": "派蒙喝醉了在群里发癫",
"priority": 99
}
@fun_msg.handle()
async def funmsg(bot: Bot, event: GroupMessageEvent):
logger.info(f'repeater派蒙开始发癫')
Chat.answer_threshold = 1
Chat.speak_threshold = 1
Chat.speak_continuously_probability = 1
Chat.speak_poke_probability = 1
Chat.speak_continuously_max_len = 10
Chat.cross_group_threshold = 1
msg_send = ['呀,旅行者。你今天走起路来,怎么看着摇摇晃晃的?嘿嘿嘿~~~','……&%*&U*……&%']
await fun_msg.finish(random.choice(msg_send))
#停止发癫
stop_fun_msg = on_message(
rule=to_me() & keyword('恢复','不准发癫','停止','stop'),
priority=5,
block=True,
permission=permission.GROUP_ADMIN | permission.GROUP_OWNER | SUPERUSER
)
stop_fun_msg.__paimon_help__ = {
"usage": "@派蒙 <不准发癫>",
"introduce": "让派蒙恢复正常",
"priority": 99
}
@stop_fun_msg.handle()
async def stopfunmsg(bot: Bot, event: GroupMessageEvent):
logger.info(f'repeater派蒙停止发癫')
Chat.answer_threshold = config.paimon_answer_threshold
Chat.speak_threshold = config.paimon_speak_threshold
Chat.speak_continuously_probability = config.paimon_speak_continuously_probability
Chat.speak_poke_probability = config.paimon_speak_poke_probability
Chat.speak_continuously_max_len = config.paimon_speak_continuously_max_len
Chat.cross_group_threshold = config.paimon_cross_group_threshold
msg_send = ['呃...头好疼...恢复了']
await stop_fun_msg.finish(msg_send)
#上调学习能力和主动发言
upLearning = on_message(
rule=to_me() & keyword('加强学习能力','派蒙快学','再学快点','多说点话') & Rule(checkGroup),
priority=6,
block=True,
permission=permission.GROUP_ADMIN | permission.GROUP_OWNER | SUPERUSER
)
upLearning.__paimon_help__ = {
"usage": "@派蒙 <派蒙快学>",
"introduce": "增强派蒙的学习能力",
"priority": 99
}
@upLearning.handle()
async def _(bot: Bot, event: GroupMessageEvent):
if Chat.answer_threshold == 1:
Chat.answer_threshold = Chat.speak_threshold
await upLearning.finish("派蒙已经学满贯了")
else:
Chat.speak_threshold -= 1
Chat.answer_threshold = Chat.speak_threshold
await upLearning.finish("派蒙会努力学习的")
#降低学习能力和主动发言
downLearning = on_message(
rule=to_me() & keyword('降低学习能力','派蒙变笨','笨比派蒙','少说点话') & Rule(checkGroup),
priority=6,
block=True,
permission=permission.GROUP_ADMIN | permission.GROUP_OWNER | SUPERUSER
)
downLearning.__paimon_help__ = {
"usage": "@派蒙 <派蒙变笨>",
"introduce": "降低派蒙的学习能力",
"priority": 99
}
@downLearning.handle()
async def _(bot: Bot, event: GroupMessageEvent):
if Chat.answer_threshold == 6:
Chat.answer_threshold = Chat.speak_threshold
await downLearning.finish("派蒙不说话就是了o( ̄ヘ ̄o)")
else:
Chat.speak_threshold += 1
Chat.answer_threshold = Chat.speak_threshold
await downLearning.finish("知道了知道了,旅行者就是嫌派蒙吵了")

View File

@ -104,6 +104,8 @@ class Chat:
blacklist_answer = defaultdict(set) blacklist_answer = defaultdict(set)
blacklist_answer_reserve = defaultdict(set) blacklist_answer_reserve = defaultdict(set)
learningGroup = config.paimonLearningGroup# 机器学习群组
def __init__(self, data: Union[ChatData, GroupMessageEvent, PrivateMessageEvent]): def __init__(self, data: Union[ChatData, GroupMessageEvent, PrivateMessageEvent]):
if isinstance(data, ChatData): if isinstance(data, ChatData):

View File

@ -11,6 +11,12 @@ from utils.config import config
from utils.auth_util import FreqLimiter2 from utils.auth_util import FreqLimiter2
from utils.message_util import MessageBuild from utils.message_util import MessageBuild
from utils.file_handler import load_json_from_url from utils.file_handler import load_json_from_url
__paimon_help__ = {
'type': '派蒙机器学习',
'range': ['private', 'group', 'guild']
}
if config.paimon_mongodb_url: if config.paimon_mongodb_url:
try: try:
from .Learning_repeate import main from .Learning_repeate import main

View File

@ -37,7 +37,7 @@ class PluginConfig(BaseModel):
# 以下为机器学习聊天模块配置 # 以下为机器学习聊天模块配置
# mongodb数据库连接url # mongodb数据库连接url
paimon_mongodb_url: str = None paimon_mongodb_url: str = "mongodb://localhost:27017"
# 派蒙聊天屏蔽用户 # 派蒙聊天屏蔽用户
paimon_chat_ban: List[int] = [] paimon_chat_ban: List[int] = []
# 派蒙聊天学习阈值,越小学习越快 # 派蒙聊天学习阈值,越小学习越快
@ -60,6 +60,8 @@ class PluginConfig(BaseModel):
paimon_speak_poke_probability: float = 0.5 paimon_speak_poke_probability: float = 0.5
# 连续主动说话最多几句话 # 连续主动说话最多几句话
paimon_speak_continuously_max_len: int = 3 paimon_speak_continuously_max_len: int = 3
# 机器学习开启群组
paimonLearningGroup: List[int] = []
# 派蒙收到好友申请或群邀请时是否向超级管理员发通知 # 派蒙收到好友申请或群邀请时是否向超级管理员发通知
paimon_request_remind: bool = True paimon_request_remind: bool = True