├── .gitignore
├── img
├── screenshot1.png
└── screenshot2.png
├── captain-definition
├── Dockerfile
├── Dockerfile.prod
├── .github
└── workflows
│ ├── test.yml
│ ├── format.yml
│ ├── contributor_list.yml
│ └── lint.yml
├── handlers
├── install.go
├── events
│ ├── app_home_opened.go
│ └── message.go
├── login.go
├── events.go
├── code.go
└── interactivity.go
├── go.mod
├── docker-compose.yml
├── main.go
├── README.md
├── util
├── util_test.go
├── util.go
└── app_home.go
├── .air.conf
├── db
├── migrate.go
├── models.go
└── db.go
├── go.sum
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | *.env
2 | tmp/
--------------------------------------------------------------------------------
/img/screenshot1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjdenio/replier/HEAD/img/screenshot1.png
--------------------------------------------------------------------------------
/img/screenshot2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cjdenio/replier/HEAD/img/screenshot2.png
--------------------------------------------------------------------------------
/captain-definition:
--------------------------------------------------------------------------------
1 | {
2 | "schemaVersion": 2,
3 | "dockerfilePath": "./Dockerfile.prod"
4 | }
5 |
--------------------------------------------------------------------------------
/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM golang:latest
2 |
3 | WORKDIR /usr/src/app
4 |
5 | COPY . .
6 |
7 | RUN go get .
8 |
9 | RUN go get -u github.com/cosmtrek/air
10 | ENV air_wd /usr/src/app
11 |
12 | EXPOSE 3000
13 |
14 | CMD [ "air" ]
--------------------------------------------------------------------------------
/Dockerfile.prod:
--------------------------------------------------------------------------------
1 | FROM golang:1.16-alpine AS builder
2 |
3 | WORKDIR /usr/src/app
4 |
5 | COPY . .
6 |
7 | RUN go build -o app .
8 |
9 | FROM alpine:latest AS runner
10 |
11 | WORKDIR /usr/src/app
12 |
13 | COPY --from=builder /usr/src/app/app ./app
14 |
15 | CMD ["./app"]
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Test
2 | on:
3 | - push
4 | - pull_request
5 | jobs:
6 | test:
7 | name: Test
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@master
11 | - uses: actions/setup-go@v2
12 | - run: go test ./...
13 |
--------------------------------------------------------------------------------
/.github/workflows/format.yml:
--------------------------------------------------------------------------------
1 | name: Format
2 | on:
3 | - push
4 | - pull_request
5 | jobs:
6 | format:
7 | name: Format
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@master
11 | - uses: actions/setup-go@v2
12 | - run: gofmt -w .
13 | - run: git diff --exit-code
14 |
--------------------------------------------------------------------------------
/.github/workflows/contributor_list.yml:
--------------------------------------------------------------------------------
1 | name: Contributor List
2 | on:
3 | push:
4 | branches:
5 | - master
6 | jobs:
7 | contributor_list:
8 | name: Contributor List
9 | runs-on: ubuntu-latest
10 | steps:
11 | - uses: actions/checkout@master
12 | - uses: docker://cjdenio/contributor_list:latest
13 |
--------------------------------------------------------------------------------
/.github/workflows/lint.yml:
--------------------------------------------------------------------------------
1 | name: golangci-lint
2 | on:
3 | - push
4 | - pull_request
5 | jobs:
6 | golangci:
7 | name: lint
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@v2
11 | - name: golangci-lint
12 | uses: golangci/golangci-lint-action@master
13 | with:
14 | version: v1.29
15 |
--------------------------------------------------------------------------------
/handlers/install.go:
--------------------------------------------------------------------------------
1 | package handlers
2 |
3 | import (
4 | "fmt"
5 | "net/http"
6 | "os"
7 | )
8 |
9 | // HandleInstall redirects the user to the Slack installation
10 | func HandleInstall(w http.ResponseWriter, r *http.Request) {
11 | http.Redirect(w, r, fmt.Sprintf("https://slack.com/oauth/v2/authorize?scope=im:history,chat:write&client_id=%s&redirect_uri=%s&team=TEHRV8VC", os.Getenv("SLACK_CLIENT_ID"), os.Getenv("HOST")+"/code"), 302)
12 | }
13 |
--------------------------------------------------------------------------------
/handlers/events/app_home_opened.go:
--------------------------------------------------------------------------------
1 | package events
2 |
3 | import (
4 | "fmt"
5 |
6 | "github.com/cjdenio/replier/util"
7 | "github.com/slack-go/slack/slackevents"
8 | )
9 |
10 | // HandleAppHomeOpened is fired when the user opens the App Home.
11 | func HandleAppHomeOpened(outer *slackevents.EventsAPICallbackEvent, inner *slackevents.AppHomeOpenedEvent) {
12 | if err := util.UpdateAppHome(inner.User, outer.TeamID); err != nil {
13 | fmt.Println(err)
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/handlers/login.go:
--------------------------------------------------------------------------------
1 | package handlers
2 |
3 | import (
4 | "fmt"
5 | "net/http"
6 | "os"
7 | )
8 |
9 | // HandleLogin redirects the user to the Slack login
10 | func HandleLogin(w http.ResponseWriter, r *http.Request) {
11 | http.Redirect(w, r, fmt.Sprintf("https://slack.com/oauth/v2/authorize?scope=im:history,chat:write&user_scope=im:history,mpim:history,channels:history,groups:history,chat:write,users:read&client_id=%s&redirect_uri=%s", os.Getenv("SLACK_CLIENT_ID"), os.Getenv("HOST")+"/code"), 302)
12 | }
13 |
--------------------------------------------------------------------------------
/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/cjdenio/replier
2 |
3 | go 1.14
4 |
5 | require (
6 | github.com/aws/aws-sdk-go v1.36.23 // indirect
7 | github.com/golang/snappy v0.0.2 // indirect
8 | github.com/klauspost/compress v1.11.6 // indirect
9 | github.com/slack-go/slack v0.7.4
10 | github.com/stretchr/testify v1.6.1
11 | go.mongodb.org/mongo-driver v1.4.4
12 | golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad // indirect
13 | golang.org/x/sync v0.0.0-20201207232520-09787c993a3a // indirect
14 | golang.org/x/text v0.3.5 // indirect
15 | )
16 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3"
2 | services:
3 | main:
4 | build: .
5 | ports:
6 | - "3000:3000"
7 | volumes:
8 | - ".:/usr/src/app"
9 | env_file: .env
10 | environment:
11 | DB_URL: "mongodb://db:27017/replier"
12 | PORT: 3000
13 | db:
14 | image: mongo
15 | volumes:
16 | - "db_volume:/data/db"
17 | ports:
18 | - "3003:27017"
19 | mongo-express:
20 | image: mongo-express
21 | ports:
22 | - "3002:8081"
23 | environment:
24 | ME_CONFIG_MONGODB_SERVER: db
25 | ngrok:
26 | image: wernight/ngrok
27 | environment:
28 | NGROK_PORT: main:3000
29 | env_file: .ngrok.env
30 | ports:
31 | - "3001:4040"
32 | volumes:
33 | db_volume:
34 |
--------------------------------------------------------------------------------
/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "log"
5 | "net/http"
6 | "os"
7 |
8 | "github.com/cjdenio/replier/db"
9 | "github.com/cjdenio/replier/handlers"
10 | )
11 |
12 | func main() {
13 | db.Connect()
14 |
15 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
16 | http.Redirect(w, r, "https://github.com/cjdenio/replier", http.StatusMovedPermanently)
17 | })
18 | http.HandleFunc("/slack/events", handlers.HandleEvents)
19 | http.HandleFunc("/slack/interactivity", handlers.HandleInteractivity)
20 | http.HandleFunc("/login", handlers.HandleLogin)
21 | http.HandleFunc("/install", handlers.HandleInstall)
22 | http.HandleFunc("/code", handlers.HandleOAuthCode)
23 |
24 | err := http.ListenAndServe(":"+os.Getenv("PORT"), http.DefaultServeMux)
25 |
26 | log.Fatal(err)
27 | }
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # 🤖 Replier
4 |
5 | 
6 | 
7 | 
8 |
9 | An autoreply bot originally for the [Hack Club](https://hackclub.com) Slack, now available for your workspace! Built using Go, MongoDB, and Docker.
10 |
11 | [](https://replier.calebden.io/login)
12 |
13 | 
14 | 
15 |
16 | ## How it works
17 |
18 | You sign in with Slack, configure your autoreply message, hit "Turn On", and Replier handles the rest! 🎉
19 |
20 |
21 |
22 | ## 👥 Contributors
23 |
24 | - **[@cjdenio](https://github.com/cjdenio)**
25 |
26 |
27 |
--------------------------------------------------------------------------------
/util/util_test.go:
--------------------------------------------------------------------------------
1 | package util
2 |
3 | import (
4 | "net/http"
5 | "os"
6 | "testing"
7 |
8 | "github.com/stretchr/testify/assert"
9 | )
10 |
11 | func TestVerifySlackRequest(t *testing.T) {
12 | // Random 32-character string
13 | secret := "2039f48n09c00249u0riunotiu034he9"
14 | os.Setenv("SLACK_SIGNING_SECRET", secret)
15 |
16 | r := &http.Request{
17 | Header: http.Header{
18 | "X-Slack-Request-Timestamp": {"1596411843"},
19 | "X-Slack-Signature": {"v0=bf6cccaf6d49158d589bb82e5ef94778d4c6c39bb4ef3a6cc56fe25426c24eb4"},
20 | },
21 | }
22 |
23 | // Example slash command request
24 | b := []byte("text=hello&user_id=U12345678&team_id=T12345678&command=/test")
25 |
26 | assert.True(t, VerifySlackRequest(r, b))
27 |
28 | // Should fail:
29 | os.Setenv("SLACK_SIGNING_SECRET", "blahblah")
30 | assert.False(t, VerifySlackRequest(r, b))
31 | }
32 |
33 | func TestIsInArray(t *testing.T) {
34 | assert.True(t, IsInArray([]string{"i", "like", "go", "!"}, "go"))
35 | assert.False(t, IsInArray([]string{"i", "like", "go", "!"}, "rust"))
36 | }
37 |
38 | func TestTransformUserReply(t *testing.T) {
39 | assert.Equal(t, "Howdy, <@U12345678>! :wave:", TransformUserReply("Howdy, @person! :wave:", "U12345678"))
40 | }
41 |
--------------------------------------------------------------------------------
/.air.conf:
--------------------------------------------------------------------------------
1 | # Config file for [Air](https://github.com/cosmtrek/air) in TOML format
2 |
3 | # Working directory
4 | # . or absolute path, please note that the directories following must be under root.
5 | root = "."
6 | tmp_dir = "tmp"
7 |
8 | [build]
9 | # Just plain old shell command. You could use `make` as well.
10 | cmd = "go build -o ./tmp/main ."
11 | # Binary file yields from `cmd`.
12 | bin = "tmp/main"
13 | # Customize binary.
14 | full_bin = "APP_ENV=dev APP_USER=air ./tmp/main"
15 | # Watch these filename extensions.
16 | include_ext = ["go", "tpl", "tmpl", "html"]
17 | # Ignore these filename extensions or directories.
18 | exclude_dir = ["assets", "tmp", "vendor", "frontend/node_modules"]
19 | # Watch these directories if you specified.
20 | include_dir = []
21 | # Exclude files.
22 | exclude_file = []
23 | # This log file places in your tmp_dir.
24 | log = "air.log"
25 | # It's not necessary to trigger build each time file changes if it's too frequent.
26 | delay = 1000 # ms
27 | # Stop running old binary when build errors occur.
28 | stop_on_error = true
29 | # Send Interrupt signal before killing process (windows does not support this feature)
30 | send_interrupt = false
31 | # Delay after sending Interrupt signal
32 | kill_delay = 500 # ms
33 |
34 | [log]
35 | # Show log time
36 | time = false
37 |
38 | [color]
39 | # Customize each part's color. If no color found, use the raw app log.
40 | main = "magenta"
41 | watcher = "cyan"
42 | build = "yellow"
43 | runner = "green"
44 |
45 | [misc]
46 | # Delete tmp directory on exit
47 | clean_on_exit = true
--------------------------------------------------------------------------------
/db/migrate.go:
--------------------------------------------------------------------------------
1 | package db
2 |
3 | import (
4 | "context"
5 | "log"
6 | "time"
7 |
8 | "go.mongodb.org/mongo-driver/bson"
9 | )
10 |
11 | // migrate defines a DB migration. It is run once upon every connection to the database.
12 | func migrate() error {
13 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
14 | defer cancel()
15 |
16 | result, err := DB.Database("replier").Collection("users").UpdateMany(ctx, bson.M{
17 | "reply.mode": bson.M{"$exists": false}, "$and": bson.A{
18 | bson.M{
19 | "$or": bson.A{
20 | bson.M{"reply.start": nil},
21 | bson.M{"reply.start": time.Time{}},
22 | },
23 | },
24 | bson.M{
25 | "$or": bson.A{
26 | bson.M{"reply.end": nil},
27 | bson.M{"reply.end": time.Time{}},
28 | },
29 | },
30 | },
31 | }, bson.M{
32 | "$set": bson.M{"reply.mode": ReplyModeManual},
33 | })
34 | if err != nil {
35 | return err
36 | }
37 |
38 | log.Printf("Successfully migrated %d DB records to ReplyModeManual", result.ModifiedCount)
39 |
40 | result, err = DB.Database("replier").Collection("users").UpdateMany(ctx, bson.M{
41 | "reply.mode": bson.M{"$exists": false}, "$or": bson.A{
42 | bson.M{"reply.start": bson.M{"$ne": nil}},
43 | bson.M{"reply.end": bson.M{"$ne": nil}},
44 | bson.M{"reply.start": bson.M{"$ne": time.Time{}}},
45 | bson.M{"reply.end": bson.M{"$ne": time.Time{}}},
46 | },
47 | }, bson.M{
48 | "$set": bson.M{"reply.mode": ReplyModeDate},
49 | })
50 | if err != nil {
51 | return err
52 | }
53 |
54 | log.Printf("Successfully migrated %d DB records to ReplyModeDate", result.ModifiedCount)
55 |
56 | return nil
57 | }
58 |
--------------------------------------------------------------------------------
/handlers/events.go:
--------------------------------------------------------------------------------
1 | package handlers
2 |
3 | import (
4 | "encoding/json"
5 | "io/ioutil"
6 | "log"
7 | "net/http"
8 |
9 | "github.com/cjdenio/replier/handlers/events"
10 | "github.com/cjdenio/replier/util"
11 | "github.com/slack-go/slack/slackevents"
12 | )
13 |
14 | // HandleEvents handles Events API requests
15 | func HandleEvents(w http.ResponseWriter, r *http.Request) {
16 | buf, _ := ioutil.ReadAll(r.Body)
17 |
18 | if !util.VerifySlackRequest(r, buf) {
19 | w.WriteHeader(http.StatusUnauthorized)
20 | _, err := w.Write([]byte("Not verified :("))
21 | if err != nil {
22 | log.Println(err)
23 | }
24 | return
25 | }
26 |
27 | slackEvent, err := slackevents.ParseEvent(buf, slackevents.OptionNoVerifyToken())
28 | if err != nil {
29 | w.WriteHeader(http.StatusBadRequest)
30 | _, err := w.Write([]byte("Invalid event payload"))
31 | if err != nil {
32 | log.Println(err)
33 | }
34 | return
35 | }
36 |
37 | if slackEvent.Type == slackevents.URLVerification {
38 | var r *slackevents.ChallengeResponse
39 | err := json.Unmarshal(buf, &r)
40 | if err != nil {
41 | w.WriteHeader(http.StatusInternalServerError)
42 | }
43 | w.Header().Set("Content-Type", "text")
44 | _, err = w.Write([]byte(r.Challenge))
45 | if err != nil {
46 | log.Println(err)
47 | }
48 | } else if slackEvent.Type == slackevents.CallbackEvent {
49 | _, err = w.Write(nil)
50 | if err != nil {
51 | log.Println(err)
52 | }
53 | innerEvent := slackEvent.InnerEvent
54 | switch ev := innerEvent.Data.(type) {
55 | case *slackevents.MessageEvent:
56 | // If this is a message sub-event, ignore it
57 | if ev.SubType != "" {
58 | return
59 | }
60 |
61 | if ev.ChannelType == "im" {
62 | events.HandleMessage(slackEvent.Data.(*slackevents.EventsAPICallbackEvent), ev)
63 | } else {
64 | events.HandleMessageNonDM(slackEvent.Data.(*slackevents.EventsAPICallbackEvent), ev)
65 | }
66 | case *slackevents.AppHomeOpenedEvent:
67 | events.HandleAppHomeOpened(slackEvent.Data.(*slackevents.EventsAPICallbackEvent), ev)
68 | }
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/db/models.go:
--------------------------------------------------------------------------------
1 | package db
2 |
3 | import (
4 | "time"
5 |
6 | "github.com/slack-go/slack"
7 | )
8 |
9 | type ReplyMode string
10 |
11 | const (
12 | ReplyModeManual ReplyMode = "manual"
13 | ReplyModeDate ReplyMode = "date"
14 | ReplyModePresence ReplyMode = "presence"
15 | )
16 |
17 | // User represents a DB user.
18 | type User struct {
19 | Token string `bson:"token"`
20 | UserID string `bson:"user_id"`
21 | Reply UserReply `bson:"reply"`
22 | Scopes []string `bson:"scopes"`
23 | TeamID string `bson:"team_id"`
24 | }
25 |
26 | // UserReply represents a user's chosen auto reply
27 | type UserReply struct {
28 | Message string `bson:"message"`
29 | Active bool `bson:"active"`
30 | Whitelist []string `bson:"whitelist"`
31 | Start time.Time `bson:"start"`
32 | End time.Time `bson:"end"`
33 | Mode ReplyMode `bson:"mode"`
34 | }
35 |
36 | // ReplyShouldSend figures out whether or not the configured autoreply should be sent
37 | func (user User) ReplyShouldSend() bool {
38 | if user.Reply.Message == "" {
39 | return false
40 | }
41 |
42 | switch user.Reply.Mode {
43 | case ReplyModeManual:
44 | return user.Reply.Active
45 | case ReplyModeDate:
46 | now := time.Now()
47 |
48 | if user.Reply.Start != (time.Time{}) && user.Reply.Start.After(now) {
49 | return false
50 | }
51 |
52 | if user.Reply.End != (time.Time{}) && user.Reply.End.Add(24*time.Hour).Before(now) {
53 | return false
54 | }
55 | case ReplyModePresence:
56 | client := slack.New(user.Token)
57 | if presence, err := client.GetUserPresence(user.UserID); err != nil {
58 | return false
59 | } else if presence.Presence == "active" {
60 | return false
61 | } else if presence.Presence == "away" {
62 | return true
63 | }
64 | }
65 |
66 | return true
67 | }
68 |
69 | // Conversation represents a single DM or channel.
70 | type Conversation struct {
71 | UserID string `bson:"user_id"`
72 | ConversationID string `bson:"conversation_id"`
73 | LastPostedOn int64 `bson:"last_posted_on"`
74 | }
75 |
76 | // Installation represents an app installation
77 | type Installation struct {
78 | TeamID string `bson:"team_id"`
79 | Scopes []string `bson:"scopes"`
80 | Token string `bson:"token"`
81 | BotID string `bson:"bot_id"`
82 | }
83 |
--------------------------------------------------------------------------------
/handlers/code.go:
--------------------------------------------------------------------------------
1 | package handlers
2 |
3 | import (
4 | "log"
5 | "net/http"
6 | "os"
7 | "strings"
8 |
9 | "github.com/cjdenio/replier/db"
10 | "github.com/cjdenio/replier/util"
11 | "github.com/slack-go/slack"
12 | //"github.com/cjdenio/replier/db"
13 | )
14 |
15 | // HandleOAuthCode handles the OAuth redirect
16 | func HandleOAuthCode(w http.ResponseWriter, r *http.Request) {
17 | code := r.URL.Query().Get("code")
18 | resp, err := slack.GetOAuthV2Response(&http.Client{}, os.Getenv("SLACK_CLIENT_ID"), os.Getenv("SLACK_CLIENT_SECRET"), code, os.Getenv("HOST")+"/code")
19 | if err != nil {
20 | w.WriteHeader(http.StatusBadRequest)
21 | _, err = w.Write([]byte("Something went wrong; please try again. :("))
22 | if err != nil {
23 | log.Println(err)
24 | }
25 | return
26 | }
27 | if resp.AuthedUser.AccessToken != "" {
28 | err = db.AddUser(db.User{
29 | Token: resp.AuthedUser.AccessToken,
30 | UserID: resp.AuthedUser.ID,
31 | Scopes: strings.Split(resp.AuthedUser.Scope, ","),
32 | TeamID: resp.Team.ID,
33 | })
34 | if err != nil {
35 | w.WriteHeader(http.StatusInternalServerError)
36 | _, err = w.Write([]byte("Something went wrong on our end. Please try again in a little bit."))
37 | if err != nil {
38 | log.Println(err)
39 | }
40 | }
41 | }
42 |
43 | if resp.AccessToken != "" {
44 | err := db.AddInstallation(db.Installation{
45 | Token: resp.AccessToken,
46 | Scopes: strings.Split(resp.Scope, ","),
47 | TeamID: resp.Team.ID,
48 | BotID: resp.BotUserID,
49 | })
50 |
51 | if err != nil {
52 | w.WriteHeader(http.StatusInternalServerError)
53 | _, err = w.Write([]byte("Something went wrong on our end. Please try again in a little bit."))
54 | if err != nil {
55 | log.Println(err)
56 | }
57 | }
58 | }
59 | w.Header().Add("Content-Type", "text/html")
60 | _, err = w.Write([]byte("
You're logged in!
You can now head on back to Slack.
"))
61 | if err != nil {
62 | log.Println(err)
63 | }
64 |
65 | err = util.UpdateAppHome(resp.AuthedUser.ID, resp.Team.ID)
66 | if err != nil {
67 | log.Println(err)
68 | }
69 |
70 | err = util.SendWelcomeMessage(resp.Team.ID, resp.AuthedUser.ID)
71 | if err != nil {
72 | log.Println(err)
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/util/util.go:
--------------------------------------------------------------------------------
1 | package util
2 |
3 | import (
4 | "crypto/hmac"
5 | "crypto/sha256"
6 | "encoding/hex"
7 | "fmt"
8 | "net/http"
9 | "os"
10 | "strings"
11 |
12 | "github.com/cjdenio/replier/db"
13 | "github.com/slack-go/slack"
14 | )
15 |
16 | // HeaderBlock represents a Slack header block
17 | type HeaderBlock struct {
18 | Type string `json:"type"`
19 | Text *slack.TextBlockObject `json:"text"`
20 | }
21 |
22 | // BlockType gets the block's type
23 | func (b HeaderBlock) BlockType() slack.MessageBlockType {
24 | return slack.MessageBlockType(b.Type)
25 | }
26 |
27 | // SendWelcomeMessage sends the specified user a welcome DM.
28 | func SendWelcomeMessage(teamID, userID string) error {
29 | installation, err := db.GetInstallation(teamID)
30 | if err != nil {
31 | return err
32 | }
33 |
34 | client := slack.New(installation.Token)
35 |
36 | _, _, err = client.PostMessage(userID, slack.MsgOptionBlocks(
37 | slack.NewSectionBlock(slack.NewTextBlockObject("mrkdwn", "Hi there, and welcome to Replier! :wave: I make setting up autoreplies for Slack simple. :robot_face: Let me show you around real quick!", false, false), nil, nil),
38 | slack.NewSectionBlock(slack.NewTextBlockObject("mrkdwn", "To get started, head on over to my Home tab. From there you can set up your autoreply message, then turn it on! :sparkles:", false, false), nil, nil),
39 | slack.NewSectionBlock(slack.NewTextBlockObject("mrkdwn", "Once you've turned your autoreply on, people will see it when they either DM you or mention you in a group DM/private channel/public channel.", false, false), nil, nil),
40 | slack.NewSectionBlock(slack.NewTextBlockObject("mrkdwn", "*By the way*, you can put `@person` in your autoreply message to get it replaced by the name of the person who messaged you!", false, false), nil, nil),
41 | slack.NewSectionBlock(slack.NewTextBlockObject("mrkdwn", "Want to get more advanced? You can set start/end dates to make sure your autoreply automatically turns on and off at the right time! :calendar:", false, false), nil, nil),
42 | slack.NewSectionBlock(slack.NewTextBlockObject("mrkdwn", "_That's all from me!_ If you run into any issues, or have any feature requests, please feel free to open an issue on the !", false, false), nil, nil),
43 | ), slack.MsgOptionText("Welcome to Replier!", false))
44 |
45 | if err != nil {
46 | return err
47 | }
48 |
49 | return nil
50 | }
51 |
52 | // VerifySlackRequest verifies a Slack request
53 | func VerifySlackRequest(r *http.Request, body []byte) bool {
54 | mac := hmac.New(sha256.New, []byte(os.Getenv("SLACK_SIGNING_SECRET")))
55 |
56 | body = append([]byte(r.Header.Get("X-Slack-Request-Timestamp")+":"), body...)
57 | body = append([]byte("v0:"), body...)
58 |
59 | _, err := mac.Write(body)
60 | if err != nil {
61 | return false
62 | }
63 |
64 | return hmac.Equal([]byte("v0="+hex.EncodeToString(mac.Sum(nil))), []byte(r.Header.Get("X-Slack-Signature")))
65 | }
66 |
67 | // IsInArray checks if the value is in the array
68 | func IsInArray(array []string, value string) bool {
69 | for _, v := range array {
70 | if v == value {
71 | return true
72 | }
73 | }
74 | return false
75 | }
76 |
77 | // GetUserTimezone gets a Slack user's timezone.
78 | func GetUserTimezone(userID string) (string, error) {
79 | user, err := db.GetUser(userID)
80 | if err != nil {
81 | return "", err
82 | }
83 |
84 | client := slack.New(user.Token)
85 | slackUser, err := client.GetUserInfo(user.UserID)
86 | if err != nil {
87 | return "", err
88 | }
89 |
90 | return slackUser.TZ, nil
91 | }
92 |
93 | // TransformUserReply transforms a user's reply
94 | func TransformUserReply(reply, userID string) string {
95 | return strings.ReplaceAll(reply, "@person", fmt.Sprintf("<@%s>", userID))
96 | }
97 |
--------------------------------------------------------------------------------
/handlers/events/message.go:
--------------------------------------------------------------------------------
1 | package events
2 |
3 | import (
4 | "fmt"
5 | "log"
6 | "os"
7 | "strings"
8 | "time"
9 |
10 | "github.com/cjdenio/replier/db"
11 | "github.com/cjdenio/replier/util"
12 |
13 | "sync"
14 |
15 | "github.com/slack-go/slack"
16 | "github.com/slack-go/slack/slackevents"
17 | )
18 |
19 | // HandleMessage handles DMs
20 | func HandleMessage(outer *slackevents.EventsAPICallbackEvent, inner *slackevents.MessageEvent) {
21 | appClient := slack.New("", slack.OptionAppLevelToken(os.Getenv("SLACK_APP_LEVEL_TOKEN")))
22 |
23 | authorizations, err := appClient.ListEventAuthorizations(outer.EventContext)
24 | if err != nil {
25 | log.Println(err)
26 | return
27 | }
28 |
29 | wg := sync.WaitGroup{}
30 |
31 | wg.Add(len(authorizations))
32 |
33 | for _, v := range authorizations {
34 | go func(userID string) {
35 | defer wg.Done()
36 |
37 | if userID == inner.User || inner.BotID != "" || inner.User == "USLACKBOT" {
38 | return
39 | }
40 | user, err := db.GetUser(userID)
41 | lastPostedOn := db.GetConversationLastPostedOn(inner.Channel, userID)
42 |
43 | if err == nil && user.ReplyShouldSend() && !util.IsInArray(user.Reply.Whitelist, inner.User) && time.Since(lastPostedOn).Minutes() > 15 {
44 | client := slack.New(user.Token)
45 | _, _, err = client.PostMessage(inner.Channel, slack.MsgOptionBlocks(
46 | slack.NewSectionBlock(
47 | slack.NewTextBlockObject("mrkdwn", util.TransformUserReply(user.Reply.Message, inner.User), false, false),
48 | nil,
49 | nil,
50 | ),
51 | slack.NewContextBlock("", slack.NewTextBlockObject("mrkdwn", fmt.Sprintf("", outer.TeamID, outer.APIAppID), false, false)),
52 | ), slack.MsgOptionText(util.TransformUserReply(user.Reply.Message, inner.User), false))
53 | if err != nil {
54 | log.Println(err)
55 | }
56 | if err = db.SetConversationLastPostedOn(inner.Channel, userID, time.Now()); err != nil {
57 | log.Println(err)
58 | }
59 | }
60 | }(v.UserID)
61 | }
62 |
63 | wg.Wait()
64 | }
65 |
66 | // HandleMessageNonDM handles non-DM messages
67 | func HandleMessageNonDM(outer *slackevents.EventsAPICallbackEvent, inner *slackevents.MessageEvent) {
68 | appClient := slack.New("", slack.OptionAppLevelToken(os.Getenv("SLACK_APP_LEVEL_TOKEN")))
69 |
70 | authorizations, err := appClient.ListEventAuthorizations(outer.EventContext)
71 | if err != nil {
72 | log.Println(err)
73 | return
74 | }
75 |
76 | wg := sync.WaitGroup{}
77 |
78 | wg.Add(len(authorizations))
79 |
80 | for _, v := range authorizations {
81 | go func(userID string) {
82 | defer wg.Done()
83 |
84 | if userID == inner.User || inner.BotID != "" {
85 | return
86 | }
87 | user, err := db.GetUser(userID)
88 |
89 | timestampToReplyTo := inner.ThreadTimeStamp
90 |
91 | if timestampToReplyTo == "" {
92 | timestampToReplyTo = inner.TimeStamp
93 | }
94 |
95 | if err == nil && strings.Contains(inner.Text, fmt.Sprintf("<@%s>", userID)) && user.ReplyShouldSend() && !util.IsInArray(user.Reply.Whitelist, inner.User) {
96 | client := slack.New(user.Token)
97 | _, _, err = client.PostMessage(inner.Channel, slack.MsgOptionBlocks(
98 | slack.NewSectionBlock(
99 | slack.NewTextBlockObject("mrkdwn", util.TransformUserReply(user.Reply.Message, inner.User), false, false),
100 | nil,
101 | nil,
102 | ),
103 | slack.NewContextBlock("", slack.NewTextBlockObject("mrkdwn", fmt.Sprintf("", outer.TeamID, outer.APIAppID), false, false)),
104 | ), slack.MsgOptionText(util.TransformUserReply(user.Reply.Message, inner.User), false), slack.MsgOptionTS(timestampToReplyTo))
105 | if err != nil {
106 | log.Println(err)
107 | }
108 | }
109 | }(v.UserID)
110 | }
111 |
112 | wg.Wait()
113 | }
114 |
--------------------------------------------------------------------------------
/util/app_home.go:
--------------------------------------------------------------------------------
1 | package util
2 |
3 | import (
4 | "fmt"
5 | "os"
6 |
7 | "github.com/cjdenio/replier/db"
8 | "github.com/slack-go/slack"
9 | )
10 |
11 | // NewInputBlock is an input block that contains the DispatchAction field
12 | type NewInputBlock struct {
13 | Type slack.MessageBlockType `json:"type"`
14 | BlockID string `json:"block_id,omitempty"`
15 | Label *slack.TextBlockObject `json:"label"`
16 | Element slack.BlockElement `json:"element"`
17 | Hint *slack.TextBlockObject `json:"hint,omitempty"`
18 | Optional bool `json:"optional,omitempty"`
19 | DispatchAction bool `json:"dispatch_action"`
20 | }
21 |
22 | func (s NewInputBlock) BlockType() slack.MessageBlockType {
23 | return s.Type
24 | }
25 |
26 | func UpdateAppHome(userID, teamID string) error {
27 | installation, err := db.GetInstallation(teamID)
28 | if err != nil {
29 | fmt.Println(err)
30 | }
31 | client := slack.New(installation.Token)
32 |
33 | user, err := db.GetUser(userID)
34 |
35 | replyMode := user.Reply.Mode
36 | if replyMode == "" {
37 | replyMode = db.ReplyModeManual
38 | }
39 |
40 | needsToLogin := false
41 |
42 | if err != nil || user.Token == "" {
43 | needsToLogin = true
44 | } else if _, err := slack.New(user.Token).AuthTest(); err != nil {
45 | needsToLogin = true
46 | }
47 |
48 | var blocks []slack.Block
49 | if needsToLogin {
50 | blocks = []slack.Block{
51 | slack.NewSectionBlock(
52 | slack.NewTextBlockObject("mrkdwn", fmt.Sprintf("Hi there! :wave: Please <%s|log in real quick> to get started!", os.Getenv("HOST")+"/login"), false, false),
53 | nil,
54 | slack.NewAccessory(&slack.ButtonBlockElement{
55 | Type: slack.METButton,
56 | Text: slack.NewTextBlockObject("plain_text", ":bust_in_silhouette: Log in", true, false),
57 | ActionID: "login",
58 | URL: os.Getenv("HOST") + "/login",
59 | }),
60 | ),
61 | }
62 | } else {
63 | replyActive := user.ReplyShouldSend()
64 |
65 | replyActiveText := ":x: Your autoreply is *off*."
66 | if replyActive {
67 | replyActiveText = ":heavy_check_mark: Your autoreply is *on*!"
68 | }
69 | if user.Reply.Message == "" {
70 | replyActiveText = ":x: Your autoreply is *off* because you haven't set a message."
71 | }
72 |
73 | var replyActiveAccessory *slack.Accessory
74 |
75 | if user.Reply.Mode == db.ReplyModeManual {
76 | replyActiveAccessory = slack.NewAccessory(&slack.ButtonBlockElement{
77 | Type: slack.METButton,
78 | Text: slack.NewTextBlockObject("plain_text", map[bool]string{true: "Turn off", false: "Turn on"}[user.Reply.Active], false, false),
79 | ActionID: "reply_toggle",
80 | })
81 | }
82 |
83 | buttonStyles := map[string]slack.Style{
84 | "manual": "",
85 | "date": "",
86 | "presence": "",
87 | }
88 | if replyMode == db.ReplyModeManual {
89 | buttonStyles["manual"] = slack.StylePrimary
90 | } else if replyMode == db.ReplyModeDate {
91 | buttonStyles["date"] = slack.StylePrimary
92 | } else if replyMode == db.ReplyModePresence {
93 | buttonStyles["presence"] = slack.StylePrimary
94 | }
95 |
96 | blocks = []slack.Block{
97 | &NewInputBlock{
98 | Type: slack.MBTInput,
99 | Label: slack.NewTextBlockObject("plain_text", "Your autoreply message", false, false),
100 | BlockID: "message",
101 | DispatchAction: true,
102 | Element: &slack.PlainTextInputBlockElement{
103 | Type: slack.METPlainTextInput,
104 | Multiline: true,
105 | ActionID: "message",
106 | InitialValue: user.Reply.Message,
107 | },
108 | },
109 | slack.NewContextBlock("", slack.NewTextBlockObject("mrkdwn", ":sparkles: *Fun fact:* if you put `@person` in the message, it'll get replaced by the actual message sender's name!", false, false)),
110 | slack.NewActionBlock("", slack.NewButtonBlockElement("edit_message", "", slack.NewTextBlockObject("plain_text", ":gear: Settings", true, false))),
111 | slack.NewDividerBlock(),
112 | slack.NewActionBlock("", slack.NewButtonBlockElement("mode-manual", "", slack.NewTextBlockObject("plain_text", "Manual", false, false)).WithStyle(buttonStyles["manual"]), slack.NewButtonBlockElement("mode-date", "", slack.NewTextBlockObject("plain_text", "Date Range", false, false)).WithStyle(buttonStyles["date"]), slack.NewButtonBlockElement("mode-presence", "", slack.NewTextBlockObject("plain_text", "Presence", false, false)).WithStyle(buttonStyles["presence"])),
113 | slack.NewSectionBlock(
114 | slack.NewTextBlockObject("mrkdwn", replyActiveText, false, false),
115 | nil,
116 | replyActiveAccessory,
117 | ),
118 | /*slack.NewDividerBlock(),
119 | slack.NewContextBlock("", slack.NewTextBlockObject("mrkdwn", "Replier is open-source on !", false, false)),*/
120 | }
121 | }
122 |
123 | _, err = client.PublishView(userID, slack.HomeTabViewRequest{
124 | Type: "home",
125 | Blocks: slack.Blocks{
126 | BlockSet: blocks,
127 | },
128 | }, "")
129 |
130 | if err != nil {
131 | return err
132 | }
133 |
134 | return nil
135 | }
136 |
--------------------------------------------------------------------------------
/db/db.go:
--------------------------------------------------------------------------------
1 | package db
2 |
3 | import (
4 | "context"
5 | "fmt"
6 | "log"
7 | "os"
8 | "time"
9 |
10 | "go.mongodb.org/mongo-driver/bson"
11 |
12 | "go.mongodb.org/mongo-driver/mongo/options"
13 |
14 | "go.mongodb.org/mongo-driver/mongo"
15 | )
16 |
17 | // DB is the Mongo database
18 | var DB *mongo.Client
19 |
20 | // Connect to the database
21 | func Connect() {
22 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
23 | defer cancel()
24 | client, err := mongo.Connect(ctx, options.Client().ApplyURI(os.Getenv("DB_URL")))
25 | if err != nil {
26 | log.Fatal(err)
27 | }
28 | DB = client
29 |
30 | if err = migrate(); err != nil {
31 | log.Fatal(err)
32 | }
33 | }
34 |
35 | // AddInstallation adds an installation to the database
36 | func AddInstallation(installation Installation) error {
37 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
38 | defer cancel()
39 |
40 | _, err := DB.Database("replier").Collection("installations").UpdateOne(ctx, bson.M{"team_id": installation.TeamID}, bson.M{"$set": installation}, options.Update().SetUpsert(true))
41 |
42 | if err != nil {
43 | return err
44 | }
45 |
46 | return nil
47 | }
48 |
49 | // GetInstallation gets an installation
50 | func GetInstallation(teamID string) (*Installation, error) {
51 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
52 | defer cancel()
53 |
54 | var installation *Installation
55 |
56 | err := DB.Database("replier").Collection("installations").FindOne(ctx, bson.M{"team_id": teamID}).Decode(&installation)
57 |
58 | if err != nil {
59 | return &Installation{}, err
60 | }
61 |
62 | return installation, nil
63 | }
64 |
65 | // AddUser adds a user
66 | func AddUser(user User) error {
67 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
68 | defer cancel()
69 |
70 | _, err := DB.Database("replier").Collection("users").UpdateOne(ctx, bson.D{{Key: "user_id", Value: user.UserID}}, bson.D{{Key: "$set", Value: bson.D{{Key: "user_id", Value: user.UserID}, {Key: "token", Value: user.Token}, {Key: "scopes", Value: user.Scopes}, {Key: "team_id", Value: user.TeamID}}}, {Key: "$setOnInsert", Value: bson.M{"reply.mode": ReplyModeManual}}}, options.Update().SetUpsert(true))
71 |
72 | return err
73 | }
74 |
75 | // GetUser gets a user based off of a user_id
76 | func GetUser(userID string) (*User, error) {
77 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
78 | defer cancel()
79 |
80 | var result *User
81 |
82 | err := DB.Database("replier").Collection("users").FindOne(ctx, bson.D{{Key: "user_id", Value: userID}}).Decode(&result)
83 |
84 | if err != nil {
85 | return &User{}, err
86 | }
87 | return result, nil
88 | }
89 |
90 | // SetUserMessage sets a users message
91 | func SetUserMessage(userID string, message string) error {
92 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
93 | defer cancel()
94 |
95 | _, err := DB.Database("replier").Collection("users").UpdateOne(ctx, bson.D{{Key: "user_id", Value: userID}}, bson.D{{Key: "$set", Value: bson.D{{Key: "reply.message", Value: message}}}})
96 |
97 | if err != nil {
98 | return err
99 | }
100 |
101 | return nil
102 | }
103 |
104 | // SetUserWhitelist sets a user's whitelist
105 | func SetUserWhitelist(userID string, whitelist []string) error {
106 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
107 | defer cancel()
108 |
109 | _, err := DB.Database("replier").Collection("users").UpdateOne(ctx, bson.D{{Key: "user_id", Value: userID}}, bson.D{{Key: "$set", Value: bson.D{{Key: "reply.whitelist", Value: whitelist}}}})
110 |
111 | return err
112 | }
113 |
114 | // SetUserDates sets a user's start/end dates
115 | func SetUserDates(start, end time.Time, userID string) error {
116 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
117 | defer cancel()
118 |
119 | _, err := DB.Database("replier").Collection("users").UpdateOne(ctx, bson.M{"user_id": userID}, bson.M{"$set": bson.M{"reply.start": start, "reply.end": end}})
120 |
121 | return err
122 | }
123 |
124 | // SetReplyMode sets a user's reply mode
125 | func SetReplyMode(userID string, mode ReplyMode) error {
126 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
127 | defer cancel()
128 |
129 | _, err := DB.Database("replier").Collection("users").UpdateOne(ctx, bson.M{"user_id": userID}, bson.M{"$set": bson.M{"reply.mode": mode}})
130 |
131 | return err
132 | }
133 |
134 | // ToggleReplyActive toggle's the activity of a user's autoreply
135 | func ToggleReplyActive(userID string) {
136 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
137 | defer cancel()
138 |
139 | user, err := GetUser(userID)
140 |
141 | if err != nil {
142 | fmt.Println(err)
143 | }
144 |
145 | _, err = DB.Database("replier").Collection("users").UpdateOne(ctx, bson.D{{Key: "user_id", Value: userID}}, bson.M{"$set": bson.M{"reply.active": !user.Reply.Active}})
146 | if err != nil {
147 | fmt.Println(err)
148 | }
149 | }
150 |
151 | // GetConversationLastPostedOn gets the Time that the conversation was last autoreplied to.
152 | func GetConversationLastPostedOn(conversationID, userID string) time.Time {
153 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
154 | defer cancel()
155 |
156 | var conversation *Conversation
157 |
158 | err := DB.Database("replier").Collection("conversations").FindOne(ctx, bson.M{"user_id": userID, "conversation_id": conversationID}).Decode(&conversation)
159 |
160 | if err != nil {
161 | return time.Time{}
162 | }
163 |
164 | result := time.Unix(conversation.LastPostedOn, 0)
165 |
166 | return result
167 | }
168 |
169 | // SetConversationLastPostedOn sets the Time above ^
170 | func SetConversationLastPostedOn(conversationID, userID string, lastPostedOn time.Time) error {
171 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
172 | defer cancel()
173 |
174 | _, err := DB.Database("replier").Collection("conversations").UpdateOne(ctx, bson.D{
175 | {Key: "conversation_id", Value: conversationID},
176 | {Key: "user_id", Value: userID},
177 | }, bson.D{
178 | {Key: "$set", Value: bson.D{
179 | {Key: "last_posted_on", Value: lastPostedOn.Unix()},
180 | }},
181 | }, options.Update().SetUpsert(true))
182 |
183 | return err
184 | }
185 |
--------------------------------------------------------------------------------
/handlers/interactivity.go:
--------------------------------------------------------------------------------
1 | package handlers
2 |
3 | import (
4 | "encoding/json"
5 | "fmt"
6 | "io/ioutil"
7 | "log"
8 | "net/http"
9 | "net/url"
10 | "time"
11 |
12 | "github.com/cjdenio/replier/db"
13 | "github.com/cjdenio/replier/util"
14 | "github.com/slack-go/slack"
15 | )
16 |
17 | // HandleInteractivity handles interactions in Slack
18 | func HandleInteractivity(w http.ResponseWriter, r *http.Request) {
19 | buf, _ := ioutil.ReadAll(r.Body)
20 | r.Form, _ = url.ParseQuery(string(buf))
21 |
22 | if !util.VerifySlackRequest(r, buf) {
23 | w.WriteHeader(http.StatusUnauthorized)
24 | _, err := w.Write([]byte("Not verified :("))
25 | if err != nil {
26 | log.Println(err)
27 | }
28 | return
29 | }
30 |
31 | var parsed slack.InteractionCallback
32 | err := json.Unmarshal([]byte(r.Form.Get("payload")), &parsed)
33 | if err != nil {
34 | w.WriteHeader(http.StatusBadRequest)
35 | _, err := w.Write([]byte("Invalid JSON payload"))
36 | if err != nil {
37 | log.Println(err)
38 | }
39 | return
40 | }
41 |
42 | if parsed.Type == slack.InteractionTypeBlockActions {
43 | _, err = w.Write(nil)
44 | if err != nil {
45 | log.Println(err)
46 | }
47 |
48 | switch parsed.ActionCallback.BlockActions[0].ActionID {
49 | case "edit_message":
50 | user, _ := db.GetUser(parsed.User.ID)
51 |
52 | blocks := []slack.Block{
53 | &slack.InputBlock{
54 | Type: slack.MBTInput,
55 | BlockID: "whitelist",
56 | Label: slack.NewTextBlockObject("plain_text", "Whitelist", false, false),
57 | Element: &slack.MultiSelectBlockElement{
58 | Type: "multi_users_select",
59 | InitialUsers: user.Reply.Whitelist,
60 | ActionID: "whitelist",
61 | Placeholder: slack.NewTextBlockObject("plain_text", "Select some...", false, false),
62 | },
63 | Optional: true,
64 | },
65 | slack.NewContextBlock("", slack.NewTextBlockObject("mrkdwn", "These people will _not_ receive your autoreply in DMs or public channels, even if it's enabled.", false, false)),
66 | }
67 |
68 | installation, err := db.GetInstallation(parsed.Team.ID)
69 | if err != nil {
70 | fmt.Println(err)
71 | }
72 |
73 | botClient := slack.New(installation.Token)
74 | _, err = botClient.OpenView(parsed.TriggerID, slack.ModalViewRequest{
75 | Type: "modal",
76 | Title: slack.NewTextBlockObject("plain_text", "Edit Settings", false, false),
77 | CallbackID: "edit_message",
78 | Blocks: slack.Blocks{
79 | BlockSet: blocks,
80 | },
81 | Close: slack.NewTextBlockObject("plain_text", "Cancel", false, false),
82 | Submit: slack.NewTextBlockObject("plain_text", "Save", false, false),
83 | })
84 |
85 | if err != nil {
86 | log.Println(err)
87 | }
88 | case "reply_toggle":
89 | db.ToggleReplyActive(parsed.User.ID)
90 | err := util.UpdateAppHome(parsed.User.ID, parsed.Team.ID)
91 | if err != nil {
92 | log.Println(err)
93 | }
94 | case "mode-manual":
95 | err = db.SetReplyMode(parsed.User.ID, db.ReplyModeManual)
96 | if err != nil {
97 | log.Println(err)
98 | }
99 | err = util.UpdateAppHome(parsed.User.ID, parsed.Team.ID)
100 | if err != nil {
101 | log.Println(err)
102 | }
103 | case "mode-date":
104 | installation, _ := db.GetInstallation(parsed.Team.ID)
105 | user, _ := db.GetUser(parsed.User.ID)
106 | client := slack.New(installation.Token)
107 |
108 | startDate := user.Reply.Start.Format("2006-01-02")
109 | if (user.Reply.Start == time.Time{}) {
110 | startDate = ""
111 | }
112 | endDate := user.Reply.End.Format("2006-01-02")
113 | if (user.Reply.End == time.Time{}) {
114 | endDate = ""
115 | }
116 |
117 | _, err = client.OpenView(parsed.TriggerID, slack.ModalViewRequest{
118 | Type: "modal",
119 | Title: slack.NewTextBlockObject("plain_text", "Date Range", false, false),
120 | CallbackID: "date_range",
121 | Blocks: slack.Blocks{
122 | BlockSet: []slack.Block{
123 | slack.InputBlock{
124 | Type: "input",
125 | BlockID: "start",
126 | Optional: true,
127 | Label: slack.NewTextBlockObject("plain_text", "Start Date", false, false),
128 | Element: slack.DatePickerBlockElement{
129 | Type: "datepicker",
130 | InitialDate: startDate,
131 | ActionID: "start",
132 | },
133 | },
134 | slack.InputBlock{
135 | Type: "input",
136 | BlockID: "end",
137 | Optional: true,
138 | Label: slack.NewTextBlockObject("plain_text", "End Date", false, false),
139 | Element: slack.DatePickerBlockElement{
140 | Type: "datepicker",
141 | InitialDate: endDate,
142 | ActionID: "end",
143 | },
144 | },
145 | },
146 | },
147 | Close: slack.NewTextBlockObject("plain_text", "Cancel", false, false),
148 | Submit: slack.NewTextBlockObject("plain_text", "Save", false, false),
149 | })
150 | if err != nil {
151 | log.Println(err)
152 | }
153 | case "mode-presence":
154 | err = db.SetReplyMode(parsed.User.ID, db.ReplyModePresence)
155 | if err != nil {
156 | log.Println(err)
157 | }
158 | err = util.UpdateAppHome(parsed.User.ID, parsed.Team.ID)
159 | if err != nil {
160 | log.Println(err)
161 | }
162 | case "message":
163 | err = db.SetUserMessage(parsed.User.ID, parsed.View.State.Values["message"]["message"].Value)
164 | if err != nil {
165 | log.Println(err)
166 | }
167 |
168 | err = util.UpdateAppHome(parsed.User.ID, parsed.Team.ID)
169 | if err != nil {
170 | log.Println(err)
171 | }
172 | }
173 | } else if parsed.Type == slack.InteractionTypeViewSubmission {
174 | switch parsed.View.CallbackID {
175 | case "edit_message":
176 | _, err = w.Write(nil)
177 | if err != nil {
178 | log.Println(err)
179 | }
180 |
181 | whitelist := parsed.View.State.Values["whitelist"]["whitelist"].SelectedUsers
182 |
183 | err = db.SetUserWhitelist(parsed.User.ID, whitelist)
184 | if err != nil {
185 | log.Println(err)
186 | }
187 |
188 | err = util.UpdateAppHome(parsed.User.ID, parsed.Team.ID)
189 | if err != nil {
190 | log.Println(err)
191 | }
192 | case "date_range":
193 | start := parsed.View.State.Values["start"]["start"].SelectedDate
194 | end := parsed.View.State.Values["end"]["end"].SelectedDate
195 |
196 | if start == "" && end == "" {
197 | w.Header().Add("Content-Type", "application/json")
198 | response, _ := json.Marshal(slack.ViewSubmissionResponse{
199 | ResponseAction: slack.RAErrors,
200 | Errors: map[string]string{
201 | "start": "Please select either a start date or an end date.",
202 | },
203 | })
204 | _, err = w.Write(response)
205 | if err != nil {
206 | log.Println(err)
207 | }
208 | } else {
209 | tz, err := util.GetUserTimezone(parsed.User.ID)
210 | if err != nil {
211 | log.Println(err)
212 | }
213 |
214 | loc, _ := time.LoadLocation(tz)
215 |
216 | startDate, _ := time.ParseInLocation("2006-01-02", start, loc)
217 | endDate, _ := time.ParseInLocation("2006-01-02", end, loc)
218 |
219 | err = db.SetUserDates(startDate, endDate, parsed.User.ID)
220 | if err != nil {
221 | log.Println(err)
222 | }
223 |
224 | err = db.SetReplyMode(parsed.User.ID, db.ReplyModeDate)
225 | if err != nil {
226 | log.Println(err)
227 | }
228 |
229 | err = util.UpdateAppHome(parsed.User.ID, parsed.Team.ID)
230 | if err != nil {
231 | log.Println(err)
232 | }
233 | }
234 | }
235 | }
236 | }
237 |
--------------------------------------------------------------------------------
/go.sum:
--------------------------------------------------------------------------------
1 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
2 | github.com/aws/aws-sdk-go v1.34.28 h1:sscPpn/Ns3i0F4HPEWAVcwdIRaZZCuL7llJ2/60yPIk=
3 | github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
4 | github.com/aws/aws-sdk-go v1.35.14 h1:nucVVXXjAr9UkmYCBWxQWRuYa5KOlaXjuJGg2ulW0K0=
5 | github.com/aws/aws-sdk-go v1.35.14/go.mod h1:tlPOdRjfxPBpNIwqDj61rmsnA85v9jc0Ps9+muhnW+k=
6 | github.com/aws/aws-sdk-go v1.36.23 h1:umM44ptMKImsUWLtjGBv/4Ut7Nd99DfqoZDkO0j0/Kc=
7 | github.com/aws/aws-sdk-go v1.36.23/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
8 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
10 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
11 | github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
12 | github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
13 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
14 | github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
15 | github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0=
16 | github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY=
17 | github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg=
18 | github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
19 | github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
20 | github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs=
21 | github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
22 | github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
23 | github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk=
24 | github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28=
25 | github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo=
26 | github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk=
27 | github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw=
28 | github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360=
29 | github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg=
30 | github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE=
31 | github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8=
32 | github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
33 | github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
34 | github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
35 | github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
36 | github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ=
37 | github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
38 | github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
39 | github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
40 | github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
41 | github.com/golang/snappy v0.0.2 h1:aeE13tS0IiQgFjYdoL8qN3K1N2bXXtI6Vi51/y7BpMw=
42 | github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
43 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
44 | github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
45 | github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
46 | github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
47 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
48 | github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
49 | github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
50 | github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
51 | github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
52 | github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
53 | github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
54 | github.com/klauspost/compress v1.9.5 h1:U+CaK85mrNNb4k8BNOfgJtJ/gr6kswUCFj6miSzVC6M=
55 | github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
56 | github.com/klauspost/compress v1.11.1 h1:bPb7nMRdOZYDrpPMTA3EInUQrdgoBinqUuSwlGdKDdE=
57 | github.com/klauspost/compress v1.11.1/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
58 | github.com/klauspost/compress v1.11.6 h1:EgWPCW6O3n1D5n99Zq3xXBt9uCwRGvpwGOusOLNBRSQ=
59 | github.com/klauspost/compress v1.11.6/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
60 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
61 | github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
62 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
63 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
64 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
65 | github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
66 | github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
67 | github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
68 | github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUruD3k1mMwo=
69 | github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
70 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
71 | github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
72 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
73 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
74 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
75 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
76 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
77 | github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
78 | github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
79 | github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
80 | github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
81 | github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
82 | github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
83 | github.com/slack-go/slack v0.6.5 h1:IkDKtJ2IROJNoe3d6mW870/NRKvq2fhLB/Q5XmzWk00=
84 | github.com/slack-go/slack v0.6.5/go.mod h1:FGqNzJBmxIsZURAxh2a8D21AnOVvvXZvGligs4npPUM=
85 | github.com/slack-go/slack v0.7.2 h1:oLy2a2YqrtoHSSxbjRhrtLDGbCKcZJwgbuQ826BWxaI=
86 | github.com/slack-go/slack v0.7.2/go.mod h1:FGqNzJBmxIsZURAxh2a8D21AnOVvvXZvGligs4npPUM=
87 | github.com/slack-go/slack v0.7.4 h1:Z+7CmUDV+ym4lYLA4NNLFIpr3+nDgViHrx8xsuXgrYs=
88 | github.com/slack-go/slack v0.7.4/go.mod h1:FGqNzJBmxIsZURAxh2a8D21AnOVvvXZvGligs4npPUM=
89 | github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
90 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
91 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
92 | github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
93 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
94 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
95 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
96 | github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
97 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
98 | github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
99 | github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c h1:u40Z8hqBAAQyv+vATcGgV0YCnDjqSL7/q/JyPhhJSPk=
100 | github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
101 | github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc h1:n+nNi93yXLkJvKwXNP9d55HC7lGK4H/SRcwB5IaUZLo=
102 | github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
103 | go.mongodb.org/mongo-driver v1.3.5 h1:S0ZOruh4YGHjD7JoN7mIsTrNjnQbOjrmgrx6l6pZN7I=
104 | go.mongodb.org/mongo-driver v1.3.5/go.mod h1:Ual6Gkco7ZGQw8wE1t4tLnvBsf6yVSM60qW6TgOeJ5c=
105 | go.mongodb.org/mongo-driver v1.4.2 h1:WlnEglfTg/PfPq4WXs2Vkl/5ICC6hoG8+r+LraPmGk4=
106 | go.mongodb.org/mongo-driver v1.4.2/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc=
107 | go.mongodb.org/mongo-driver v1.4.4 h1:bsPHfODES+/yx2PCWzUYMH8xj6PVniPI8DQrsJuSXSs=
108 | go.mongodb.org/mongo-driver v1.4.4/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc=
109 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
110 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
111 | golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
112 | golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5 h1:8dUaAV7K4uHsF56JQWkprecIQKdPHtR9jCHF5nB8uzc=
113 | golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
114 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
115 | golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E=
116 | golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
117 | golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
118 | golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
119 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
120 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
121 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
122 | golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
123 | golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
124 | golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
125 | golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
126 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
127 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
128 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9 h1:SQFwaSi55rU7vdNs9Yr0Z324VNlrF+0wMqRXT4St8ck=
129 | golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
130 | golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs=
131 | golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
132 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
133 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
134 | golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
135 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
136 | golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
137 | golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
138 | golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
139 | golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
140 | golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
141 | golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
142 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
143 | golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
144 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
145 | golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
146 | golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
147 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
148 | golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
149 | golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
150 | golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
151 | golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
152 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
153 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
154 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
155 | gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
156 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
157 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
158 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
159 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
160 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and`show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------