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

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,12 +93,12 @@ async def check_ann_state():
img = await convert_img(img)
for bot_id in sub_list:
try:
if bot_id in gss.active_bot:
bot = gss.active_bot[bot_id]
else:
continue
for BOT_ID in gss.active_bot:
bot = gss.active_bot[BOT_ID]
for group_id in sub_list[bot_id]:
await bot.target_send(img, 'group', group_id)
await bot.target_send(
img, 'group', group_id, bot_id, ''
)
await asyncio.sleep(random.uniform(1, 3))
except Exception as e:
logger.exception(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[
str, Union[GsDictConfig, GsBoolConfig, GsListConfig, GsStrConfig]
] = {
CONIFG_DEFAULT: Dict[str, GSC] = {
'proxy': GsStrConfig('设置代理', '设置国际服的代理地址', ''),
'_pass_API': GsStrConfig('神奇API', '设置某种神奇的API', ''),
'random_pic_API': GsStrConfig(
@ -17,7 +21,7 @@ CONIFG_DEFAULT: Dict[
'原神公告推送群组',
{},
),
'Ann_Ids': GsListConfig(
'Ann_Ids': GsListIntConfig(
'推送公告ID',
'原神公告推送ID列表',
[],

View File

@ -4,10 +4,18 @@ from msgspec import json as msgjson
from .config_default import CONIFG_DEFAULT
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']
LIST_CONFIG = Literal['Ann_Ids']
LIST_INT_CONFIG = Literal['Ann_Ids']
LIST_STR_CONFIG = Literal['']
DICT_CONFIG = Literal['Ann_Groups']
@ -61,7 +69,11 @@ class StringConfig:
...
@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
@ -86,7 +98,11 @@ class StringConfig:
...
@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

View File

@ -20,8 +20,14 @@ class GsDictConfig(GsConfig, tag=True):
data: Dict[str, List]
class GsListConfig(GsConfig, tag=True):
class GsListStrConfig(GsConfig, tag=True):
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:
try:
for bot_id in gss.active_bot:
for single in private_msg_list[qid]:
await gss.active_bot['bot_id'].target_send(
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)
logger.info('[每日全部签到]私聊推送完成')
@ -79,8 +80,11 @@ async def send_daily_sign():
msg_title = group_msg_list[gid]['push_message']
# 发送群消息
try:
await gss.active_bot['bot_id'].target_send(msg_title, 'group', gid)
except Exception:
logger.warning(f'[每日全部签到]群 {gid} 推送失败!')
for bot_id in gss.active_bot:
await gss.active_bot[bot_id].target_send(
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))
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):
logger.warning(f'[签到] {uid} 出错, 请检查Cookies是否过期')
return '签到失败...请检查Cookies是否过期'
status = sign_data['message']
# 获取签到奖励物品,拿旧的总签到天数 + 1 为新的签到天数,再 -1 即为今日奖励物品的下标
getitem = sign_list['awards'][int(sign_info['total_sign_day']) + 1 - 1]
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']:
mes_im = '签到成功'
else:
mes_im = f'签到失败, 状态为:{status}'
mes_im = '签到失败...'
sign_missed -= 1
sign_missed = sign_info.get('sign_cnt_missed') or 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():
"""
:说明:
将数据库中全部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
tasks = []
for bot_id in gss.active_bot:
@ -166,7 +149,7 @@ async def daily_sign():
if user.sign_switch != 'off':
tasks.append(
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:

View File

@ -209,7 +209,7 @@ class MysApi:
HEADER = copy.deepcopy(_HEADER)
HEADER['Cookie'] = ck
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_Requested_With'] = 'com.mihoyo.hyperion'
HEADER['DS'] = get_web_ds_token(True)
@ -824,7 +824,13 @@ class MysApi:
timeout=300,
) as resp:
raw_data = await resp.json()
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:
await self._upass(header)
return retcode

View File

@ -18,7 +18,9 @@ class SQLA:
self.bot_id = bot_id
self.url = f'sqlite+aiosqlite:///{url}'
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):
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]]
name = "identify"
version = "2.5.19"
version = "2.5.20"
description = "File identification library for Python"
category = "dev"
optional = false
python-versions = ">=3.7"
files = [
{file = "identify-2.5.19-py2.py3-none-any.whl", hash = "sha256:3ee3533e7f6f5023157fbebbd5687bb4b698ce6f305259e0d24b2d7d9efb72bc"},
{file = "identify-2.5.19.tar.gz", hash = "sha256:4102ecd051f6884449e7359e55b38ba6cd7aafb6ef27b8e2b38495a5723ea106"},
{file = "identify-2.5.20-py2.py3-none-any.whl", hash = "sha256:5dfef8a745ca4f2c95f27e9db74cb4c8b6d9916383988e8791f3595868f78a33"},
{file = "identify-2.5.20.tar.gz", hash = "sha256:c8b288552bc5f05a08aff09af2f58e6976bf8ac87beb38498a0e3d98ba64eb18"},
]
[package.extras]
@ -1396,14 +1396,14 @@ typing-extensions = ">=4.0.0,<5.0.0"
[[package]]
name = "openpyxl"
version = "3.1.1"
version = "3.1.2"
description = "A Python library to read/write Excel 2010 xlsx/xlsm files"
category = "main"
optional = false
python-versions = ">=3.6"
files = [
{file = "openpyxl-3.1.1-py2.py3-none-any.whl", hash = "sha256:a0266e033e65f33ee697254b66116a5793c15fc92daf64711080000df4cfe0a8"},
{file = "openpyxl-3.1.1.tar.gz", hash = "sha256:f06d44e2c973781068bce5ecf860a09bcdb1c7f5ce1facd5e9aa82c92c93ae72"},
{file = "openpyxl-3.1.2-py2.py3-none-any.whl", hash = "sha256:f91456ead12ab3c6c2e9491cf33ba6d08357d802192379bb482f1033ade496f5"},
{file = "openpyxl-3.1.2.tar.gz", hash = "sha256:a6f5977418eff3b2d5500d54d9db50c8277a368436f4e4f8ddb1be3422870184"},
]
[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"
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"
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"
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"