mirror of
https://github.com/maubot/maubot
synced 2025-08-29 19:00:39 +00:00
Add command spec parsing/handler execution
This commit is contained in:
parent
307a32e0c0
commit
4536fcfe62
9 changed files with 282 additions and 37 deletions
24
commands.go
24
commands.go
|
@ -16,15 +16,31 @@
|
|||
|
||||
package maubot
|
||||
|
||||
type CommandHandler func(*Event)
|
||||
type CommandHandler func(*Event) CommandHandlerResult
|
||||
|
||||
type CommandSpec struct {
|
||||
Commands []Command `json:"commands"`
|
||||
PassiveCommands []PassiveCommand `json:"passive_commands"`
|
||||
Commands []Command `json:"commands,omitempty"`
|
||||
PassiveCommands []PassiveCommand `json:"passive_commands,omitempty"`
|
||||
}
|
||||
|
||||
func (spec *CommandSpec) Clone() *CommandSpec {
|
||||
return &CommandSpec{
|
||||
Commands: append([]Command(nil), spec.Commands...),
|
||||
PassiveCommands: append([]PassiveCommand(nil), spec.PassiveCommands...),
|
||||
}
|
||||
}
|
||||
|
||||
func (spec *CommandSpec) Merge(otherSpecs ...*CommandSpec) {
|
||||
for _, otherSpec := range otherSpecs {
|
||||
spec.Commands = append(spec.Commands, otherSpec.Commands...)
|
||||
spec.PassiveCommands = append(spec.PassiveCommands, otherSpec.PassiveCommands...)
|
||||
}
|
||||
}
|
||||
|
||||
func (spec *CommandSpec) Equals(otherSpec *CommandSpec) bool {
|
||||
if len(spec.Commands) != len(otherSpec.Commands) || len(spec.PassiveCommands) != len(otherSpec.PassiveCommands) {
|
||||
if otherSpec == nil ||
|
||||
len(spec.Commands) != len(otherSpec.Commands) ||
|
||||
len(spec.PassiveCommands) != len(otherSpec.PassiveCommands) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue