Skip to content

Commit

Permalink
feat(bind): edge case of same-user binding (#1319)
Browse files Browse the repository at this point in the history
Co-authored-by: Shigma <[email protected]>
  • Loading branch information
XxLittleCxX and shigma authored Dec 25, 2023
1 parent 0294c38 commit 0bbed71
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions plugins/common/bind/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ export function apply(ctx: Context, config: Config = {}) {
const token = session.stripped.content
const data = tokens[token]
if (!data) return next()
if (data[0] === session.platform && data[1] === session.userId) {
return session.text('commands.bind.messages.self-' + (data[2] < 0 ? '2' : '1'))
}
delete tokens[token]
if (data[2] < 0) {
const [binding] = await ctx.database.get('binding', { platform: data[0], pid: data[1] }, ['aid'])
Expand Down
2 changes: 2 additions & 0 deletions plugins/common/bind/src/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ commands.bind:
请在 5 分钟内使用你的账号在目标平台内向机器人发送以下文本:
{0}
注意:当前平台是你的原始平台,这里的用户数据将覆盖目标平台的数据。
self-1: 请前往原始平台输入。
self-2: 请前往目标平台输入。
success: 账号绑定成功!
remove-success: 账号解绑成功!
remove-original: 无法解除绑定:这是你的原始账号。
2 changes: 2 additions & 0 deletions plugins/common/bind/tests/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ describe('@koishijs/plugin-bind', () => {
await client1.shouldReply('name', 'foo')
await client2.shouldReply('name', 'bar')
await client1.shouldReply('bind', /^koishi\/000001$/m)
await client1.shouldReply('koishi/000001', '请前往原始平台输入。')
await client2.shouldReply('koishi/000001', /^koishi\/000002$/m)
await client2.shouldReply('koishi/000002', '请前往目标平台输入。')
await client1.shouldReply('koishi/000002', '账号绑定成功!')
await client1.shouldReply('name', 'bar')
await client2.shouldReply('name', 'bar')
Expand Down

0 comments on commit 0bbed71

Please sign in to comment.