Skip to content

Commit

Permalink
perf: 优化扫码登录
Browse files Browse the repository at this point in the history
  • Loading branch information
XasYer committed Dec 23, 2024
1 parent b9a6dd7 commit c6009fc
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions apps/QRLogin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const rule = {
QRLoginTips: {
reg: App.getReg(baseReg),
fnc: async (e) => {
const tips = '将使用steamApp扫码二维码进行登录, 登录完成后机器人可获得对应账号的access_token并保存, 不会同时绑定对应的steamId, 拥有access_token后可执行各种隐私操作, 请在**特别信任**的机器人上进行扫码登录, 如果确认需要扫码登录, 请继续发送\n#steam确认扫码登录'
const tips = '将使用steamApp扫码二维码进行登录, 登录完成后机器人可获得对应账号的access_token并保存, 不会同时绑定对应的steamId, 拥有access_token后可执行各种隐私操作, 请在**特别信任**的机器人上进行扫码登录, 如果确认需要扫码登录, 请先打开steamApp进入扫码界面并继续发送\n#steam确认扫码登录'
await e.reply(tips)
verify[e.user_id] = true
return true
Expand All @@ -24,20 +24,23 @@ const rule = {
reg: App.getReg(`确认${baseReg}`),
fnc: async (e) => {
if (!verify[e.user_id]) return true
delete verify[e.user_id]
const session = await api.IAuthenticationService.BeginAuthSessionViaQR()
const qrcode = (await QRCode.toDataURL(session.challenge_url)).replace('data:image/png;base64,', 'base64://')
await e.reply(['请使用30秒内使用steamApp扫描二维码进行登录', segment.image(qrcode)])
await App.reply(e, ['请使用30秒内使用steamApp扫描二维码进行登录', segment.image(qrcode)], {
recallMsg: 30,
quote: true
})
for (let i = 0; i < 6; i++) {
await new Promise(resolve => setTimeout(resolve, 1000 * 5))
const qrcodeRes = await api.IAuthenticationService.PollAuthSessionStatus(session.client_id, session.request_id)
const qrcodeRes = await api.IAuthenticationService.PollAuthSessionStatus(session.client_id, session.request_id).catch(() => {})
if (qrcodeRes.access_token) {
const dbRes = await db.TokenTableAddData(e.user_id, qrcodeRes.access_token, qrcodeRes.refresh_token)
console.log(dbRes)
await e.reply(`登录成功\nsteamId: ${dbRes.steamId}\n登录名: ${qrcodeRes.account_name.replace(/^(.)(.*)(.)$/, '$1***$3')}`)
break
await e.reply(`登录成功\nsteamId: ${dbRes.steamId}\n登录名: ${qrcodeRes.account_name.replace(/^(.)(.*)(.)$/, '$1***$3')}\n需要切换到对应的steamId才会生效`)
return true
}
}
await e.reply('登录超时~请重新触发指令')
return true
}
}
}
Expand Down

0 comments on commit c6009fc

Please sign in to comment.