2018-06-13 18:41:05 -04:00
|
|
|
// maubot - A plugin-based Matrix bot system written in Go.
|
|
|
|
// Copyright (C) 2018 Tulir Asokan
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package maubot
|
|
|
|
|
2018-09-19 18:16:13 -04:00
|
|
|
import (
|
|
|
|
"maunium.net/go/gomatrix"
|
2018-06-14 04:11:24 -04:00
|
|
|
)
|
|
|
|
|
2018-06-14 13:21:44 -04:00
|
|
|
type EventHandler func(*Event) EventHandlerResult
|
2018-06-20 15:25:33 -04:00
|
|
|
type EventHandlerResult int
|
|
|
|
type CommandHandlerResult = EventHandlerResult
|
2018-06-14 13:21:44 -04:00
|
|
|
|
|
|
|
const (
|
2018-09-19 18:16:13 -04:00
|
|
|
Continue EventHandlerResult = iota
|
2018-06-20 15:25:33 -04:00
|
|
|
StopEventPropagation
|
|
|
|
StopCommandPropagation CommandHandlerResult = iota
|
2018-06-14 13:21:44 -04:00
|
|
|
)
|
2018-06-14 04:11:24 -04:00
|
|
|
|
|
|
|
type MatrixClient interface {
|
2018-09-19 18:16:13 -04:00
|
|
|
AddEventHandler(gomatrix.EventType, EventHandler)
|
2018-06-18 18:25:47 -04:00
|
|
|
AddCommandHandler(string, CommandHandler)
|
|
|
|
SetCommandSpec(*CommandSpec)
|
2018-06-14 06:36:53 -04:00
|
|
|
GetEvent(string, string) *Event
|
2018-06-14 04:11:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type EventFuncs interface {
|
2018-06-14 06:36:53 -04:00
|
|
|
MarkRead() error
|
2018-06-14 04:11:24 -04:00
|
|
|
Reply(string) (string, error)
|
2018-09-19 18:16:13 -04:00
|
|
|
ReplyContent(gomatrix.Content) (string, error)
|
2018-06-14 04:11:24 -04:00
|
|
|
SendMessage(string) (string, error)
|
2018-09-19 18:16:13 -04:00
|
|
|
SendContent(gomatrix.Content) (string, error)
|
|
|
|
SendRawEvent(gomatrix.EventType, interface{}) (string, error)
|
2018-06-14 04:11:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type Event struct {
|
|
|
|
EventFuncs
|
2018-09-19 18:16:13 -04:00
|
|
|
*gomatrix.Event
|
2018-06-13 18:41:05 -04:00
|
|
|
}
|