Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions bridge/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,22 @@ const (

const ParentIDNotFound = "msg-parent-not-found"

//nolint: tagliatelle
type Message struct {
Text string `json:"text"`
Channel string `json:"channel"`
Username string `json:"username"`
UserID string `json:"userid"` // userid on the bridge
Avatar string `json:"avatar"`
Account string `json:"account"`
Event string `json:"event"`
Protocol string `json:"protocol"`
Gateway string `json:"gateway"`
ParentID string `json:"parent_id"`
Timestamp time.Time `json:"timestamp"`
ID string `json:"id"`
Extra map[string][]interface{}
Text string `json:"text"`
Channel string `json:"channel"`
Username string `json:"username"`
OriginalUsername string `json:"original_username"`
UserID string `json:"userid"` // userid on the bridge
Avatar string `json:"avatar"`
Account string `json:"account"`
Event string `json:"event"`
Protocol string `json:"protocol"`
Gateway string `json:"gateway"`
ParentID string `json:"parent_id"`
Timestamp time.Time `json:"timestamp"`
ID string `json:"id"`
Extra map[string][]interface{}
}

func (m Message) ParentNotFound() bool {
Expand Down Expand Up @@ -143,6 +145,10 @@ type Protocol struct {
ReplaceNicks [][]string // all protocols
RemoteNickFormat string // all protocols
RunCommands []string // IRC
UseAppService bool // matrix
AppServiceHost string // matrix
AppServicePort uint16 // matrix
AppServiceConfigPath string // matrix
Server string // IRC,mattermost,XMPP,discord,matrix
SessionFile string // msteams,whatsapp
ShowJoinPart bool // all protocols
Expand Down
54 changes: 54 additions & 0 deletions bridge/matrix/appservice.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package bmatrix

import (
"errors"

"maunium.net/go/mautrix/appservice"
"maunium.net/go/mautrix/event"
)

//nolint: wrapcheck
func (b *Bmatrix) startAppService() error {
appService := appservice.Create()

appService.HomeserverURL = b.mc.HomeserverURL.String()
_, homeServerDomain, _ := b.mc.UserID.Parse()
appService.HomeserverDomain = homeServerDomain
//nolint: exhaustivestruct
appService.Host = appservice.HostConfig{
Hostname: b.GetString("AppServiceHost"),
Port: uint16(b.GetInt("AppServicePort")),
}
appService.RegistrationPath = b.GetString("AppServiceConfigPath")

initSuccess, err := appService.Init()
if err != nil {
return err
} else if !initSuccess {
return errors.New("couldn't initialise the application service")
}

b.appService = appService

// TODO: detect service completion and rerun automatically
go b.appService.Start()
b.Log.Debug("appservice launched")

processor := appservice.NewEventProcessor(b.appService)
processor.On(event.EventMessage, func(ev *event.Event) {
b.handleEvent(originAppService, ev)
})
go processor.Start()
b.Log.Debug("appservice even dispatcher launched")

// handle service stopping/restarting
go func(b *Bmatrix, processor *appservice.EventProcessor) {
<-b.stop

b.appService.Stop()
processor.Stop()
b.stopAck <- struct{}{}
}(b, processor)

return nil
}
Loading