mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-12-16 13:40:53 +08:00
新增实时便签树脂提醒
This commit is contained in:
parent
47474ffe6a
commit
a2e8dff95c
@ -64,7 +64,7 @@
|
|||||||
|
|
||||||
## 功能列表🌅
|
## 功能列表🌅
|
||||||
|
|
||||||
详见[功能列表I](https://github.com/CMHopeSunshine/LittlePaimon/wiki/%E5%8A%9F%E8%83%BD%E5%88%97%E8%A1%A8),向派蒙发送`#帮助派蒙`可以查看指令列表。
|
详见[功能列表](https://github.com/CMHopeSunshine/LittlePaimon/wiki/%E5%8A%9F%E8%83%BD%E5%88%97%E8%A1%A8),向派蒙发送`#帮助派蒙`可以查看指令列表。
|
||||||
|
|
||||||
## 部署方法🖥️
|
## 部署方法🖥️
|
||||||
|
|
||||||
@ -107,6 +107,8 @@ javascript:(function(){prompt(document.domain,document.cookie)})();
|
|||||||
|
|
||||||
## 新功能更新😙
|
## 新功能更新😙
|
||||||
|
|
||||||
|
> 更新涉及的功能指令前往[功能列表](https://github.com/CMHopeSunshine/LittlePaimon/wiki/%E5%8A%9F%E8%83%BD%E5%88%97%E8%A1%A8)查看哦
|
||||||
|
|
||||||
- 3.20 新增Windows一键部署脚本
|
- 3.20 新增Windows一键部署脚本
|
||||||
- 3.22 新增蓝佬授权提供的收益曲线和参考面板攻略图
|
- 3.22 新增蓝佬授权提供的收益曲线和参考面板攻略图
|
||||||
- 3.24 新增抽卡记录导出和分析功能,原模拟抽卡的指令更改
|
- 3.24 新增抽卡记录导出和分析功能,原模拟抽卡的指令更改
|
||||||
@ -114,16 +116,17 @@ javascript:(function(){prompt(document.domain,document.cookie)})();
|
|||||||
- 3.31 实时便签加入参量质变仪信息
|
- 3.31 实时便签加入参量质变仪信息
|
||||||
- 4.11 改用数据库进行数据存储,优化代码
|
- 4.11 改用数据库进行数据存储,优化代码
|
||||||
- 4.14 新增每日天赋突破材料表查询
|
- 4.14 新增每日天赋突破材料表查询
|
||||||
|
- 4.15 新增实时便签树脂提醒功能
|
||||||
|
|
||||||
## ToDo🕛
|
## ToDo🕛
|
||||||
|
|
||||||
- [ ] 实时便签树脂提醒
|
- [x] 实时便签树脂提醒
|
||||||
- [x] 抽卡记录导出和分析
|
- [x] 抽卡记录导出和分析
|
||||||
- [ ] ocr圣遗物评分和角色面板记录
|
- [ ] ocr圣遗物评分和角色面板记录
|
||||||
- [ ] 角色、武器和圣遗物wiki
|
- [ ] 角色、武器和圣遗物wiki
|
||||||
- [ ] 派蒙AI闲聊
|
- [ ] 派蒙AI闲聊
|
||||||
- [ ] 米游社自动签到
|
- [ ] 米游社自动签到
|
||||||
- [ ] 今日可刷材料
|
- [x] 今日可刷材料
|
||||||
- [ ] 角色练度统计
|
- [ ] 角色练度统计
|
||||||
- [ ] 派蒙戳一戳集卡
|
- [ ] 派蒙戳一戳集卡
|
||||||
|
|
||||||
|
@ -1,13 +1,16 @@
|
|||||||
import json,os,re
|
import re
|
||||||
from hoshino import R,MessageSegment,logger, Service
|
from hoshino import Service
|
||||||
from hoshino.typing import CQEvent, Message
|
|
||||||
from hoshino.util import filt_message
|
|
||||||
from ..util import get_uid_in_msg
|
from ..util import get_uid_in_msg
|
||||||
from ..get_data import get_daily_note_data
|
from ..get_data import get_daily_note_data
|
||||||
from .get_img import draw_daily_note_card
|
from .get_img import draw_daily_note_card
|
||||||
|
from ..db_util import update_note_remind2, update_note_remind, get_note_remind, delete_note_remind, update_day_remind_count
|
||||||
|
from hoshino import get_bot, logger
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from asyncio import sleep
|
||||||
|
|
||||||
help_msg='''
|
help_msg='''
|
||||||
[ssbq/实时便签 (uid)]查询当前树脂、洞天宝钱、派遣状况等
|
[ssbq/实时便签 (uid)]查询当前树脂、洞天宝钱、派遣状况等
|
||||||
|
[ssbq (uid) 开启提醒(树脂数)/关闭提醒]开启/关闭树脂提醒,达到树脂数时会在群里艾特你
|
||||||
*绑定私人cookie之后才能使用
|
*绑定私人cookie之后才能使用
|
||||||
'''
|
'''
|
||||||
sv = Service('派蒙实时便签', bundle='派蒙', help_=help_msg)
|
sv = Service('派蒙实时便签', bundle='派蒙', help_=help_msg)
|
||||||
@ -15,6 +18,22 @@ sv = Service('派蒙实时便签', bundle='派蒙', help_=help_msg)
|
|||||||
@sv.on_prefix(('ssbq','实时便笺','实时便签'))
|
@sv.on_prefix(('ssbq','实时便笺','实时便签'))
|
||||||
async def main(bot,ev):
|
async def main(bot,ev):
|
||||||
uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
|
uid, msg, user_id, use_cache = await get_uid_in_msg(ev)
|
||||||
|
find_remind_enable = re.search(r'(?P<action>开启提醒|关闭提醒|删除提醒)((?P<num>\d{1,3})|(?:.*))', msg)
|
||||||
|
if find_remind_enable:
|
||||||
|
if find_remind_enable.group('action') == '开启提醒':
|
||||||
|
if find_remind_enable.group('num'):
|
||||||
|
await update_note_remind2(user_id, uid, str(ev.group_id), True, find_remind_enable.group('num'))
|
||||||
|
await bot.send(ev, f'开启提醒成功,派蒙会在你的树脂达到{find_remind_enable.group("num")}时在群里提醒你的', at_sender=True)
|
||||||
|
else:
|
||||||
|
await update_note_remind2(user_id, uid, str(ev.group_id), True)
|
||||||
|
await bot.send(ev, '开启提醒成功', at_sender=True)
|
||||||
|
elif find_remind_enable.group('action') == '关闭提醒':
|
||||||
|
await bot.send(ev, '关闭提醒成功', at_sender=True)
|
||||||
|
await update_note_remind2(user_id, uid, str(ev.group_id), False)
|
||||||
|
elif find_remind_enable.group('action') == '删除提醒':
|
||||||
|
await bot.send(ev, '删除提醒成功', at_sender=True)
|
||||||
|
await delete_note_remind(user_id, uid)
|
||||||
|
else:
|
||||||
try:
|
try:
|
||||||
data = await get_daily_note_data(uid)
|
data = await get_daily_note_data(uid)
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
@ -24,3 +43,45 @@ async def main(bot,ev):
|
|||||||
await bot.send(ev, daily_note_card, at_sender=True)
|
await bot.send(ev, daily_note_card, at_sender=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
await bot.send(ev, f'派蒙出现了问题:{e}',at_sender=True)
|
await bot.send(ev, f'派蒙出现了问题:{e}',at_sender=True)
|
||||||
|
|
||||||
|
@sv.scheduled_job('cron', minute='*/8')
|
||||||
|
async def check_note():
|
||||||
|
data = await get_note_remind()
|
||||||
|
if data:
|
||||||
|
now_time = datetime.now()
|
||||||
|
logger.info('---派蒙开始检查实时便签树脂提醒---')
|
||||||
|
for user_id, uid, count, remind_group, enable, last_remind_time, today_remind_count in data:
|
||||||
|
if last_remind_time:
|
||||||
|
last_remind_time = datetime.strptime(last_remind_time, '%Y%m%d %H:%M:%S')
|
||||||
|
if now_time - last_remind_time > timedelta(minutes=30):
|
||||||
|
time_e = True
|
||||||
|
else:
|
||||||
|
time_e = False
|
||||||
|
else:
|
||||||
|
time_e = True
|
||||||
|
if enable and ((today_remind_count and today_remind_count < 3) or not today_remind_count) and time_e:
|
||||||
|
now_data = await get_daily_note_data(uid)
|
||||||
|
if isinstance(now_data, str):
|
||||||
|
try:
|
||||||
|
await get_bot().send_group_msg(group_id=remind_group, message=f'[CQ:at,qq={user_id}]你的cookie失效了哦,派蒙没办法帮你检查树脂,先帮你删除了,请重新添加ck后再叫派蒙开启提醒')
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f'---派蒙发送树脂提醒失败:{e}---')
|
||||||
|
else:
|
||||||
|
if now_data['data']['current_resin'] >= count:
|
||||||
|
logger.info(f'---用户{user_id}的uid{uid}的树脂已经达到阈值了,发送提醒---')
|
||||||
|
if today_remind_count:
|
||||||
|
today_remind_count += 1
|
||||||
|
else:
|
||||||
|
today_remind_count = 1
|
||||||
|
now_time_str = now_time.strftime('%Y%m%d %H:%M:%S')
|
||||||
|
try:
|
||||||
|
await update_note_remind(user_id, uid, count, remind_group, enable, now_time_str, today_remind_count)
|
||||||
|
await get_bot().send_group_msg(group_id=remind_group, message=f'[CQ:at,qq={user_id}]⚠️你的树脂已经达到了{now_data["data"]["current_resin"]},派蒙30分钟后还会帮你检查⚠️')
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f'---派蒙发送树脂提醒失败:{e}---')
|
||||||
|
await sleep(2)
|
||||||
|
|
||||||
|
@sv.scheduled_job('cron', hour='0')
|
||||||
|
async def delete_day_limit():
|
||||||
|
logger.info('---清空今日树脂提醒限制---')
|
||||||
|
await update_day_remind_count()
|
@ -248,7 +248,102 @@ async def update_last_query(user_id, value, key='uid'):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
# 获取树脂提醒信息
|
||||||
|
async def get_note_remind():
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('''CREATE TABLE IF NOT EXISTS note_remind
|
||||||
|
(
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
uid TEXT NOT NULL,
|
||||||
|
count INTEGER,
|
||||||
|
remind_group TEXT,
|
||||||
|
enable bool,
|
||||||
|
last_remind_time datetime,
|
||||||
|
today_remind_count INTEGER,
|
||||||
|
PRIMARY KEY (user_id, uid)
|
||||||
|
);''')
|
||||||
|
cursor.execute('SELECT * FROM note_remind;')
|
||||||
|
res = cursor.fetchall()
|
||||||
|
conn.close()
|
||||||
|
return res
|
||||||
|
|
||||||
|
# 更新树脂提醒信息
|
||||||
|
async def update_note_remind(user_id, uid, count, remind_group, enable, last_remind_time, today_remind_count):
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('''CREATE TABLE IF NOT EXISTS note_remind
|
||||||
|
(
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
uid TEXT NOT NULL,
|
||||||
|
count INTEGER,
|
||||||
|
remind_group TEXT,
|
||||||
|
enable boolean,
|
||||||
|
last_remind_time datetime,
|
||||||
|
today_remind_count INTEGER,
|
||||||
|
PRIMARY KEY (user_id, uid)
|
||||||
|
);''')
|
||||||
|
cursor.execute('REPLACE INTO note_remind VALUES (?, ?, ?, ?, ?, ?, ?);', (user_id, uid, count, remind_group, enable, last_remind_time, today_remind_count))
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
async def update_note_remind2(user_id, uid, remind_group, enable=True, count=''):
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('''CREATE TABLE IF NOT EXISTS note_remind
|
||||||
|
(
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
uid TEXT NOT NULL,
|
||||||
|
count INTEGER,
|
||||||
|
remind_group TEXT,
|
||||||
|
enable boolean,
|
||||||
|
last_remind_time datetime,
|
||||||
|
today_remind_count INTEGER,
|
||||||
|
PRIMARY KEY (user_id, uid)
|
||||||
|
);''')
|
||||||
|
if count:
|
||||||
|
cursor.execute(f'REPLACE INTO note_remind (user_id, uid, remind_group, count, enable) VALUES ("{user_id}", "{uid}", "{remind_group}", {count}, {enable});')
|
||||||
|
else:
|
||||||
|
cursor.execute(f'UPDATE note_remind SET enable={enable}, remind_group={remind_group} WHERE user_id="{user_id}" AND uid="{uid}"')
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
async def update_day_remind_count():
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('''CREATE TABLE IF NOT EXISTS note_remind
|
||||||
|
(
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
uid TEXT NOT NULL,
|
||||||
|
count INTEGER,
|
||||||
|
remind_group TEXT,
|
||||||
|
enable bool,
|
||||||
|
last_remind_time datetime,
|
||||||
|
today_remind_count INTEGER,
|
||||||
|
PRIMARY KEY (user_id, uid)
|
||||||
|
);''')
|
||||||
|
cursor.execute('UPDATE note_remind SET today_remind_count=0 WHERE today_remind_count!=0')
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
# 删除树脂提醒信息
|
||||||
|
async def delete_note_remind(user_id, uid):
|
||||||
|
conn = sqlite3.connect(db_path)
|
||||||
|
cursor = conn.cursor()
|
||||||
|
cursor.execute('''CREATE TABLE IF NOT EXISTS note_remind
|
||||||
|
(
|
||||||
|
user_id TEXT NOT NULL,
|
||||||
|
uid TEXT NOT NULL,
|
||||||
|
count INTEGER,
|
||||||
|
remind_group TEXT,
|
||||||
|
enable bool,
|
||||||
|
last_remind_time datetime,
|
||||||
|
today_remind_count INTEGER,
|
||||||
|
PRIMARY KEY (user_id, uid)
|
||||||
|
);''')
|
||||||
|
cursor.execute('DELETE FROM note_remind WHERE user_id=? AND uid=?;', (user_id, uid))
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
init_db()
|
init_db()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user