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