新增群聊记录学习发言

This commit is contained in:
CMHopeSunshine 2022-05-28 23:30:59 +08:00
parent 7f98ef6e4a
commit de09bb113f
9 changed files with 81 additions and 55 deletions

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/LittlePaimon.iml" filepath="$PROJECT_DIR$/.idea/LittlePaimon.iml" />
</modules>
</component>
</project>

View File

@ -7,7 +7,7 @@ from nonebot.params import CommandArg
from ..utils.config import config
from ..utils.file_handler import load_json, save_json
from ..utils.generate import *
from .generate import *
import re
HELP_STR = '''
@ -62,7 +62,7 @@ async def _(bot: Bot, event: Union[GroupMessageEvent, MessageEvent], msg: Messag
fun = str(msg).strip()
action = re.search(r'(?P<action>on|off|time|status|test)', fun)
if group_id not in config.paimon_calender_group:
if group_id not in config.paimon_calender_group or int(group_id) not in config.paimon_calender_group:
await calendar.finish(f"尚未在群 {group_id} 开启本功能!", at_sender=True)
if not fun:

View File

@ -1,9 +1,6 @@
import os
import json
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from .aiorequests import get
import aiohttp
from utils.aiorequests import get
import asyncio
import math
import functools

View File

@ -1,4 +1,3 @@
import base64
from io import BytesIO
from .event import *

View File

@ -11,6 +11,13 @@ from utils.config import config
from utils.auth_util import FreqLimiter2
from utils.message_util import MessageBuild
from utils.file_handler import load_json_from_url
if config.paimon_mongodb_url:
try:
from .Learning_repeate import main
except ImportError:
logger.info('派蒙机器学习聊天启用失败可能是mongodb连接失败或缺少相关库')
else:
logger.info('派蒙机器学习聊天启用失败mongodb尚未配置')
driver = get_driver()

View File

@ -77,6 +77,12 @@
- 修复可能因ssl证书导致的静态资源下载问题
+ 5.23
- 新增`xx原魔图鉴`
+ 5.25
- `ys、ysc、ysa、sy`等和`wiki`模块指令可以对话式查询
+ 5.27
- 新增`原神日历`[@nicklly](https://github.com/nicklly),需在`.env.*`配置`paimon_calender_group=[开启群号]`
+ 5.28
- `Paimon_Chat`聊天新增`学习群友发言`(魔改自[Pallas-Bot](https://github.com/InvoluteHell/Pallas-Bot/tree/master/src/plugins/repeater)),需安装`jieba_fast、pymongo、pypinyin依赖库`、`mongodb数据库`且在`.env.*`配置文件中添加mongodb连接参数`paimon_mongodb_url`,例如`paimon_mongodb_url=mongodb://localhost:27017/`
## 丨功能列表
@ -128,10 +134,11 @@ javascript:(function(){prompt(document.domain,document.cookie)})();
- [NoneBot2](https://github.com/nonebot/nonebot2) - 跨平台异步机器人框架
- [go-cqhttp](https://github.com/Mrs4s/go-cqhttp) - Onebot标准的框架实现
- [西北一枝花](https://github.com/Nwflower) - 部分图片的美工大大和武器攻略图提供
- [egenshin](https://github.com/pcrbot/erinilis-modules/tree/master/egenshin) - 参考了它的代码和资源
- [西北一枝花](https://github.com/Nwflower) - 美工大大和武器攻略图提供
- [egenshin](https://github.com/pcrbot/erinilis-modules/tree/master/egenshin) - 抽卡和猜语音代码、资源参考
- [bluemushoom](https://bbs.nga.cn/nuke.php?func=ucp&uid=62861898) - 全角色收益曲线和参考面板攻略图来源
- [genshin-gacha-export](https://github.com/sunfkny/genshin-gacha-export) - 抽卡记录导出参考
- [genshin-gacha-export](https://github.com/sunfkny/genshin-gacha-export) - 抽卡记录导出代码参考
- [Pallas-Bot](https://github.com/InvoluteHell/Pallas-Bot/tree/master/src/plugins/repeater) - 群聊记录发言学习代码参考
- [西风驿站](https://bbs.mihoyo.com/ys/collection/307224) - 角色攻略一图流来源
- [游创工坊](https://space.bilibili.com/176858937) - 深渊排行榜数据来源
@ -139,15 +146,15 @@ javascript:(function(){prompt(document.domain,document.cookie)})();
- 如果本项目对你有帮助给个star~~求求啦
- 部分资源使用了云存储,如果想赞助流量费用,欢迎来[爱发电](https://afdian.net/@cherishmoon),十分感谢!
### 赞助支持
十分感谢!
| 赞助者 | 金额 | 日期 |
| ------- | ---- | ---- |
| 深海 | 10 | 5.20 |
| 夜空koi | 30 | 5.22 |
| 情话 | 20 | 5.23 |
| 赞助者 | 金额 |
| --------------- | ---- |
| 深海 | 10 |
| 夜空koi | 30 |
| 情话 | 20 |
| 爱发电用户_Mfms | 15 |
| 米特建木 | 10 |
| 永远的皇珈骑士 | 30 |
| 小兔和鹿 | 30 |
## 丨其他

View File

@ -33,11 +33,38 @@ class PluginConfig(BaseModel):
paimon_add_group: bool = False
# 派蒙聊天开启群组
paimon_chat_group: List[int] = []
# 派蒙猜语音持续时间
paimon_guess_voice: int = 30
# 原神日历开启群组
paimon_calender_group: List[int] = []
# 以下为机器学习聊天模块配置
# mongodb数据库连接url
paimon_mongodb_url: str = None
# 派蒙聊天屏蔽用户
paimon_chat_ban: List[int] = []
# 派蒙聊天学习阈值,越小学习越快
paimon_answer_threshold: int = 3
# 派蒙聊天上限阈值
paimon_answer_limit_threshold: int = 25
# N个群有相同的回复就跨群作为全局回复
paimon_cross_group_threshold: int = 2
# 复读的阈值
paimon_repeat_threshold: int = 3
# 主动发言阈值,越小话越多
paimon_speak_threshold: int = 3
# 喝醉的概率
paimon_drunk_probability: float = 0.07
# 用文字转语音来回复的概率
paimon_voice_probability: float = 0.03
# 连续主动说话的概率
paimon_speak_continuously_probability: float = 0.5
# 主动说话加上随机戳一戳群友的概率
paimon_speak_poke_probability: float = 0.5
# 连续主动说话最多几句话
paimon_speak_continuously_max_len: int = 3
driver = get_driver()
global_config = driver.config

View File

@ -1,8 +1,5 @@
import sqlite3
import json
import os
import re
from nonebot import logger
from datetime import datetime
db_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'user_data', 'user_data.db')
@ -32,31 +29,31 @@ def init_db():
mys_id TEXT,
last_time datetime
);''')
try:
with open(os.path.join(os.path.dirname(__file__), 'user_data', 'user_cookies.json'), 'r',
encoding='utf-8') as f:
data = json.load(f)
for d in data['私人'].items():
for c in d[1]['cookies']:
match = re.search(r'account_id=(\d{6,12})', c['cookie'])
mys_id = match.group(1) if match else ''
cursor.execute('INSERT INTO private_cookies (user_id, uid, mys_id, cookie) VALUES (?, ?, ?, ?);',
(d[0], c['uid'], mys_id, c['cookie']))
cursor.execute('INSERT INTO last_query (user_id, uid, last_time) VALUES (?, ?, ?);',
(d[0], d[1]['last_query'], datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
cursor.execute('''CREATE TABLE IF NOT EXISTS public_cookies (
no int IDENTITY(1,1) PRIMARY KEY,
cookie TEXT,
status TEXT);''')
for d in data['通用']:
if d['cookie']:
try:
cursor.execute('INSERT INTO public_cookies VALUES (?, ?, "OK");', (d['no'], d['cookie']))
except:
pass
logger.info('---派蒙初始化数据库成功已导入原json数据---')
except:
logger.error('---派蒙初始化数据库失败请检查user_cookies.json文件是否存在---')
# try:
# with open(os.path.join(os.path.dirname(__file__), 'user_data', 'user_cookies.json'), 'r',
# encoding='utf-8') as f:
# data = json.load(f)
# for d in data['私人'].items():
# for c in d[1]['cookies']:
# match = re.search(r'account_id=(\d{6,12})', c['cookie'])
# mys_id = match.group(1) if match else ''
# cursor.execute('INSERT INTO private_cookies (user_id, uid, mys_id, cookie) VALUES (?, ?, ?, ?);',
# (d[0], c['uid'], mys_id, c['cookie']))
# cursor.execute('INSERT INTO last_query (user_id, uid, last_time) VALUES (?, ?, ?);',
# (d[0], d[1]['last_query'], datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
# cursor.execute('''CREATE TABLE IF NOT EXISTS public_cookies (
# no int IDENTITY(1,1) PRIMARY KEY,
# cookie TEXT,
# status TEXT);''')
# for d in data['通用']:
# if d['cookie']:
# try:
# cursor.execute('INSERT INTO public_cookies VALUES (?, ?, "OK");', (d['no'], d['cookie']))
# except:
# pass
# logger.info('---派蒙初始化数据库成功已导入原json数据---')
# except:
# logger.error('---派蒙初始化数据库失败请检查user_cookies.json文件是否存在---')
conn.commit()
conn.close()