Skip to content

Commit

Permalink
Breaking change for onCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoii committed Apr 12, 2020
1 parent 6098389 commit 3b12f74
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1246,17 +1246,17 @@ Content-Type:multipart/form-data
```json5
{
"name": "commandName",
"friend": 12345,
"sender": 12345,
"group": 54321,
"args": ["arg1", "arg2"]
}
```

> 当指令通过好友消息发送时,friend为好友QQ好,group为0
> 当指令通过好友消息发送时,sender为好友QQ号,group为0
>
> 当指令通过群组消息发送时,friend为0,group为群号
> 当指令通过群组消息发送时,sender为发送人QQ号,group为群号
>
> 当指令通过其他方式发送时,如控制台、HTTP接口等,friend和group均为0
> 当指令通过其他方式发送时,如控制台、HTTP接口等,sender和group均为0


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,14 @@ object HttpApiPluginBase: PluginBase() {

override fun onCommand(command: Command, sender: CommandSender, args: List<String>) {
launch {
val (friend: Long, group: Long) = when(sender) {
is ContactCommandSender -> when(sender.contact) {
is Group -> 0L to sender.contact.id
is QQ -> sender.contact.id to 0L
else -> 0L to 0L // assert unreachable
}
val (from: Long, group: Long) = when(sender) {
is GroupContactCommandSender -> sender.realSender.id to sender.contact.id
is ContactCommandSender -> sender.contact.id to 0L
else -> 0L to 0L // 考虑保留对其他Sender类型的扩展,先统一默认为ConsoleSender
}

subscribers.forEach {
it(command.name, friend, group, args)
it(command.name, from, group, args)
}
}
}
Expand Down

0 comments on commit 3b12f74

Please sign in to comment.