koishijs / koishi

Cross-platform chatbot framework made with love
https://koishi.chat
MIT License
4.53k stars 246 forks source link

Bug: 当全局设置 autoAuthorize 为 0 时 一个不在数据库的用户执行命令 会报错 #1267

Closed 502647092 closed 1 year ago

502647092 commented 1 year ago

Describe the bug

当全局设置 autoAuthorize 为 0 时 一个不在数据库的用户执行命令 会报错

Steps to reproduce

设置 autoAuthorize 为 0 找一个数据库不存在的用户 执行任意命令

Expected behavior

正常运行

Screenshots

错误日志

2023-11-16 12:08:29 [W] app Error: user not found                                                                                                                                                                 
                            at Proxy.setUser (/home/project/TSWorkSpace/koishi/development/koishi-app/node_modules/@koishijs/core/src/database.ts:136:25)                                                         
                            at process.processTicksAndRejections (node:internal/process/task_queues:95:5)                                                                                                         
                            at _Processor._handleMessage (/home/project/TSWorkSpace/koishi/development/koishi-app/node_modules/@koishijs/core/src/middleware.ts:279:7)                                            

Versions

System: OS: Linux 5.10 Debian GNU/Linux 11 (bullseye) 11 (bullseye) CPU: (16) x64 Intel(R) Xeon(R) CPU E5-2696 v2 @ 2.50GHz

Binaries: Node: 20.9.0 Yarn: 1.22.19

Koishi: Core: 4.15.5 Console: 5.18.5

Additional context

No response

maxoyed commented 1 year ago

最低权限是1,我之前也手动设置0,其实用1就没事了

Hieuzest commented 1 year ago

https://github.com/koishijs/koishi/blob/8a2d13db98c2b34a0d5f3f129183e5399423504d/packages/core/src/session.ts#L273

Shoule be like

cache = observe(data, diff => (data as any).$detached || this.app.database.setUser(this.platform, userId, diff as any), `user ${this.uid}`)