-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_react.go
More file actions
60 lines (55 loc) · 1.4 KB
/
cmd_react.go
File metadata and controls
60 lines (55 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"context"
"fmt"
"strings"
"github.com/slack-go/slack"
"github.com/urfave/cli/v3"
)
func cmdReact() *cli.Command {
return &cli.Command{
Name: "react",
Aliases: []string{"r"},
Usage: "メッセージにリアクションを付ける",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "target",
Aliases: []string{"t"},
Usage: "対象のメッセージURL",
Required: true,
},
&cli.StringFlag{
Name: "emoji",
Aliases: []string{"e"},
Usage: "リアクションの絵文字名 (例: +1 または :+1:)",
Required: true,
},
&cli.BoolFlag{
Name: "remove",
Aliases: []string{"d"},
Usage: "リアクションを削除する",
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
api := newAPI()
target := cmd.String("target")
emoji := strings.Trim(cmd.String("emoji"), ":")
remove := cmd.Bool("remove")
channelID, ts, ok := parseMessageURL(target)
if !ok {
return fmt.Errorf("無効なSlack URL: %s", target)
}
item := slack.NewRefToMessage(channelID, ts)
if remove {
if err := api.RemoveReaction(emoji, item); err != nil {
return fmt.Errorf("リアクション削除エラー: %w", err)
}
return nil
}
if err := api.AddReaction(emoji, item); err != nil {
return fmt.Errorf("リアクション追加エラー: %w", err)
}
return nil
},
}
}