fix(core): default to group when no options.session
#196
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
对于
createMessage
API,判断在私聊还是群聊中发送是适配器的职责。在判断出私聊还是群聊后,适配器需要在MessageEncoder
的prepare()
方法中做如下五件事:this.session.isDirect
,该值在被适配器设置之前始终为默认值this.session.channel.type = this.session.isDirect ? Channel.Type.DIRECT : Channel.Type.TEXT
this.session.subtype = this.session.isDirect ? 'private' : 'group'
if (!this.session.isDirect) this.guildId = this.channelId
flush()
及同类方法中的实际消息发送逻辑,使其基于this.session.isDirect
判断需要调用的 APIadapter-onebot#8 是上面修改的一个完美示范。
对于本 PR,一般地,若
createMessage
请求没有来源 session,且适配器也不打算进行上述三项设置的情况下,我们认为此时应当默认发送群聊消息。这一结论根据目前的用户群体在私聊和群聊中使用该 API 的比例得出。本 PR 规范了这一行为。本 PR 是一个中间改动。在所有适配器均实现了上面所述的判断逻辑后,本 PR 中
send()
方法中isDirect
相关部分将会全部失效,届时将可以直接删除相关行。