|
9 | 9 | "github.com/slack-go/slack" |
10 | 10 | "github.com/spf13/cobra" |
11 | 11 | "github.com/triptechtravel/slackbuzz-cli/internal/api" |
| 12 | + "github.com/triptechtravel/slackbuzz-cli/internal/auth" |
12 | 13 | "github.com/triptechtravel/slackbuzz-cli/pkg/cmdutil" |
13 | 14 | ) |
14 | 15 |
|
@@ -119,6 +120,19 @@ func sendRun(opts *sendOptions) error { |
119 | 120 | return fmt.Errorf("%s", api.FormatResolveError(err, opts.channel)) |
120 | 121 | } |
121 | 122 |
|
| 123 | + // Self-DM: if sending a DM to yourself, switch to bot so you get a notification |
| 124 | + if api.LooksLikeUser(opts.channel) && !opts.asBot { |
| 125 | + if selfID, _, _ := auth.ResolveUserID(); selfID != "" { |
| 126 | + targetID := resolveTargetUserID(resolver, opts.channel) |
| 127 | + if targetID == selfID { |
| 128 | + if botClient, botErr := opts.factory.BotClient(); botErr == nil { |
| 129 | + client = botClient |
| 130 | + fmt.Fprintf(ios.ErrOut, "%s Sending to yourself — using bot so you get a notification\n", cs.Blue("→")) |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | + } |
| 135 | + |
122 | 136 | // Get message text from args or stdin |
123 | 137 | text := opts.text |
124 | 138 | if text == "" { |
@@ -187,6 +201,16 @@ func sendRun(opts *sendOptions) error { |
187 | 201 | return nil |
188 | 202 | } |
189 | 203 |
|
| 204 | +// resolveTargetUserID resolves a DM target to a user ID without opening a conversation. |
| 205 | +// Returns empty string if resolution fails. |
| 206 | +func resolveTargetUserID(r *api.Resolver, target string) string { |
| 207 | + id, err := r.ResolveUser(target) |
| 208 | + if err != nil { |
| 209 | + return "" |
| 210 | + } |
| 211 | + return id |
| 212 | +} |
| 213 | + |
190 | 214 | // unescapeShellArtifacts removes common shell escape sequences that leak into |
191 | 215 | // CLI arguments. For example, zsh's history expansion escapes ! as \! when |
192 | 216 | // passed through double-quoted strings. |
|
0 commit comments