username lowercase

This commit is contained in:
stryan 2022-07-17 15:53:20 -04:00
parent 1b677a2bbc
commit 3ce33e0185

View File

@ -3,6 +3,7 @@ package main
import (
"fmt"
"log"
"strings"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/id"
@ -12,6 +13,8 @@ func newMatrixClient(config *botConfig) *mautrix.Client {
fmt.Println("Logging into", config.Homeserver, "as", config.Username)
var client *mautrix.Client
var err error
//make sure username is lower case otherwise token login breaks
uname := strings.ToLower(config.Username)
if config.Token == "" {
client, err = mautrix.NewClient(config.Homeserver, "", "")
if err != nil {
@ -19,7 +22,7 @@ func newMatrixClient(config *botConfig) *mautrix.Client {
}
} else {
log.Println("using token login")
client, err = mautrix.NewClient(config.Homeserver, id.NewUserID(config.Username, config.Domain), config.Token)
client, err = mautrix.NewClient(config.Homeserver, id.NewUserID(uname, config.Domain), config.Token)
if err != nil {
panic(err)
}
@ -28,7 +31,7 @@ func newMatrixClient(config *botConfig) *mautrix.Client {
if config.Token == "" {
loginRes, err := client.Login(&mautrix.ReqLogin{
Type: "m.login.password",
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: config.Username},
Identifier: mautrix.UserIdentifier{Type: mautrix.IdentifierTypeUser, User: uname},
Password: config.Password,
StoreCredentials: true,
})