Skip to content

Commit

Permalink
fix(common): remove user before bind, fix #152
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 15, 2021
1 parent 22dc774 commit de3baaa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions packages/plugin-common/src/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ export default function apply(ctx: Context, config: AdminConfig = {}) {
return token
}

async function bind(user: User.Observed<never>, platform: Platform, userId: string) {
await ctx.database.removeUser(platform, userId)
ctx.app._userCache[platform].set(userId, user)
user[platform] = userId as never
await user._update()
}

ctx.command('user/bind', '绑定到账号', { authority: 0 })
.action(({ session }) => {
const token = generate(session, +(session.subtype === 'group'))
Expand All @@ -268,9 +275,8 @@ export default function apply(ctx: Context, config: AdminConfig = {}) {
if (data[2] < 0) {
const sess = new Session(ctx.app, { ...session, platform: data[0], userId: data[1] })
const user = await sess.observeUser([session.platform])
user[session.platform] = session.userId as never
delete tokens[session.content]
await user._update()
await bind(user, session.platform, session.userId)
return session.send(template('bind.success'))
} else {
const user = await session.observeUser(['authority', data[0]])
Expand All @@ -281,8 +287,7 @@ export default function apply(ctx: Context, config: AdminConfig = {}) {
const token = generate(session, -1)
return session.send(template('bind.generated-2', token))
} else {
user[data[0] as any] = data[1]
await user._update()
await bind(user, data[0], data[1])
return session.send(template('bind.success'))
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-tools/src/baidu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function apply(ctx: Context, options: BaiduOptions = {}) {
}

ctx.command('tools/baidu <keyword>', '使用百度百科搜索')
.example('百度一下最终幻想14')
.example('百度一下 最终幻想14')
.shortcut('百度一下', { fuzzy: true, greedy: true })
.shortcut('百度', { fuzzy: true, greedy: true })
.action(async ({ session }, keyword) => {
Expand Down

0 comments on commit de3baaa

Please sign in to comment.