mirror of
https://github.com/maubot/maubot
synced 2025-08-29 15:40:37 +00:00
Separate plugin interface to reduce file size
This commit is contained in:
parent
d572522a96
commit
ef8fffaff8
9 changed files with 254 additions and 31 deletions
|
@ -18,6 +18,7 @@ package matrix
|
|||
|
||||
import (
|
||||
"maubot.xyz/database"
|
||||
"maubot.xyz/interfaces"
|
||||
"maunium.net/go/gomatrix"
|
||||
log "maunium.net/go/maulogger"
|
||||
)
|
||||
|
@ -39,22 +40,33 @@ func NewClient(db *database.MatrixClient) (*Client, error) {
|
|||
DB: db,
|
||||
}
|
||||
|
||||
client.Syncer = NewMaubotSyncer(client, client.Store)
|
||||
|
||||
client.AddEventHandler(gomatrix.StateMember, client.onJoin)
|
||||
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func (client *Client) AddEventHandler(evt string, handler gomatrix.OnEventListener) {
|
||||
client.Syncer.(*gomatrix.DefaultSyncer).OnEventType(evt, handler)
|
||||
func (client *Client) ParseEvent(evt *gomatrix.Event) *Event {
|
||||
return &Event{
|
||||
Client: client,
|
||||
Event: evt,
|
||||
}
|
||||
}
|
||||
|
||||
func (client *Client) onJoin(evt *gomatrix.Event) {
|
||||
if !client.DB.AutoJoinRooms || evt.StateKey == nil || *evt.StateKey != client.DB.UserID {
|
||||
return
|
||||
func (client *Client) AddEventHandler(evt string, handler interfaces.EventHandler) {
|
||||
client.Syncer.(*MaubotSyncer).OnEventType(evt, handler)
|
||||
}
|
||||
|
||||
func (client *Client) onJoin(evt *interfaces.Event) bool {
|
||||
if !client.DB.AutoJoinRooms || evt.StateKey != client.DB.UserID {
|
||||
return true
|
||||
}
|
||||
if membership, _ := evt.Content["membership"].(string); membership == "invite" {
|
||||
client.JoinRoom(evt.RoomID)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (client *Client) JoinRoom(roomID string) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue