增加敏感词过滤,fix bug

This commit is contained in:
CMHopeSunshine 2022-06-22 11:26:10 +08:00
parent a249f751d5
commit e7f26925ed
6 changed files with 2663 additions and 20 deletions

View File

@ -23,6 +23,7 @@ from utils.auth_util import check_cookie, FreqLimiter
from utils.decorator import exception_handler
from utils.enka_util import PlayerInfo
from utils.message_util import get_uid_in_msg, uid_userId_to_dict, replace_all, transform_uid, get_message_id
from utils.message_util import MessageBuild as MsgBd
from .draw_abyss_info import draw_abyss_card
from .draw_daily_note import draw_daily_note_card
from .draw_month_info import draw_monthinfo_card
@ -339,7 +340,7 @@ async def _(event: MessageEvent, state: T_State):
state['choice'] = match_alias
else:
if not match_alias:
await ysc.finish(f'没有找到叫{name}的角色哦~', at_sender=True)
await ysc.finish(MsgBd.Text(f'没有找到叫{name}的角色哦~'), at_sender=True)
elif 'choice' not in state:
msg = f'你要找的角色是哪个呀:\n'
# 将字典中每个键拼接到msg中并添加序号
@ -397,7 +398,7 @@ async def ysb_handler(event: MessageEvent, msg: Message = CommandArg()):
# 获取方法:登录网页版米游社,在地址栏粘贴代码:\njavascript:(function(){prompt(document.domain,document.cookie)})(
# );\n复制弹窗出来的字符串手机要via或chrome浏览器才行\n然后添加派蒙私聊发送ysb接刚刚复制的字符串例如:ysb
# UM_distinctid=17d131d...\ncookie是账号重要安全信息请确保机器人持有者可信赖 '''
res = '获取cookie的教程在这里哦\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1\n获取到后添加派蒙好友私聊发送ysb接复制到的cookie就行啦~'
res = '获取cookie的教程\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1\n获取到后添加派蒙好友私聊发送ysb接复制到的cookie就行啦~'
await ysb.finish(res, at_sender=True)
else:
cookie_info, mys_id = await get_bind_game(cookie)
@ -419,7 +420,7 @@ async def ysb_handler(event: MessageEvent, msg: Message = CommandArg()):
msg = f'{nickname}绑定成功啦!使用ys/ysa等指令和派蒙互动吧!'
if event.message_type != 'private':
msg += '\n当前是在群聊里绑定建议旅行者把cookie撤回哦!'
await ysb.finish(msg, at_sender=True)
await ysb.finish(MsgBd.Text(msg), at_sender=True)
@add_public_ck.handle()
@ -586,7 +587,7 @@ async def _(event: MessageEvent, state: T_State):
player_info = PlayerInfo(uid)
roles_list = player_info.get_roles_list()
if role not in roles_list:
await role_info.finish(f'派蒙还没有你{role}的信息哦,请先把该角色放在游戏内展柜中,然后使用 更新角色信息 命令更新~', at_sender=True)
await role_info.finish(MsgBd.Text(f'派蒙还没有你{role}的信息哦,请先把该角色放在游戏内展柜中,然后使用 更新角色信息 命令更新~'), at_sender=True)
else:
role_data = player_info.get_roles_info(role)
img = await draw_role_card(uid, role_data)

View File

@ -68,7 +68,7 @@ async def genshinAttribute(event: MessageEvent):
img = MessageBuild.Text(f'没有找到{name}的参考面板')
await attribute.finish(img)
else:
await attribute.finish(f'没有找到{name}的参考面板', at_sender=True)
await attribute.finish(MessageBuild.Text(f'没有找到{name}的参考面板'), at_sender=True)
@daily_material.handle()
@ -145,7 +145,7 @@ def create_choice_command(endswith: str, type_: str, url: str, tips: str = None,
await MessageBuild.StaticImage(url=url.format(match_alias[0]), tips=tips.format(match_alias[0])))
else:
if not match_alias:
await command.finish(f'没有{state["name"]}{endswith}哦~', at_sender=True)
await command.finish(MessageBuild.Text(f'没有{state["name"]}{endswith}哦~'), at_sender=True)
else:
if isinstance(match_alias, dict):
match_alias = list(match_alias.keys())

View File

@ -65,9 +65,6 @@
## 丨更新日志
> README只展示最近2条更新全部更新日志详见[这里](https://github.com/CMHopeSunshine/LittlePaimon/blob/nonebot2/UPDATE_LOG.md)
+ 6.19
- 新增`米游币商品兑换`功能,私聊机器人发送`myb`跟着一步步指引来做目前该功能还没有机会做测试出现问题请提issue
- `ysb`绑定cookie的方法增加腾讯文档
+ 6.21
- 适配`nonebot2 beta4`插件元数据请更新nb版本`pip install nonebot2 --upgrade`
- `Paimon_Chat`现在可以发图片、视频等,可自行添加
@ -76,6 +73,9 @@
- 增加部分注释文档
- 更换原神日历样式[@nicklly](https://github.com/nicklly) 需用到htmlrender插件`pip install nonebot-plugin-htmlrender`
- 添加`pyproject.toml`和`poetry.lock`
+ 6.22
- 增加文本敏感词过滤
- fix `原神日历`和发送图片bug
## 丨功能列表

View File

@ -42,4 +42,7 @@
- 对对联功能api更换
- 增加部分注释文档
- 更换原神日历样式[@nicklly](https://github.com/nicklly) 需用到htmlrender插件`pip install nonebot-plugin-htmlrender`
- 添加`pyproject.toml`和`poetry.lock`
- 添加`pyproject.toml`和`poetry.lock`
+ 6.22
- 增加文本敏感词过滤
- fix `原神日历`和发送图片bug

File diff suppressed because it is too large Load Diff

View File

@ -54,7 +54,7 @@ class MessageBuild:
if mode:
img = img.convert(mode)
bio = BytesIO()
img.save(bio, format=img.format or 'JPEG', quality=quality)
img.save(bio, format='JPEG' if img.mode == 'RGB' else 'PNG', quality=quality)
return MessageSegment.image(bio)
@classmethod
@ -96,19 +96,19 @@ class MessageBuild:
if mode:
img = img.convert(mode)
bio = BytesIO()
img.save(bio, format=img.format or 'JPEG', quality=quality)
img.save(bio, format='JPEG' if img.mode == 'RGB' else 'PNG', quality=quality)
return MessageSegment.image(bio)
@classmethod
def Text(cls, text: str) -> MessageSegment:
"""
过滤文本中的敏感
过滤文本中的敏感违禁
:param text: 文本
:return: MessageSegment.text
"""
for word in ban_word:
if word in text:
text = text.replace(word, '*')
for word in ban_word[2:]:
if word and word in text:
text = text.replace(word, '*' * len(word))
return MessageSegment.text(text)
@classmethod