💥 修改签到等相关推送设置、修改配置模型

This commit is contained in:
Wuyi无疑 2023-03-12 12:27:53 +08:00
parent 01186ac23b
commit a77f17990d
10 changed files with 78 additions and 57 deletions

View File

@ -93,13 +93,13 @@ async def check_ann_state():
img = await convert_img(img) img = await convert_img(img)
for bot_id in sub_list: for bot_id in sub_list:
try: try:
if bot_id in gss.active_bot: for BOT_ID in gss.active_bot:
bot = gss.active_bot[bot_id] bot = gss.active_bot[BOT_ID]
else: for group_id in sub_list[bot_id]:
continue await bot.target_send(
for group_id in sub_list[bot_id]: img, 'group', group_id, bot_id, ''
await bot.target_send(img, 'group', group_id) )
await asyncio.sleep(random.uniform(1, 3)) await asyncio.sleep(random.uniform(1, 3))
except Exception as e: except Exception as e:
logger.exception(e) logger.exception(e)
except Exception as e: except Exception as e:

View File

@ -1,10 +1,14 @@
from typing import Dict, Union from typing import Dict
from .models import GsStrConfig, GsBoolConfig, GsDictConfig, GsListConfig from .models import (
GSC,
GsStrConfig,
GsBoolConfig,
GsDictConfig,
GsListIntConfig,
)
CONIFG_DEFAULT: Dict[ CONIFG_DEFAULT: Dict[str, GSC] = {
str, Union[GsDictConfig, GsBoolConfig, GsListConfig, GsStrConfig]
] = {
'proxy': GsStrConfig('设置代理', '设置国际服的代理地址', ''), 'proxy': GsStrConfig('设置代理', '设置国际服的代理地址', ''),
'_pass_API': GsStrConfig('神奇API', '设置某种神奇的API', ''), '_pass_API': GsStrConfig('神奇API', '设置某种神奇的API', ''),
'random_pic_API': GsStrConfig( 'random_pic_API': GsStrConfig(
@ -17,7 +21,7 @@ CONIFG_DEFAULT: Dict[
'原神公告推送群组', '原神公告推送群组',
{}, {},
), ),
'Ann_Ids': GsListConfig( 'Ann_Ids': GsListIntConfig(
'推送公告ID', '推送公告ID',
'原神公告推送ID列表', '原神公告推送ID列表',
[], [],

View File

@ -4,10 +4,18 @@ from msgspec import json as msgjson
from .config_default import CONIFG_DEFAULT from .config_default import CONIFG_DEFAULT
from ..utils.resource.RESOURCE_PATH import CONFIG_PATH from ..utils.resource.RESOURCE_PATH import CONFIG_PATH
from .models import GSC, GsStrConfig, GsBoolConfig, GsDictConfig, GsListConfig from .models import (
GSC,
GsStrConfig,
GsBoolConfig,
GsDictConfig,
GsListIntConfig,
GsListStrConfig,
)
STR_CONFIG = Literal['proxy', '_pass_API', 'random_pic_API'] STR_CONFIG = Literal['proxy', '_pass_API', 'random_pic_API']
LIST_CONFIG = Literal['Ann_Ids'] LIST_INT_CONFIG = Literal['Ann_Ids']
LIST_STR_CONFIG = Literal['']
DICT_CONFIG = Literal['Ann_Groups'] DICT_CONFIG = Literal['Ann_Groups']
@ -61,7 +69,11 @@ class StringConfig:
... ...
@overload @overload
def get_config(self, key: LIST_CONFIG) -> GsListConfig: def get_config(self, key: LIST_INT_CONFIG) -> GsListIntConfig:
...
@overload
def get_config(self, key: LIST_STR_CONFIG) -> GsListStrConfig:
... ...
@overload @overload
@ -86,7 +98,11 @@ class StringConfig:
... ...
@overload @overload
def set_config(self, key: LIST_CONFIG, value: List) -> bool: def set_config(self, key: LIST_INT_CONFIG, value: List[int]) -> bool:
...
@overload
def set_config(self, key: LIST_STR_CONFIG, value: List[str]) -> bool:
... ...
@overload @overload

View File

@ -20,8 +20,14 @@ class GsDictConfig(GsConfig, tag=True):
data: Dict[str, List] data: Dict[str, List]
class GsListConfig(GsConfig, tag=True): class GsListStrConfig(GsConfig, tag=True):
data: List[str] data: List[str]
GSC = Union[GsDictConfig, GsBoolConfig, GsListConfig, GsStrConfig] class GsListIntConfig(GsConfig, tag=True):
data: List[int]
GSC = Union[
GsDictConfig, GsBoolConfig, GsListIntConfig, GsListStrConfig, GsStrConfig
]

View File

@ -52,12 +52,13 @@ async def send_daily_sign():
# 执行私聊推送 # 执行私聊推送
for qid in private_msg_list: for qid in private_msg_list:
try: try:
for single in private_msg_list[qid]: for bot_id in gss.active_bot:
await gss.active_bot['bot_id'].target_send( for single in private_msg_list[qid]:
single['msg'], 'direct', qid await gss.active_bot[bot_id].target_send(
) single['msg'], 'direct', qid, single['bot_id'], ''
except Exception: )
logger.warning(f'[每日全部签到] QQ {qid} 私聊推送失败!') except Exception as e:
logger.warning(f'[每日全部签到] QQ {qid} 私聊推送失败!错误信息:{e}')
await asyncio.sleep(0.5) await asyncio.sleep(0.5)
logger.info('[每日全部签到]私聊推送完成') logger.info('[每日全部签到]私聊推送完成')
@ -79,8 +80,11 @@ async def send_daily_sign():
msg_title = group_msg_list[gid]['push_message'] msg_title = group_msg_list[gid]['push_message']
# 发送群消息 # 发送群消息
try: try:
await gss.active_bot['bot_id'].target_send(msg_title, 'group', gid) for bot_id in gss.active_bot:
except Exception: await gss.active_bot[bot_id].target_send(
logger.warning(f'[每日全部签到]群 {gid} 推送失败!') msg_title, 'group', gid, group_msg_list[gid]['bot_id'], ''
)
except Exception as e:
logger.warning(f'[每日全部签到]群 {gid} 推送失败!错误信息:{e}')
await asyncio.sleep(0.5 + random.randint(1, 3)) await asyncio.sleep(0.5 + random.randint(1, 3))
logger.info('[每日全部签到]群聊推送完成') logger.info('[每日全部签到]群聊推送完成')

View File

@ -90,7 +90,6 @@ async def sign_in(uid: str) -> str:
if isinstance(sign_list, int) or isinstance(new_sign_info, int): if isinstance(sign_list, int) or isinstance(new_sign_info, int):
logger.warning(f'[签到] {uid} 出错, 请检查Cookies是否过期') logger.warning(f'[签到] {uid} 出错, 请检查Cookies是否过期')
return '签到失败...请检查Cookies是否过期' return '签到失败...请检查Cookies是否过期'
status = sign_data['message']
# 获取签到奖励物品,拿旧的总签到天数 + 1 为新的签到天数,再 -1 即为今日奖励物品的下标 # 获取签到奖励物品,拿旧的总签到天数 + 1 为新的签到天数,再 -1 即为今日奖励物品的下标
getitem = sign_list['awards'][int(sign_info['total_sign_day']) + 1 - 1] getitem = sign_list['awards'][int(sign_info['total_sign_day']) + 1 - 1]
get_im = f'本次签到获得{getitem["name"]}x{getitem["cnt"]}' get_im = f'本次签到获得{getitem["name"]}x{getitem["cnt"]}'
@ -100,7 +99,7 @@ async def sign_in(uid: str) -> str:
if new_sign_info['is_sign']: if new_sign_info['is_sign']:
mes_im = '签到成功' mes_im = '签到成功'
else: else:
mes_im = f'签到失败, 状态为:{status}' mes_im = '签到失败...'
sign_missed -= 1 sign_missed -= 1
sign_missed = sign_info.get('sign_cnt_missed') or sign_missed sign_missed = sign_info.get('sign_cnt_missed') or sign_missed
im = f'{mes_im}!\n{get_im}\n本月漏签次数:{sign_missed}' im = f'{mes_im}!\n{get_im}\n本月漏签次数:{sign_missed}'
@ -141,22 +140,6 @@ async def single_daily_sign(bot_id: str, uid: str, gid: str, qid: str):
async def daily_sign(): async def daily_sign():
"""
:说明:
将数据库中全部Status不为`off`的用户进行签到,
并返回签到信息private_msg_list, group_msg_list,
private_msg_list = [{'qid': 'msg'}, ...],
group_msg_list = [
{'gid': {'success': 0, 'failed': 0, 'push_message': ''}}, ...
],
如开启简洁签到,
success = 签到成功数,
failed = 签到失败数,
不开启简洁签到,
success将为负数,
:返回:
* {'private_msg_list': ..., 'group_msg_list': ...} (dict): 要发送的私聊消息和群聊消息
"""
global already global already
tasks = [] tasks = []
for bot_id in gss.active_bot: for bot_id in gss.active_bot:
@ -166,7 +149,7 @@ async def daily_sign():
if user.sign_switch != 'off': if user.sign_switch != 'off':
tasks.append( tasks.append(
single_daily_sign( single_daily_sign(
bot_id, user.uid, user.sign_switch, user.user_id user.bot_id, user.uid, user.sign_switch, user.user_id
) )
) )
if len(tasks) >= 1: if len(tasks) >= 1:

View File

@ -209,7 +209,7 @@ class MysApi:
HEADER = copy.deepcopy(_HEADER) HEADER = copy.deepcopy(_HEADER)
HEADER['Cookie'] = ck HEADER['Cookie'] = ck
HEADER['x-rpc-device_id'] = random_hex(32) HEADER['x-rpc-device_id'] = random_hex(32)
HEADER['x-rpc-app_version'] = '2.35.2' HEADER['x-rpc-app_version'] = '2.44.1'
HEADER['x-rpc-client_type'] = '5' HEADER['x-rpc-client_type'] = '5'
HEADER['X_Requested_With'] = 'com.mihoyo.hyperion' HEADER['X_Requested_With'] = 'com.mihoyo.hyperion'
HEADER['DS'] = get_web_ds_token(True) HEADER['DS'] = get_web_ds_token(True)
@ -824,7 +824,13 @@ class MysApi:
timeout=300, timeout=300,
) as resp: ) as resp:
raw_data = await resp.json() raw_data = await resp.json()
retcode: int = raw_data['retcode'] print(raw_data)
if 'retcode' in raw_data:
retcode: int = raw_data['retcode']
elif 'code' in raw_data:
retcode: int = raw_data['code']
else:
retcode = 0
if retcode == 1034: if retcode == 1034:
await self._upass(header) await self._upass(header)
return retcode return retcode

View File

@ -18,7 +18,9 @@ class SQLA:
self.bot_id = bot_id self.bot_id = bot_id
self.url = f'sqlite+aiosqlite:///{url}' self.url = f'sqlite+aiosqlite:///{url}'
self.engine = create_async_engine(self.url, pool_recycle=1500) self.engine = create_async_engine(self.url, pool_recycle=1500)
self.session = sessionmaker(self.engine, class_=AsyncSession)() self.session = sessionmaker(
self.engine, expire_on_commit=False, class_=AsyncSession
)()
def create_all(self): def create_all(self):
asyncio.create_task(self._create_all()) asyncio.create_task(self._create_all())

12
poetry.lock generated
View File

@ -947,14 +947,14 @@ socks = ["socksio (>=1.0.0,<2.0.0)"]
[[package]] [[package]]
name = "identify" name = "identify"
version = "2.5.19" version = "2.5.20"
description = "File identification library for Python" description = "File identification library for Python"
category = "dev" category = "dev"
optional = false optional = false
python-versions = ">=3.7" python-versions = ">=3.7"
files = [ files = [
{file = "identify-2.5.19-py2.py3-none-any.whl", hash = "sha256:3ee3533e7f6f5023157fbebbd5687bb4b698ce6f305259e0d24b2d7d9efb72bc"}, {file = "identify-2.5.20-py2.py3-none-any.whl", hash = "sha256:5dfef8a745ca4f2c95f27e9db74cb4c8b6d9916383988e8791f3595868f78a33"},
{file = "identify-2.5.19.tar.gz", hash = "sha256:4102ecd051f6884449e7359e55b38ba6cd7aafb6ef27b8e2b38495a5723ea106"}, {file = "identify-2.5.20.tar.gz", hash = "sha256:c8b288552bc5f05a08aff09af2f58e6976bf8ac87beb38498a0e3d98ba64eb18"},
] ]
[package.extras] [package.extras]
@ -1396,14 +1396,14 @@ typing-extensions = ">=4.0.0,<5.0.0"
[[package]] [[package]]
name = "openpyxl" name = "openpyxl"
version = "3.1.1" version = "3.1.2"
description = "A Python library to read/write Excel 2010 xlsx/xlsm files" description = "A Python library to read/write Excel 2010 xlsx/xlsm files"
category = "main" category = "main"
optional = false optional = false
python-versions = ">=3.6" python-versions = ">=3.6"
files = [ files = [
{file = "openpyxl-3.1.1-py2.py3-none-any.whl", hash = "sha256:a0266e033e65f33ee697254b66116a5793c15fc92daf64711080000df4cfe0a8"}, {file = "openpyxl-3.1.2-py2.py3-none-any.whl", hash = "sha256:f91456ead12ab3c6c2e9491cf33ba6d08357d802192379bb482f1033ade496f5"},
{file = "openpyxl-3.1.1.tar.gz", hash = "sha256:f06d44e2c973781068bce5ecf860a09bcdb1c7f5ce1facd5e9aa82c92c93ae72"}, {file = "openpyxl-3.1.2.tar.gz", hash = "sha256:a6f5977418eff3b2d5500d54d9db50c8277a368436f4e4f8ddb1be3422870184"},
] ]
[package.dependencies] [package.dependencies]

View File

@ -32,7 +32,7 @@ msgspec==0.13.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.
multidict==6.0.4 ; python_full_version >= "3.8.1" and python_version < "4.0" multidict==6.0.4 ; python_full_version >= "3.8.1" and python_version < "4.0"
nonebot-plugin-apscheduler==0.2.0 ; python_full_version >= "3.8.1" and python_version < "4.0" nonebot-plugin-apscheduler==0.2.0 ; python_full_version >= "3.8.1" and python_version < "4.0"
nonebot2==2.0.0rc3 ; python_full_version >= "3.8.1" and python_version < "4.0" nonebot2==2.0.0rc3 ; python_full_version >= "3.8.1" and python_version < "4.0"
openpyxl==3.1.1 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" openpyxl==3.1.2 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
passlib==1.7.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" passlib==1.7.4 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
pillow==9.4.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" pillow==9.4.0 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"
pydantic==1.10.6 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0" pydantic==1.10.6 ; python_full_version >= "3.8.1" and python_full_version < "4.0.0"