1
0
Fork 0
mirror of https://codeberg.org/june64/mrvc.git synced 2026-01-09 15:52:53 +01:00
mrvc/main.go

53 lines
1.4 KiB
Go

package main
import (
"context"
"log"
"github.com/matrix-org/gomatrixserverlib/fclient"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/id"
"codeberg.org/june64/mrvc/config"
"codeberg.org/june64/mrvc/output"
"codeberg.org/june64/mrvc/roominfotree"
)
func main() {
config := config.Get()
userId := id.UserID(config.UserID)
_, homeserver, err := userId.ParseAndValidate()
if err != nil {
log.Println("Error while parsing and validating the given user ID. Please ensure it is valid.")
log.Fatal(err)
}
clientWellKnown, err := mautrix.DiscoverClientAPI(context.Background(), homeserver)
if err != nil {
log.Println("Error while trying to discover the homeservers client API URL from the given user ID. Please ensure it is valid and its homeserver is correctly configured.")
log.Fatal(err)
}
homeserverURL := clientWellKnown.Homeserver.BaseURL
client, err := mautrix.NewClient(
homeserverURL,
userId,
config.Token,
)
if err != nil {
log.Fatal(err)
}
federationClient := fclient.NewClient(
fclient.WithWellKnownSRVLookups(true),
fclient.WithTimeout(config.HomeserverVersionInfoTimeout),
)
roomInfoTree := roominfotree.Get(config.Rooms, config.Recursive, config.RecursionMaxDepth, config.RecursionSuggestedOnly, client, federationClient)
if config.JSON {
output.PrintJSON(roomInfoTree, config.OutputHomeserverMemberCount)
} else {
output.Print(roomInfoTree, config.OutputHomeserverMemberCount)
}
}