Skip to content

Commit

Permalink
tell the user to add bot first
Browse files Browse the repository at this point in the history
  • Loading branch information
gardenerik committed Mar 8, 2024
1 parent 5686725 commit 6b691db
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions slack.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"github.com/charmbracelet/log"
"github.com/slack-go/slack"
Expand Down Expand Up @@ -130,6 +131,18 @@ func handleCommand(evt *socketmode.Event, client *socketmode.Client) {
msg := fmt.Sprintf("Nastavenia tohto kanálu nájdeš tu: %s/%s/%s/", App.config.RootURL, ev.ChannelID, token)
_, err := client.PostEphemeral(ev.ChannelID, ev.UserID, slack.MsgOptionText(msg, false))
if err != nil {
var slackErr slack.SlackErrorResponse
ok := errors.As(err, &slackErr)

if ok && (slackErr.Err == "channel_not_found" || slackErr.Err == "not_in_channel") {
log.Warn("Received command from a channel I am not in.", "channel", ev.ChannelID, "user", ev.UserID)
_, _, err := client.PostMessage(ev.UserID, slack.MsgOptionText("⚠️ Predtým, ako môžeš použiť `/buzerator` v nejakom kanáli, musíš ma doňho pridať.", false))
if err != nil {
log.Error("Could not send command not_in_channel notice.", "channel", ev.ChannelID, "user", ev.UserID)
}
return
}

log.Error("Could not send command reply.", "err", err)
}
}
Expand Down

0 comments on commit 6b691db

Please sign in to comment.