新增留影叙佳期

This commit is contained in:
Wuyi无疑 2023-03-26 16:51:56 +08:00
parent 4bb2a9e88b
commit 019a968397
6 changed files with 203 additions and 1 deletions

View File

@ -0,0 +1,19 @@
from gsuid_core.sv import SV
from gsuid_core.bot import Bot
from gsuid_core.models import Event
from .get_draw import post_my_draw
from ..utils.database import get_sqla
from ..utils.error_reply import UID_HINT
sv_post_my_draw = SV('留影叙佳期')
# 群聊内 每月统计 功能
@sv_post_my_draw.on_fullmatch(('留影叙佳期'))
async def send_postdraw_data(bot: Bot, ev: Event):
sqla = get_sqla(ev.bot_id)
uid = await sqla.get_bind_uid(ev.user_id)
if uid is None:
return UID_HINT
await bot.send(await post_my_draw(uid))

View File

@ -0,0 +1,35 @@
from ..utils.mys_api import mys_api
from ..utils.error_reply import get_error
async def post_my_draw(uid) -> str:
bs_index = await mys_api.get_bs_index(uid)
calendar = await mys_api.get_draw_calendar(uid)
# 错误检查
if isinstance(bs_index, int):
return get_error(bs_index)
if isinstance(calendar, int):
return get_error(calendar)
im_list = []
for role in bs_index['role']:
if not role['is_partake']:
data = await mys_api.post_draw(uid, role['role_id'])
if isinstance(data, int):
im_list.append(get_error(data))
else:
retcode = data['retcode']
if retcode != 0:
message = (
data['message']
if 'message' in data
else f'错误码{retcode}'
)
im_list.append(message)
else:
im_list.append(f'UID{uid}成功获取{role["name"]}的画片!')
if im_list == []:
im_list.append(f'UID{uid}没有需要获取的画片了~')
return '\n'.join(im_list)

View File

@ -128,4 +128,10 @@ CreateOrderurl = f'{HK4_SDK_URL}/hk4e_cn/mdk/atropos/api/createOrder'
CheckOrderurl = f'{HK4_SDK_URL}/hk4e_cn/mdk/atropos/api/checkOrder'
PriceTierurl = f'{HK4_SDK_URL}/hk4e_cn/mdk/shopwindow/shopwindow/listPriceTier'
# 留影叙佳期
DRAW_BASE_URL = f'{HK4_URL}/event/birthdaystar/account'
CALENDAR_URL = f'{DRAW_BASE_URL}/calendar'
RECEIVE_URL = f'{DRAW_BASE_URL}/post_my_draw'
BS_INDEX_URL = f'{DRAW_BASE_URL}/index'
_API = locals()

View File

@ -717,3 +717,64 @@ class GcgAction(TypedDict):
rank_id: int
deck_recommend: str
card_wiki: str
# 留影叙佳期
class GsRoleBirthDay(TypedDict):
role_id: int
name: str
jump_tpye: str
jump_target: str
jump_start_time: str
jump_end_time: str
role_gender: int
take_picture: str
gal_xml: str
gal_resource: str
is_partake: bool
bgm: str
class BsIndex(TypedDict):
nick_name: str
uid: int
region: str
role: List[GsRoleBirthDay]
draw_notice: bool
CurrentTime: str
gender: int
is_show_remind: bool
class RolesCalendar(TypedDict):
calendar_role_infos: MonthlyRoleCalendar
is_pre: bool
is_next: bool
is_year_subscribe: bool
class RoleCalendar(TypedDict):
role_id: int
name: str
role_birthday: str
head_icon: str
is_subscribe: bool
MonthlyRoleCalendar = TypedDict(
'MonthlyRoleCalendar',
{
'1': List[RoleCalendar],
'2': List[RoleCalendar],
'3': List[RoleCalendar],
'4': List[RoleCalendar],
'5': List[RoleCalendar],
'6': List[RoleCalendar],
'7': List[RoleCalendar],
'8': List[RoleCalendar],
'9': List[RoleCalendar],
'10': List[RoleCalendar],
'11': List[RoleCalendar],
'12': List[RoleCalendar],
},
)

View File

@ -24,6 +24,7 @@ from .tools import (
generate_passport_ds,
)
from .models import (
BsIndex,
GcgInfo,
MysGame,
MysSign,
@ -43,6 +44,7 @@ from .models import (
DailyNoteData,
GameTokenInfo,
MysOrderCheck,
RolesCalendar,
CharDetailData,
CookieTokenInfo,
LoginTicketInfo,
@ -312,6 +314,81 @@ class MysApi:
data = cast(MonthlyAward, data['data'])
return data
async def get_draw_calendar(self, uid: str) -> Union[int, RolesCalendar]:
server_id = RECOGNIZE_SERVER.get(uid[0])
ck = await self.get_ck(uid, 'OWNER')
if ck is None:
return -51
hk4e_token = await self.get_hk4e_token(uid)
header = {}
header['Cookie'] = f'{ck};{hk4e_token}'
params = {
'lang': 'zh-cn',
'badge_uid': uid,
'badge_region': server_id,
'game_biz': 'hk4e_cn',
'activity_id': 20220301153521,
'year': 2023,
}
data = await self._mys_request(
_API['CALENDAR_URL'], 'GET', header, params
)
if isinstance(data, Dict):
return cast(RolesCalendar, data['data'])
return data
async def get_bs_index(self, uid: str) -> Union[int, BsIndex]:
server_id = RECOGNIZE_SERVER.get(uid[0])
ck = await self.get_ck(uid, 'OWNER')
if ck is None:
return -51
hk4e_token = await self.get_hk4e_token(uid)
header = {}
header['Cookie'] = f'{ck};{hk4e_token}'
data = await self._mys_request(
_API['BS_INDEX_URL'],
'GET',
header,
{
'lang': 'zh-cn',
'badge_uid': uid,
'badge_region': server_id,
'game_biz': 'hk4e_cn',
'activity_id': 20220301153521,
},
)
if isinstance(data, Dict):
return cast(BsIndex, data['data'])
return data
async def post_draw(self, uid: str, role_id: int) -> Union[int, Dict]:
server_id = RECOGNIZE_SERVER.get(uid[0])
ck = await self.get_ck(uid, 'OWNER')
if ck is None:
return -51
hk4e_token = await self.get_hk4e_token(uid)
header = {}
header['Cookie'] = f'{ck};{hk4e_token}'
data = await self._mys_request(
_API['RECEIVE_URL'],
'POST',
header,
{
'lang': 'zh-cn',
'badge_uid': uid,
'badge_region': server_id,
'game_biz': 'hk4e_cn',
'activity_id': 20220301153521,
},
{'role_id': role_id},
)
if isinstance(data, Dict):
return data
elif data == -512009:
return {'data': None, 'message': '这张画片已经被收录啦~', 'retcode': -512009}
else:
return -999
async def get_spiral_abyss_info(
self, uid: str, schedule_type='1', ck: Optional[str] = None
) -> Union[AbyssData, int]:

View File

@ -21,7 +21,9 @@ UPDATE_HINT = '''更新失败!更多错误信息请查看控制台...
def get_error(retcode: Union[int, str]) -> str:
if retcode == -51:
return CK_HINT
if retcode == 10001:
elif retcode == -100:
return '您的cookie已经失效, 请重新获取!'
elif retcode == 10001:
return '您的cookie已经失效, 请重新获取!'
elif retcode == 10101:
return '当前查询CK已超过每日30次上限!'
@ -33,6 +35,8 @@ def get_error(retcode: Union[int, str]) -> str:
return '请求体出错, 请检查具体实现代码...'
elif retcode == 10104:
return CK_HINT
elif retcode == -512009:
return '已经获取过该内容~!'
elif retcode == -201:
return '你的账号可能已被封禁, 请联系米游社客服...'
else: