diff --git a/commands.go b/commands.go index 83078fc..c5b9374 100644 --- a/commands.go +++ b/commands.go @@ -56,6 +56,7 @@ func (br *DiscordBridge) RegisterCommands() { cmdReconnect, cmdDisconnect, cmdSetRelay, + cmdUnsetRelay, cmdGuilds, cmdRejoinSpace, cmdDeleteAllPortals, @@ -465,6 +466,39 @@ func fnSetRelay(ce *WrappedCommandEvent) { ce.Reply("Saved webhook %s (%s) as portal relay webhook", webhookMeta.Name, portal.RelayWebhookID) } +var cmdUnsetRelay = &commands.FullHandler{ + Func: wrapCommand(fnUnsetRelay), + Name: "unset-relay", + Help: commands.HelpMeta{ + Section: commands.HelpSectionUnclassified, + Description: "Disable the relay webhook and optionally delete it on Discord", + Args: "[--delete]", + }, + RequiresPortal: true, + RequiresEventLevel: roomModerator, +} + +func fnUnsetRelay(ce *WrappedCommandEvent) { + if ce.Portal.RelayWebhookID == "" { + ce.Reply("This portal doesn't have a relay webhook") + return + } + if len(ce.Args) > 0 && ce.Args[0] == "--delete" { + err := relayClient.WebhookDeleteWithToken(ce.Portal.RelayWebhookID, ce.Portal.RelayWebhookSecret) + if err != nil { + ce.Reply("Failed to delete webhook: %v", err) + return + } else { + ce.Reply("Successfully deleted webhook") + } + } else { + ce.Reply("Relay webhook disabled") + } + ce.Portal.RelayWebhookID = "" + ce.Portal.RelayWebhookSecret = "" + ce.Portal.Update() +} + var cmdGuilds = &commands.FullHandler{ Func: wrapCommand(fnGuilds), Name: "guilds", diff --git a/go.mod b/go.mod index 4fdf42f..5f0ce91 100644 --- a/go.mod +++ b/go.mod @@ -37,4 +37,4 @@ require ( maunium.net/go/mauflag v1.0.0 // indirect ) -replace github.com/bwmarrin/discordgo => github.com/beeper/discordgo v0.0.0-20230227224009-daaee0136f88 +replace github.com/bwmarrin/discordgo => github.com/beeper/discordgo v0.0.0-20230301183055-25031a2e2461 diff --git a/go.sum b/go.sum index daee64f..3216dd3 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60= -github.com/beeper/discordgo v0.0.0-20230227224009-daaee0136f88 h1:sZUZP+ClkQk1uC0KB6dYJ+v6Ygao3RaPKp/3leRjYik= -github.com/beeper/discordgo v0.0.0-20230227224009-daaee0136f88/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= +github.com/beeper/discordgo v0.0.0-20230301183055-25031a2e2461 h1:NYwJRLsgc22WsKB16uxUx2xbB+3AtbH0QuttVSCGe+4= +github.com/beeper/discordgo v0.0.0-20230301183055-25031a2e2461/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY= github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 h1:rtAn27wIbmOGUs7RIbVgPEjb31ehTVniDwPGXyMxm5U= github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=