瀏覽代碼

Don't allow overriding set-relay without unsetting first

Tulir Asokan 2 年之前
父節點
當前提交
4e9e50dbed
共有 1 個文件被更改,包括 11 次插入2 次删除
  1. 11 2
      commands.go

+ 11 - 2
commands.go

@@ -426,14 +426,23 @@ func fnSetRelay(ce *WrappedCommandEvent) {
 		ce.Reply("You must either run the command in a portal, or specify an internal room ID as the first parameter")
 		return
 	}
-	if ce.Portal.GuildID == "" {
+	log := ce.ZLog.With().Str("channel_id", portal.Key.ChannelID).Logger()
+	if portal.GuildID == "" {
 		ce.Reply("Only guild channels can have relays")
 		return
+	} else if portal.RelayWebhookID != "" {
+		webhookMeta, err := relayClient.WebhookWithToken(portal.RelayWebhookID, portal.RelayWebhookSecret)
+		if err != nil {
+			log.Warn().Err(err).Msg("Failed to get existing webhook info")
+			ce.Reply("This channel has a relay webhook set, but getting its info failed: %v", err)
+			return
+		}
+		ce.Reply("This channel already has a relay webhook %s (%s)", webhookMeta.Name, webhookMeta.ID)
+		return
 	} else if len(ce.Args) == 0 {
 		ce.Reply(selectRelayHelp)
 		return
 	}
-	log := ce.ZLog.With().Str("channel_id", portal.Key.ChannelID).Logger()
 	createType := strings.ToLower(strings.TrimLeft(ce.Args[0], "-"))
 	var webhookMeta *discordgo.Webhook
 	switch createType {