Merge branch 'CMHopeSunshine:Bot' into Bot

This commit is contained in:
Mmx 2023-04-01 10:01:52 +08:00 committed by GitHub
commit 99a4f60b5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 127 additions and 5 deletions

View File

@ -306,6 +306,7 @@ class Character(Model):
character.character_id = data['avatarId']
character.level = int(data['propMap']['4001']['val'])
character.fetter = data['fetterInfo']['expLevel']
character.promote_level = int(data['propMap']['1002'].get('val', 0))
if name in ['', '']:
character.region = '未知'
character.rarity = 5

View File

@ -33,7 +33,7 @@ __plugin_meta__ = PluginMetadata(
}
)
ysb = on_command('ysb', aliases={'原神绑定', '绑定uid'}, priority=1, block=True, state={
ysb = on_command('ysb', aliases={'原神绑定', '绑定uid', '绑定UID'}, priority=1, block=True, state={
'pm_name': 'ysb',
'pm_description': '绑定原神uid或者cookie',
'pm_usage': 'ysb[uid|cookie]',
@ -78,6 +78,53 @@ refresh_ck = on_command('刷新ck', aliases={'刷新cookie'}, priority=1, block=
'pm_usage': '刷新ck',
'pm_priority': 7
})
ysch = on_command('ysch', aliases={'原神切换', '切换uid', '切换UID'}, priority=1, block=True, state={
'pm_name': 'ysch',
'pm_description': '切换当前绑定的UID至下一个或指定序号的UID',
'pm_usage': 'ysch[序号]',
'pm_priority': 8
})
@ysch.handle()
async def _(event: MessageEvent, msg: Message = CommandArg()):
if not (cookie_list := await PrivateCookie.filter(user_id=str(event.user_id))):
await ysch.finish(f'你还没有绑定过Cookie的UID如需绑定cookie可看教程\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1',
at_sender=True)
if len(cookie_list) == 1:
await ysch.finish(f'你只绑定了一个UID{cookie_list[0].uid},无需切换', at_sender=True)
uid_list = [i.uid for i in cookie_list]
uid_list_text = '\n'.join([f'{uid_list.index(i) + 1}.{i}' for i in uid_list])
msg = msg.extract_plain_text().strip()
if msg.isdigit():
# 如果指令后面跟了数字序号就切换到对应序号的UID
num = int(msg)
if len(cookie_list) >= num:
await LastQuery.update_or_create(user_id=str(event.user_id),
defaults={'uid': cookie_list[num - 1].uid,
'last_time': datetime.datetime.now()})
await ysch.finish(f'当前已切换至UID{cookie_list[num - 1].uid}\n\n已绑定的UID有{uid_list_text}\n可使用[切换uid 序号]来切换至指定UID',
at_sender=True)
else:
await ysch.finish(
f'你没有绑定那么多UID哦\n已绑定的UID有{uid_list_text}\n可使用[切换uid 序号]来切换至指定UID',
at_sender=True)
else:
cache_uid = await LastQuery.get_or_none(user_id=str(event.user_id))
if cache_uid and cache_uid.uid in uid_list:
index = uid_list.index(cache_uid.uid)
if index == len(uid_list) - 1:
# 如果当前UID是最后一个那么切换至第一个
index = 0
else:
# 否则切换至下一个
index += 1
current_uid = cookie_list[index].uid
else:
current_uid = cookie_list[0].uid
await LastQuery.update_or_create(user_id=str(event.user_id),
defaults={'uid': current_uid, 'last_time': datetime.datetime.now()})
await ysch.finish(f'当前已切换至UID{current_uid}\n\n已绑定的UID有{uid_list_text}\n可使用[切换uid 序号]来切换至指定UID', at_sender=True)
@ysb.handle()
@ -346,4 +393,3 @@ async def _(event: MessageEvent):
await refresh_ck.finish(f'成功刷新米游社ID为{"".join(refresh_done)}的账号的cookie', at_sender=True)
else:
await refresh_ck.finish('你还未绑定私人cookie或过期太久已被移除请重新绑定', at_sender=True)

View File

@ -1,16 +1,20 @@
import time
from typing import Union
from asyncio import get_running_loop
from urllib.parse import quote
from nonebot import on_command
from nonebot.adapters.onebot.v11 import (
Bot,
MessageEvent,
GroupMessageEvent,
PrivateMessageEvent,
PrivateMessageEvent, ActionFailed,
)
from nonebot.plugin import PluginMetadata
from LittlePaimon.utils import logger
from LittlePaimon.utils.message import CommandPlayer
from LittlePaimon.utils import logger, NICKNAME
from LittlePaimon.utils.message import CommandPlayer, CommandUID
from LittlePaimon.utils.api import get_authkey_by_stoken
from .data_source import (
get_gacha_log_img,
get_gacha_log_data,
@ -78,6 +82,18 @@ export_log = on_command(
'pm_priority': 4,
},
)
gacha_url = on_command(
'查看抽卡记录链接',
aliases={'导出抽卡记录链接'},
priority=11,
block=True,
state={
'pm_name': '查看抽卡记录链接',
'pm_description': '*获取你的抽卡记录链接',
'pm_usage': '查看抽卡记录链接(uid)',
'pm_priority': 5,
},
)
running_update = []
running_show = []
@ -153,3 +169,62 @@ async def _(
)
except Exception as e:
await export_log.finish(f'上传文件失败,错误信息:{e}', at_sender=True)
@gacha_url.handle()
async def _(
bot: Bot,
event: MessageEvent,
uid: str = CommandUID()
):
await gacha_url.send("正在获取抽卡记录链接")
logger.info('获取抽卡记录链接', '开始执行')
authkey, state, _ = await get_authkey_by_stoken(str(event.user_id), uid)
if not state:
return authkey
if authkey == {}:
await gacha_url.finish(authkey, at_sender=True)
region = 'cn_qd01' if uid[0] == '5' else 'cn_gf01'
url = (
f"https://hk4e-api.mihoyo.com/event/gacha_info/api/getGachaLog?"
f"authkey_ver=1&sign_type=2&auth_appid=webview_gacha&init_type=301&"
f"gacha_id=fecafa7b6560db5f3182222395d88aaa6aaac1bc"
f"&timestamp={int(time.time())}"
f"&lang=zh-cn&device_type=mobile&plat_type=ios&region={region}"
f"&authkey={quote(authkey,'utf-8')}"
f"&game_biz=hk4e_cn&gacha_type=301&page=1&size=5&end_id=0"
)
msgs = [
{
"type": "node",
"data": {
"name": NICKNAME,
"uin": event.self_id,
"content": f"UID{uid}的抽卡记录链接为:",
},
},
{
"type": "node",
"data": {"name": NICKNAME, "uin": event.self_id, "content": url},
},
]
try:
if isinstance(event, PrivateMessageEvent):
msg = await bot.call_api(
"send_private_forward_msg", user_id=event.user_id, messages=msgs
)
else:
msg = await bot.call_api(
"send_group_forward_msg", group_id=event.group_id, messages=msgs
)
loop = get_running_loop()
loop.call_later(85,
lambda: loop.create_task(bot.delete_msg(message_id=msg['message_id'])))
except ActionFailed:
logger.info('抽卡记录', '➤抽卡记录链接合并转发<r>发送失败</r>,尝试以普通信息发送')
try:
await gacha_url.finish(f"UID{uid}的抽卡记录链接为:\n{url}")
except ActionFailed as e:
logger.info('抽卡记录', f'➤抽卡记录链接<r>发送失败</r>{e}')
except Exception as e:
logger.info('抽卡记录', f'➤抽卡记录链接<r>发送失败</r>,报错信息:{e}')