mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-10-21 16:27:15 +08:00
🎨 可指定序号快速切换UID
This commit is contained in:
parent
1d12588478
commit
eba4eec2ab
@ -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_name': 'ysb',
|
||||||
'pm_description': '绑定原神uid或者cookie',
|
'pm_description': '绑定原神uid或者cookie',
|
||||||
'pm_usage': 'ysb[uid|cookie]',
|
'pm_usage': 'ysb[uid|cookie]',
|
||||||
@ -78,32 +78,54 @@ refresh_ck = on_command('刷新ck', aliases={'刷新cookie'}, priority=1, block=
|
|||||||
'pm_usage': '刷新ck',
|
'pm_usage': '刷新ck',
|
||||||
'pm_priority': 7
|
'pm_priority': 7
|
||||||
})
|
})
|
||||||
ysch = on_command('ysch', aliases={'原神切换', '切换uid'}, priority=1, block=True, state={
|
ysch = on_command('ysch', aliases={'原神切换', '切换uid', '切换UID'}, priority=1, block=True, state={
|
||||||
'pm_name': 'ysch',
|
'pm_name': 'ysch',
|
||||||
'pm_description': '切换绑定Cookie的其他UID',
|
'pm_description': '切换当前绑定的UID至下一个或指定序号的UID',
|
||||||
'pm_usage': 'ysch',
|
'pm_usage': 'ysch[序号]',
|
||||||
'pm_priority': 1
|
'pm_priority': 8
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ysch.handle()
|
@ysch.handle()
|
||||||
async def _(event: MessageEvent, msg: Message = CommandArg()):
|
async def _(event: MessageEvent, msg: Message = CommandArg()):
|
||||||
user_id = event.user_id
|
if not (cookie_list := await PrivateCookie.filter(user_id=str(event.user_id))):
|
||||||
cookie_list = await PrivateCookie.filter(user_id=event.user_id)
|
await ysch.finish(f'你还没有绑定过Cookie的UID,如需绑定cookie可看教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1',
|
||||||
cache_uid = await LastQuery.get_or_none(user_id=user_id)
|
at_sender=True)
|
||||||
|
if len(cookie_list) == 1:
|
||||||
if not cookie_list:
|
await ysch.finish(f'你只绑定了一个UID{cookie_list[0].uid},无需切换', at_sender=True)
|
||||||
ysch.finish(f'你还没有绑定Cookie,如需绑定cookie可看教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1')
|
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])
|
||||||
uids = [i.uid for i in cookie_list]
|
msg = msg.extract_plain_text().strip()
|
||||||
current_uid = uids[0]
|
if msg.isdigit():
|
||||||
if len(cookie_list)>1 and cache_uid and (cache_uid.uid in uids):
|
# 如果指令后面跟了数字序号,就切换到对应序号的UID
|
||||||
for idx,uid in enumerate(uids):
|
num = int(msg)
|
||||||
if uid == cache_uid.uid:
|
if len(cookie_list) >= num:
|
||||||
current_uid = uids[(idx+1)%len(uids)]
|
await LastQuery.update_or_create(user_id=str(event.user_id),
|
||||||
break
|
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),
|
await LastQuery.update_or_create(user_id=str(event.user_id),
|
||||||
defaults={'uid': current_uid, 'last_time': datetime.datetime.now()})
|
defaults={'uid': current_uid, 'last_time': datetime.datetime.now()})
|
||||||
ysch.finish(f'当前UID切换为:{current_uid}\n当前绑定的UID列表为[{",".join(uids)}] ')
|
await ysch.finish(f'当前已切换至UID{current_uid}\n\n已绑定的UID有:{uid_list_text}\n可使用[切换uid 序号]来切换至指定UID', at_sender=True)
|
||||||
|
|
||||||
|
|
||||||
@ysb.handle()
|
@ysb.handle()
|
||||||
async def _(event: MessageEvent, msg: Message = CommandArg()):
|
async def _(event: MessageEvent, msg: Message = CommandArg()):
|
||||||
@ -371,4 +393,3 @@ async def _(event: MessageEvent):
|
|||||||
await refresh_ck.finish(f'成功刷新米游社ID为{"、".join(refresh_done)}的账号的cookie', at_sender=True)
|
await refresh_ck.finish(f'成功刷新米游社ID为{"、".join(refresh_done)}的账号的cookie', at_sender=True)
|
||||||
else:
|
else:
|
||||||
await refresh_ck.finish('你还未绑定私人cookie或过期太久已被移除,请重新绑定', at_sender=True)
|
await refresh_ck.finish('你还未绑定私人cookie或过期太久已被移除,请重新绑定', at_sender=True)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user