Fix Matrix bot replying to old commands on program launch (fix #11)

This commit is contained in:
Noah 2024-03-11 17:43:24 -05:00
parent 818e95c33f
commit 841dda8f8f

View File

@ -64,6 +64,7 @@ func initMatrix() {
log.Printf("[Matrix] Logged in as %s", resp.UserID)
syncer := client.Syncer.(*mautrix.DefaultSyncer)
client.Syncer.(mautrix.ExtensibleSyncer).OnSync(client.DontProcessOldEvents)
syncer.OnEventType(event.StateMember, func(ctx context.Context, evt *event.Event) {
if evt.GetStateKey() == client.UserID.String() && evt.Content.AsMember().Membership == event.MembershipInvite {
if evt.RoomID.String() == configuration.matrix.room_id {
@ -140,9 +141,11 @@ func initMatrix() {
}
}()
log.Print("[Matrix] Running!")
err = client.Sync()
if err != nil {
log.Fatal(err)
}
go func() {
log.Print("[Matrix] Running!")
err = client.Sync()
if err != nil {
log.Fatal(err)
}
}()
}