From aa24d1dc47103c1ad3bb3f29cd23229f289c68d7 Mon Sep 17 00:00:00 2001 From: wangyu Date: Tue, 28 Mar 2023 14:17:35 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20[=E5=88=87=E6=8D=A2UID?= =?UTF-8?q?]=20=E6=8C=87=E4=BB=A4,=20=E7=BB=B4=E6=8A=A4=E5=A4=9A=E8=B4=A6?= =?UTF-8?q?=E6=88=B7=E6=83=85=E5=86=B5,=20=E4=BB=8E=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E7=9A=84Cookie=E6=9F=A5=E6=89=BEUID=E5=B9=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=87=E6=8D=A2=E4=B8=8B=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=88=B0LastQuery=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/plugins/Paimon_Bind/__init__.py | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/LittlePaimon/plugins/Paimon_Bind/__init__.py b/LittlePaimon/plugins/Paimon_Bind/__init__.py index a049da9..ae4be88 100644 --- a/LittlePaimon/plugins/Paimon_Bind/__init__.py +++ b/LittlePaimon/plugins/Paimon_Bind/__init__.py @@ -78,7 +78,33 @@ refresh_ck = on_command('刷新ck', aliases={'刷新cookie'}, priority=1, block= 'pm_usage': '刷新ck', 'pm_priority': 7 }) +ysch = on_command('ysch', aliases={'原神切换', '切换uid'}, priority=1, block=True, state={ + 'pm_name': 'ysch', + 'pm_description': '切换绑定Cookie的其他UID', + 'pm_usage': 'ysch', + 'pm_priority': 1 +}) +@ysch.handle() +async def _(event: MessageEvent, msg: Message = CommandArg()): + user_id = event.user_id + cookie_list = await PrivateCookie.filter(user_id=event.user_id) + cache_uid = await LastQuery.get_or_none(user_id=user_id) + + if not cookie_list: + ysch.finish(f'你还没有绑定Cookie,如需绑定cookie可看教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1') + + uids = [i.uid for i in cookie_list] + current_uid = uids[0] + if len(cookie_list)>1 and cache_uid and (cache_uid.uid in uids): + current_uid = uids[0] + for idx,uid in enumerate(uids): + if uid == cache_uid.uid: + current_uid = uids[(idx+1)%len(uids)] + break + await LastQuery.update_or_create(user_id=str(event.user_id), + defaults={'uid': current_uid, 'last_time': datetime.datetime.now()}) + ysch.finish(f'当前UID切换为:{current_uid}\n当前绑定的UID列表为[{",".join(uids)}] ') @ysb.handle() async def _(event: MessageEvent, msg: Message = CommandArg()): From 1d125884786cca185508e742cce4b78834d5148b Mon Sep 17 00:00:00 2001 From: wangyu Date: Tue, 28 Mar 2023 14:32:36 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=BA=86=E6=97=A0?= =?UTF-8?q?=E6=95=88=E4=BB=A3=E7=A0=81=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/plugins/Paimon_Bind/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/LittlePaimon/plugins/Paimon_Bind/__init__.py b/LittlePaimon/plugins/Paimon_Bind/__init__.py index ae4be88..87aac65 100644 --- a/LittlePaimon/plugins/Paimon_Bind/__init__.py +++ b/LittlePaimon/plugins/Paimon_Bind/__init__.py @@ -97,7 +97,6 @@ async def _(event: MessageEvent, msg: Message = CommandArg()): uids = [i.uid for i in cookie_list] current_uid = uids[0] if len(cookie_list)>1 and cache_uid and (cache_uid.uid in uids): - current_uid = uids[0] for idx,uid in enumerate(uids): if uid == cache_uid.uid: current_uid = uids[(idx+1)%len(uids)] From eba4eec2ab3f96af9c518e80f36754c98ef7d128 Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Tue, 28 Mar 2023 15:03:39 +0800 Subject: [PATCH 3/3] =?UTF-8?q?:art:=20=E5=8F=AF=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E5=BA=8F=E5=8F=B7=E5=BF=AB=E9=80=9F=E5=88=87=E6=8D=A2UID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/plugins/Paimon_Bind/__init__.py | 65 +++++++++++++------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/LittlePaimon/plugins/Paimon_Bind/__init__.py b/LittlePaimon/plugins/Paimon_Bind/__init__.py index 87aac65..d9346ea 100644 --- a/LittlePaimon/plugins/Paimon_Bind/__init__.py +++ b/LittlePaimon/plugins/Paimon_Bind/__init__.py @@ -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,32 +78,54 @@ refresh_ck = on_command('刷新ck', aliases={'刷新cookie'}, priority=1, block= 'pm_usage': '刷新ck', '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_description': '切换绑定Cookie的其他UID', - 'pm_usage': 'ysch', - 'pm_priority': 1 + 'pm_description': '切换当前绑定的UID至下一个或指定序号的UID', + 'pm_usage': 'ysch[序号]', + 'pm_priority': 8 }) + @ysch.handle() async def _(event: MessageEvent, msg: Message = CommandArg()): - user_id = event.user_id - cookie_list = await PrivateCookie.filter(user_id=event.user_id) - cache_uid = await LastQuery.get_or_none(user_id=user_id) - - if not cookie_list: - ysch.finish(f'你还没有绑定Cookie,如需绑定cookie可看教程:\ndocs.qq.com/doc/DQ3JLWk1vQVllZ2Z1') - - uids = [i.uid for i in cookie_list] - current_uid = uids[0] - if len(cookie_list)>1 and cache_uid and (cache_uid.uid in uids): - for idx,uid in enumerate(uids): - if uid == cache_uid.uid: - current_uid = uids[(idx+1)%len(uids)] - break - await LastQuery.update_or_create(user_id=str(event.user_id), + 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()}) - 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() 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) else: await refresh_ck.finish('你还未绑定私人cookie或过期太久已被移除,请重新绑定', at_sender=True) -