mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-10-21 16:27:15 +08:00
🐛 修复群聊学习
用指令关闭学习后无法用指令再次开启的问题
This commit is contained in:
parent
06d2a1af82
commit
e8c07fb086
@ -39,6 +39,7 @@ class Result(IntEnum):
|
|||||||
Repeat = auto()
|
Repeat = auto()
|
||||||
Ban = auto()
|
Ban = auto()
|
||||||
SetEnable = auto()
|
SetEnable = auto()
|
||||||
|
SetDisable = auto()
|
||||||
|
|
||||||
|
|
||||||
class LearningChat:
|
class LearningChat:
|
||||||
@ -76,13 +77,19 @@ class LearningChat:
|
|||||||
|
|
||||||
async def _learn(self) -> Result:
|
async def _learn(self) -> Result:
|
||||||
# logger.debug('群聊学习', f'收到来自群<m>{self.data.group_id}</m>的消息<m>{self.data.message}</m>')
|
# logger.debug('群聊学习', f'收到来自群<m>{self.data.group_id}</m>的消息<m>{self.data.message}</m>')
|
||||||
if not chat_config.total_enable or not self.config.enable:
|
if self.to_me and any(
|
||||||
|
w in self.data.message for w in {'学说话', '快学', '开启学习'}):
|
||||||
|
return Result.SetEnable
|
||||||
|
elif self.to_me and any(
|
||||||
|
w in self.data.message for w in {'闭嘴', '别学', '关闭学习'}):
|
||||||
|
return Result.SetDisable
|
||||||
|
elif not chat_config.total_enable or not self.config.enable:
|
||||||
logger.debug('群聊学习', f'➤该群<m>{self.data.group_id}</m>未开启群聊学习,跳过')
|
logger.debug('群聊学习', f'➤该群<m>{self.data.group_id}</m>未开启群聊学习,跳过')
|
||||||
# 如果未开启群聊学习,跳过
|
# 如果未开启群聊学习,跳过
|
||||||
return Result.Pass
|
return Result.Pass
|
||||||
elif command_start_ and self.data.message.startswith(tuple(command_start_)):
|
elif command_start_ and self.data.message.startswith(tuple(command_start_)):
|
||||||
# 以命令前缀开头的消息,跳过
|
# 以命令前缀开头的消息,跳过
|
||||||
logger.debug('群聊学习', '➤消息以命令前缀开头,跳过')
|
logger.debug('群聊学习', '➤该消息以命令前缀开头,跳过')
|
||||||
return Result.Pass
|
return Result.Pass
|
||||||
elif self.data.user_id in self.ban_users:
|
elif self.data.user_id in self.ban_users:
|
||||||
# 发言人在屏蔽列表中,跳过
|
# 发言人在屏蔽列表中,跳过
|
||||||
@ -91,9 +98,6 @@ class LearningChat:
|
|||||||
elif self.to_me and any(w in self.data.message for w in {'不可以', '达咩', '不能说这'}):
|
elif self.to_me and any(w in self.data.message for w in {'不可以', '达咩', '不能说这'}):
|
||||||
# 如果是对某句话进行禁言
|
# 如果是对某句话进行禁言
|
||||||
return Result.Ban
|
return Result.Ban
|
||||||
elif self.to_me and any(
|
|
||||||
w in self.data.message for w in {'学说话', '快学', '开启学习', '闭嘴', '别学', '关闭学习'}):
|
|
||||||
return Result.SetEnable
|
|
||||||
elif not await self._check_allow(self.data):
|
elif not await self._check_allow(self.data):
|
||||||
# 本消息不合法,跳过
|
# 本消息不合法,跳过
|
||||||
logger.debug('群聊学习', '➤消息未通过校验,跳过')
|
logger.debug('群聊学习', '➤消息未通过校验,跳过')
|
||||||
@ -158,20 +162,16 @@ class LearningChat:
|
|||||||
return [random.choice(SORRY_WORDS)]
|
return [random.choice(SORRY_WORDS)]
|
||||||
else:
|
else:
|
||||||
return [random.choice(DOUBT_WORDS)]
|
return [random.choice(DOUBT_WORDS)]
|
||||||
elif result == Result.SetEnable:
|
elif result in [Result.SetEnable, Result.SetDisable]:
|
||||||
|
# 检查权限
|
||||||
if self.role not in {'superuser', 'admin', 'owner'}:
|
if self.role not in {'superuser', 'admin', 'owner'}:
|
||||||
return [random.choice(NO_PERMISSION_WORDS)]
|
return [random.choice(NO_PERMISSION_WORDS)]
|
||||||
# 检查权限
|
self.config.update(enable=(result == Result.SetEnable))
|
||||||
if any(w in self.data.message for w in {'学说话', '快学', '开启学习'}):
|
config_manager.config.group_config[self.data.group_id] = self.config
|
||||||
self.config.update(enable=True)
|
config_manager.save()
|
||||||
config_manager.config.group_config[self.data.group_id] = self.config
|
logger.info('群聊学习',
|
||||||
config_manager.save()
|
f'群<m>{self.data.group_id}</m>{"开启" if result == Result.SetEnable else "关闭"}学习功能')
|
||||||
return [random.choice(ENABLE_WORDS)]
|
return [random.choice(ENABLE_WORDS if result == Result.SetEnable else DISABLE_WORDS)]
|
||||||
else:
|
|
||||||
self.config.update(enable=False)
|
|
||||||
config_manager.config.group_config[self.data.group_id] = self.config
|
|
||||||
config_manager.save()
|
|
||||||
return [random.choice(DISABLE_WORDS)]
|
|
||||||
elif result == Result.Pass:
|
elif result == Result.Pass:
|
||||||
# 跳过
|
# 跳过
|
||||||
return None
|
return None
|
||||||
@ -179,7 +179,7 @@ class LearningChat:
|
|||||||
if await ChatMessage.filter(group_id=self.data.group_id,
|
if await ChatMessage.filter(group_id=self.data.group_id,
|
||||||
time__gte=self.data.time - 3600).limit(
|
time__gte=self.data.time - 3600).limit(
|
||||||
self.config.repeat_threshold + 5).filter(
|
self.config.repeat_threshold + 5).filter(
|
||||||
user_id=self.bot_id, message=self.data.message).exists():
|
user_id=self.bot_id, message=self.data.message).exists():
|
||||||
# 如果在阈值+5条消息内,bot已经回复过这句话,则跳过
|
# 如果在阈值+5条消息内,bot已经回复过这句话,则跳过
|
||||||
logger.debug('群聊学习', '➤➤已经复读过了,跳过')
|
logger.debug('群聊学习', '➤➤已经复读过了,跳过')
|
||||||
return None
|
return None
|
||||||
|
@ -3,7 +3,7 @@ import re
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import git
|
import git
|
||||||
from git.exc import GitCommandError, InvalidGitRepositoryError
|
from git.exc import InvalidGitRepositoryError
|
||||||
from nonebot.utils import run_sync
|
from nonebot.utils import run_sync
|
||||||
|
|
||||||
from . import __version__, NICKNAME
|
from . import __version__, NICKNAME
|
||||||
@ -54,7 +54,7 @@ def update():
|
|||||||
try:
|
try:
|
||||||
origin.pull()
|
origin.pull()
|
||||||
msg = f'更新完成,版本:{__version__}\n最新更新日志为:\n{repo.head.commit.message.replace(":bug:", "🐛").replace(":sparkles:", "✨").replace(":memo:", "📝")}\n可使用命令[@bot 重启]重启{NICKNAME}'
|
msg = f'更新完成,版本:{__version__}\n最新更新日志为:\n{repo.head.commit.message.replace(":bug:", "🐛").replace(":sparkles:", "✨").replace(":memo:", "📝")}\n可使用命令[@bot 重启]重启{NICKNAME}'
|
||||||
except GitCommandError as e:
|
except Exception as e:
|
||||||
if 'timeout' in e or 'unable to access' in e:
|
if 'timeout' in e or 'unable to access' in e:
|
||||||
msg = '更新失败,连接git仓库超时,请重试或修改源为代理源后再重试。'
|
msg = '更新失败,连接git仓库超时,请重试或修改源为代理源后再重试。'
|
||||||
elif ' Your local changes to the following files would be overwritten by merge' in e:
|
elif ' Your local changes to the following files would be overwritten by merge' in e:
|
||||||
@ -62,8 +62,9 @@ def update():
|
|||||||
'更新失败,本地修改过文件导致冲突,可在命令行运行git pull查看冲突的文件是哪些,请解决冲突后再更新。')
|
'更新失败,本地修改过文件导致冲突,可在命令行运行git pull查看冲突的文件是哪些,请解决冲突后再更新。')
|
||||||
else:
|
else:
|
||||||
msg = f'更新失败,错误信息:{e},请尝试手动进行更新'
|
msg = f'更新失败,错误信息:{e},请尝试手动进行更新'
|
||||||
if raw_plugins_load:
|
finally:
|
||||||
pyproject_new_content = pyproject_file.read_text(encoding='utf-8')
|
if raw_plugins_load:
|
||||||
pyproject_new_content = pyproject_new_content.replace('plugins = []', raw_plugins_load.group())
|
pyproject_new_content = pyproject_file.read_text(encoding='utf-8')
|
||||||
pyproject_file.write_text(pyproject_new_content, encoding='utf-8')
|
pyproject_new_content = pyproject_new_content.replace('plugins = []', raw_plugins_load.group())
|
||||||
|
pyproject_file.write_text(pyproject_new_content, encoding='utf-8')
|
||||||
return msg
|
return msg
|
||||||
|
Loading…
Reference in New Issue
Block a user