Add command to login with token

This commit is contained in:
Tulir Asokan
2022-09-20 00:17:22 +03:00
parent b8b2eef369
commit a1ff5fb61b
3 changed files with 33 additions and 8 deletions

View File

@@ -42,7 +42,8 @@ type WrappedCommandEvent struct {
func (br *DiscordBridge) RegisterCommands() {
proc := br.CommandProcessor.(*commands.Processor)
proc.AddHandlers(
cmdLogin,
cmdLoginToken,
cmdLoginQR,
cmdLogout,
cmdReconnect,
cmdDisconnect,
@@ -64,16 +65,40 @@ func wrapCommand(handler func(*WrappedCommandEvent)) func(*commands.Event) {
}
}
var cmdLogin = &commands.FullHandler{
Func: wrapCommand(fnLogin),
Name: "login",
var cmdLoginToken = &commands.FullHandler{
Func: wrapCommand(fnLoginToken),
Name: "login-token",
Help: commands.HelpMeta{
Section: commands.HelpSectionAuth,
Description: "Link the bridge to your Discord account by extracting the access token manually.",
},
}
func fnLoginToken(ce *WrappedCommandEvent) {
ce.MarkRead()
defer ce.Redact()
if ce.User.IsLoggedIn() {
ce.Reply("You're already logged in")
return
}
if err := ce.User.Login(ce.Args[0]); err != nil {
ce.Reply("Error connecting to Discord: %v", err)
return
}
ce.Reply("Successfully logged in as %s#%s", ce.User.Session.State.User.Username, ce.User.Session.State.User.Discriminator)
}
var cmdLoginQR = &commands.FullHandler{
Func: wrapCommand(fnLoginQR),
Name: "login-qr",
Aliases: []string{"login"},
Help: commands.HelpMeta{
Section: commands.HelpSectionAuth,
Description: "Link the bridge to your Discord account by scanning a QR code.",
},
}
func fnLogin(ce *WrappedCommandEvent) {
func fnLoginQR(ce *WrappedCommandEvent) {
if ce.User.IsLoggedIn() {
ce.Reply("You're already logged in")
return

2
go.mod
View File

@@ -12,7 +12,7 @@ require (
github.com/stretchr/testify v1.8.0
github.com/yuin/goldmark v1.4.13
maunium.net/go/maulogger/v2 v2.3.2
maunium.net/go/mautrix v0.12.1
maunium.net/go/mautrix v0.12.2-0.20220919211529-34e3589a5d5e
)
require (

4
go.sum
View File

@@ -66,5 +66,5 @@ maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
maunium.net/go/maulogger/v2 v2.3.2 h1:1XmIYmMd3PoQfp9J+PaHhpt80zpfmMqaShzUTC7FwY0=
maunium.net/go/maulogger/v2 v2.3.2/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
maunium.net/go/mautrix v0.12.1 h1:MLfkWkpRIgUn7lueDSlPwYOeIuGF+NrAHW0hInIuVAw=
maunium.net/go/mautrix v0.12.1/go.mod h1:/jxQFIipObSsjZPH6o3xyUi8uoULz3Hfr/8p9loqpYE=
maunium.net/go/mautrix v0.12.2-0.20220919211529-34e3589a5d5e h1:NkB/p2VTBiF+kis+JhOYKKyAgE0KH7kN9744WETU9aA=
maunium.net/go/mautrix v0.12.2-0.20220919211529-34e3589a5d5e/go.mod h1:/jxQFIipObSsjZPH6o3xyUi8uoULz3Hfr/8p9loqpYE=