@ -6,7 +6,7 @@ import (
"time"
"github.com/gomarkdown/markdown"
gomatrix "maunium.net/go/mautrix"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/crypto"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
@ -15,7 +15,7 @@ import (
type MatrixDaemon struct {
Stopped bool
ShutdownChannel chan string
bot * go matrix. Client
bot * mau trix. Client
userID id . UserID
tokens map [ string ] UnverifiedUser // Map of tokens to users
languages map [ id . RoomID ] string // Map of roomIDs to language codes
@ -40,9 +40,9 @@ type MatrixUser struct {
Contact bool
}
var matrixFilter = go matrix. Filter {
Room : go matrix. RoomFilter {
Timeline : go matrix. FilterPart {
var matrixFilter = mau trix. Filter {
Room : mau trix. RoomFilter {
Timeline : mau trix. FilterPart {
Types : [ ] event . Type {
event . EventMessage ,
event . EventEncrypted ,
@ -76,7 +76,7 @@ func newMatrixDaemon(app *appContext) (d *MatrixDaemon, err error) {
app : app ,
start : time . Now ( ) . UnixNano ( ) / 1e6 ,
}
d . bot , err = go matrix. NewClient ( homeserver , d . userID , token )
d . bot , err = mau trix. NewClient ( homeserver , d . userID , token )
if err != nil {
return
}
@ -96,16 +96,16 @@ func newMatrixDaemon(app *appContext) (d *MatrixDaemon, err error) {
}
func ( d * MatrixDaemon ) generateAccessToken ( homeserver , username , password string ) ( string , error ) {
req := & go matrix. ReqLogin {
Type : go matrix. AuthTypePassword ,
Identifier : go matrix. UserIdentifier {
Type : go matrix. IdentifierTypeUser ,
req := & mau trix. ReqLogin {
Type : mau trix. AuthTypePassword ,
Identifier : mau trix. UserIdentifier {
Type : mau trix. IdentifierTypeUser ,
User : username ,
} ,
Password : password ,
DeviceID : id . DeviceID ( "jfa-go-" + commit ) ,
}
bot , err := go matrix. NewClient ( homeserver , id . UserID ( username ) , "" )
bot , err := mau trix. NewClient ( homeserver , id . UserID ( username ) , "" )
if err != nil {
return "" , err
}
@ -119,7 +119,7 @@ func (d *MatrixDaemon) generateAccessToken(homeserver, username, password string
func ( d * MatrixDaemon ) run ( ) {
startTime := d . start
d . app . info . Println ( "Starting Matrix bot daemon" )
syncer := d . bot . Syncer . ( * go matrix. DefaultSyncer )
syncer := d . bot . Syncer . ( * mau trix. DefaultSyncer )
HandleSyncerCrypto ( startTime , d , syncer )
syncer . OnEventType ( event . EventMessage , d . handleMessage )
@ -135,7 +135,7 @@ func (d *MatrixDaemon) Shutdown() {
close ( d . ShutdownChannel )
}
func ( d * MatrixDaemon ) handleMessage ( source go matrix. EventSource , evt * event . Event ) {
func ( d * MatrixDaemon ) handleMessage ( source mau trix. EventSource , evt * event . Event ) {
if evt . Timestamp < d . start {
return
}
@ -189,8 +189,8 @@ func (d *MatrixDaemon) commandLang(evt *event.Event, code, lang string) {
}
func ( d * MatrixDaemon ) CreateRoom ( userID string ) ( roomID id . RoomID , encrypted bool , err error ) {
var room * go matrix. RespCreateRoom
room , err = d . bot . CreateRoom ( & go matrix. ReqCreateRoom {
var room * mau trix. RespCreateRoom
room , err = d . bot . CreateRoom ( & mau trix. ReqCreateRoom {
Visibility : "private" ,
Invite : [ ] id . UserID { id . UserID ( userID ) } ,
Topic : d . app . config . Section ( "matrix" ) . Key ( "topic" ) . String ( ) ,
@ -221,7 +221,7 @@ func (d *MatrixDaemon) SendStart(userID string) (ok bool) {
Encrypted : encrypted ,
} ,
}
err = d . send (
err = d . send ToRoom (
& event . MessageEventContent {
MsgType : event . MsgText ,
Body : d . app . storage . lang . Telegram [ lang ] . Strings . get ( "matrixStartMessage" ) + "\n\n" + pin + "\n\n" +
@ -237,18 +237,20 @@ func (d *MatrixDaemon) SendStart(userID string) (ok bool) {
return
}
func ( d * MatrixDaemon ) send ( content * event . MessageEventContent , roomID id . RoomID ) ( err error ) {
func ( d * MatrixDaemon ) send ToRoom ( content * event . MessageEventContent , roomID id . RoomID ) ( err error ) {
if encrypted , ok := d . isEncrypted [ roomID ] ; ok && encrypted {
err = SendEncrypted ( d , content , roomID )
} else {
_ , err = d . bot . SendMessageEvent ( roomID , event . NewEventType ( "m.room.message" ) , content , gomatrix . ReqSendEvent { } )
}
if err != nil {
return
_ , err = d . bot . SendMessageEvent ( roomID , event . EventMessage , content , mautrix . ReqSendEvent { } )
}
return
}
func ( d * MatrixDaemon ) send ( content * event . MessageEventContent , roomID id . RoomID ) ( err error ) {
_ , err = d . bot . SendMessageEvent ( roomID , event . EventMessage , content , mautrix . ReqSendEvent { } )
return
}
func ( d * MatrixDaemon ) Send ( message * Message , users ... MatrixUser ) ( err error ) {
md := ""
if message . Markdown != "" {
@ -264,11 +266,7 @@ func (d *MatrixDaemon) Send(message *Message, users ...MatrixUser) (err error) {
content . Format = "org.matrix.custom.html"
}
for _ , user := range users {
if user . Encrypted {
err = SendEncrypted ( d , content , id . RoomID ( user . RoomID ) )
} else {
err = d . send ( content , id . RoomID ( user . RoomID ) )
}
err = d . sendToRoom ( content , id . RoomID ( user . RoomID ) )
if err != nil {
return
}