Add command spec parsing/handler execution

This commit is contained in:
Tulir Asokan 2018-06-20 22:25:33 +03:00
parent 307a32e0c0
commit 4536fcfe62
9 changed files with 282 additions and 37 deletions

View file

@ -54,11 +54,13 @@ const (
const FormatHTML = "org.matrix.custom.html"
type EventHandler func(*Event) EventHandlerResult
type EventHandlerResult bool
type EventHandlerResult int
type CommandHandlerResult = EventHandlerResult
const (
Continue EventHandlerResult = false
StopPropagation EventHandlerResult = true
Continue EventHandlerResult = iota
StopEventPropagation
StopCommandPropagation CommandHandlerResult = iota
)
type MatrixClient interface {
@ -130,7 +132,8 @@ type Content struct {
Membership string `json:"membership,omitempty"`
RelatesTo RelatesTo `json:"m.relates_to,omitempty"`
Command MatchedCommand `json:"m.command,omitempty"`
RelatesTo RelatesTo `json:"m.relates_to,omitempty"`
}
func (content Content) Equals(otherContent *Content) bool {
@ -162,6 +165,12 @@ func (fi *FileInfo) Equals(otherFI *FileInfo) bool {
((fi.ThumbnailInfo != nil && fi.ThumbnailInfo.Equals(otherFI.ThumbnailInfo)) || otherFI.ThumbnailInfo == nil)
}
type MatchedCommand struct {
Target string `json:"target"`
Matched string `json:"matched"`
Arguments map[string]string `json:"arguments"`
}
type RelatesTo struct {
InReplyTo InReplyTo `json:"m.in_reply_to,omitempty"`
}