Basic login test making sure we logged in properly

This just adds a message handler and spits out the message in the log to verify
that the websocket did connect successfully.
This commit is contained in:
Gary Kramlich
2022-01-05 11:47:03 -06:00
parent 94104102d2
commit aa7059b1e3
3 changed files with 41 additions and 14 deletions

View File

@@ -16,14 +16,27 @@ type User struct {
MXID id.UserID
ID string
Discriminator string
Username string
ManagementRoom id.RoomID
Session *discordgo.Session
}
// Login is just used to create the session and update the database and should
// only be called by bridge.User.Login which will continue setting up event
// handlers.
func (u *User) Login(token string) error {
session, err := discordgo.New(token)
if err != nil {
return err
}
u.Session = session
u.Update()
return nil
}
func (u *User) Scan(row Scannable) *User {
var token sql.NullString
@@ -37,11 +50,8 @@ func (u *User) Scan(row Scannable) *User {
}
if token.Valid {
session, err := discordgo.New("Bearer " + token.String)
if err != nil {
u.log.Errorln("Failed to create discord session:", err)
} else {
u.Session = session
if err := u.Login(token.String); err != nil {
u.log.Errorln("Failed to login: ", err)
}
}