-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (61 loc) · 1.4 KB
/
main.go
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
61
62
63
64
65
66
67
package main
import (
"context"
"fmt"
"log"
"os"
"strings"
"github.com/hidapple/memi/bot"
"github.com/hidapple/memi/kibela"
"golang.org/x/xerrors"
)
var help = fmt.Sprintf(`
%s
ping:
Test the reachability of the bot.
> @memi ping
link:
Append markdown link to the Kibela note.
> @memi link $URL [$TITLE $TEXT...]
%s`, "```", "```")
func main() {
b := bot.NewBot(os.Getenv("SLACK_TOKEN"), help)
b.AddCommands(
&bot.Command{
Name: "ping",
Do: func(args ...string) (string, error) {
return "にゃん:two_hearts:", nil
},
},
&bot.Command{
Name: "link",
Do: func(args ...string) (string, error) {
if len(args) == 0 {
return "こうやって使ってね:point_right: `@memi link $URL [$TITLE $TEXT...]`", nil
}
var url, title string
url = args[0]
if len(args) == 1 {
title = url
} else {
title = strings.Join(args[1:], " ")
}
k := kibela.New(os.Getenv("KIBELA_TOKEN"), os.Getenv("KIBELA_TEAM"))
note, err := k.AddLink(os.Getenv("KIBELA_LINK_NOTE"), url, title)
if err != nil {
return "", xerrors.Errorf("link command failed: %s", err)
}
msg := "更新したよ〜:cat:\n"
msg += "```\n"
msg += note.Content
msg += "```"
return msg, nil
},
},
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := b.OpenRTM(ctx); err != nil {
log.Fatalf("memi is stopped by err: %s", err)
}
}