Add command to login with token
This commit is contained in:
35
commands.go
35
commands.go
@@ -42,7 +42,8 @@ type WrappedCommandEvent struct {
|
|||||||
func (br *DiscordBridge) RegisterCommands() {
|
func (br *DiscordBridge) RegisterCommands() {
|
||||||
proc := br.CommandProcessor.(*commands.Processor)
|
proc := br.CommandProcessor.(*commands.Processor)
|
||||||
proc.AddHandlers(
|
proc.AddHandlers(
|
||||||
cmdLogin,
|
cmdLoginToken,
|
||||||
|
cmdLoginQR,
|
||||||
cmdLogout,
|
cmdLogout,
|
||||||
cmdReconnect,
|
cmdReconnect,
|
||||||
cmdDisconnect,
|
cmdDisconnect,
|
||||||
@@ -64,16 +65,40 @@ func wrapCommand(handler func(*WrappedCommandEvent)) func(*commands.Event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdLogin = &commands.FullHandler{
|
var cmdLoginToken = &commands.FullHandler{
|
||||||
Func: wrapCommand(fnLogin),
|
Func: wrapCommand(fnLoginToken),
|
||||||
Name: "login",
|
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{
|
Help: commands.HelpMeta{
|
||||||
Section: commands.HelpSectionAuth,
|
Section: commands.HelpSectionAuth,
|
||||||
Description: "Link the bridge to your Discord account by scanning a QR code.",
|
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() {
|
if ce.User.IsLoggedIn() {
|
||||||
ce.Reply("You're already logged in")
|
ce.Reply("You're already logged in")
|
||||||
return
|
return
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -12,7 +12,7 @@ require (
|
|||||||
github.com/stretchr/testify v1.8.0
|
github.com/stretchr/testify v1.8.0
|
||||||
github.com/yuin/goldmark v1.4.13
|
github.com/yuin/goldmark v1.4.13
|
||||||
maunium.net/go/maulogger/v2 v2.3.2
|
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 (
|
require (
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -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/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 h1:1XmIYmMd3PoQfp9J+PaHhpt80zpfmMqaShzUTC7FwY0=
|
||||||
maunium.net/go/maulogger/v2 v2.3.2/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
|
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.2-0.20220919211529-34e3589a5d5e h1:NkB/p2VTBiF+kis+JhOYKKyAgE0KH7kN9744WETU9aA=
|
||||||
maunium.net/go/mautrix v0.12.1/go.mod h1:/jxQFIipObSsjZPH6o3xyUi8uoULz3Hfr/8p9loqpYE=
|
maunium.net/go/mautrix v0.12.2-0.20220919211529-34e3589a5d5e/go.mod h1:/jxQFIipObSsjZPH6o3xyUi8uoULz3Hfr/8p9loqpYE=
|
||||||
|
|||||||
Reference in New Issue
Block a user