Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Koishi 4.12 Iteration Plan #1000

Closed
23 of 24 tasks
shigma opened this issue Mar 2, 2023 · 6 comments
Closed
23 of 24 tasks

Koishi 4.12 Iteration Plan #1000

shigma opened this issue Mar 2, 2023 · 6 comments
Labels
plan future works

Comments

@shigma
Copy link
Member

shigma commented Mar 2, 2023

数据库更新

  • 数据结构变动
    • user 表中中的平台相关字段被移除,迁移到一个新的 binding 表中
    • 用户名改动:user.name -> user.nickname,同时新增 user.username 字段
  • 新的绑定 / 登录机制
    • 允许一个用户绑定同一平台下的多个账户
    • 绑定后初始数据被封存,解绑后自动恢复到封存数据
  • 修改目前的 ABC 插件 (auth / bind / callme),适配新特性
    • auth 插件增加 admin.enabled 配置项,默认开启
    • 如果启用,增加 admin.username / admin.password 配置项 (必选)

加载机制更新

  • @koishijs/plugin-hmr:负责目前的热重载功能
  • 增加 .env.local 支持:用于覆盖 .env 中的配置

Backlog

@shigma shigma pinned this issue Mar 2, 2023
@shigma shigma added the plan future works label Mar 2, 2023
@srk24
Copy link

srk24 commented Mar 3, 2023

目前session user相关id有点多,我一开始以为uid指的是主键id,但是后来发现uid指的是拿到的却是sandbox+sandbox.value,userId拿到的是sandbox.value,id拿到的是主键id。而且session.getUser()中使用的参数是sandbox.value,而不是主键id。这块东西后面也会一并处理吗?

@shigma
Copy link
Member Author

shigma commented Mar 3, 2023

Koishi 各种 ID 的用法介绍

首先我们区分一下两个基础概念:

  • 平台用户:指接入聊天平台的用户账户,例如 QQ 号 123456789 就是平台 QQ 上的用户 ID
  • Koishi 用户:指 Koishi 用户系统中的账户,可以绑定一个或多个平台用户

然后下面是会话对象上的各种 ID:

  • session.id: number 会话的唯一 ID
  • session.platform: string 会话的平台
  • session.userId: string 会话用户的平台 ID
  • session.uid: string 会话的平台+用户的平台 ID,可用于作为平台用户的唯一标识符
  • session.user.id: number 会话用户的 Koishi ID

如何请求用户数据

请求平台用户的数据:

ctx.database.getUser(platform, userId, fields)

请求 Koishi 用户的数据:

ctx.database.get('user', id, fields)

上面两种写法不能混用。

沙盒中的用户

沙盒被视为一个特殊的聊天平台,平台名为 sandbox,用户 ID 直接是 Alice

@srk24
Copy link

srk24 commented Mar 3, 2023

目前代码里面getUser()没有要填写platform吧?

 getUser<K extends User.Field = never>(id?: string, fields?: K[]): Promise<User>;

@shigma
Copy link
Member Author

shigma commented Mar 3, 2023

image

你从哪看到的 getUser 用法……

@srk24
Copy link

srk24 commented Mar 3, 2023

抱歉看错了,我用的是session.getUser()

@shigma
Copy link
Member Author

shigma commented Mar 3, 2023

session.getUser() 用法不受影响,相当于 database.getUser() 少了一个一参数。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plan future works
Projects
None yet
Development

No branches or pull requests

2 participants