Skip to content

Commit

Permalink
feat: Using ChatPotte for crafting notification
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Apr 18, 2022
1 parent 94a4622 commit cfdf8a3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 67 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ViBiOh/fibr
go 1.18

require (
github.com/ViBiOh/ChatPotte v0.0.3
github.com/ViBiOh/ChatPotte v0.0.6
github.com/ViBiOh/absto v0.5.5
github.com/ViBiOh/auth/v2 v2.12.5
github.com/ViBiOh/exas v0.4.1
Expand All @@ -29,8 +29,8 @@ require (
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.14.2 // indirect
github.com/klauspost/cpuid/v2 v2.0.11 // indirect
github.com/klauspost/compress v1.14.1 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/minio-go/v7 v7.0.23 // indirect
Expand All @@ -53,5 +53,5 @@ require (
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
google.golang.org/protobuf v1.27.1 // indirect
gopkg.in/ini.v1 v1.66.4 // indirect
gopkg.in/ini.v1 v1.66.3 // indirect
)
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/ViBiOh/ChatPotte v0.0.3 h1:W6n93tMRdXR7/CfcvAyDD5NLgTnBPp520og3a6+2ufo=
github.com/ViBiOh/ChatPotte v0.0.3/go.mod h1:uYz4qfDDARGn+swAPZJJ1K41TBWxwZ2g+YY1LgJ/e8s=
github.com/ViBiOh/ChatPotte v0.0.6 h1:SvglTFvA0hSlnredARkut16Xu/lYw8F1bm39l0M7eVo=
github.com/ViBiOh/ChatPotte v0.0.6/go.mod h1:uYz4qfDDARGn+swAPZJJ1K41TBWxwZ2g+YY1LgJ/e8s=
github.com/ViBiOh/absto v0.5.5 h1:gKLJNHOG96vBiK7KvoW0fMszuwtRPlflxFHmT7GGbHs=
github.com/ViBiOh/absto v0.5.5/go.mod h1:z34OebEK3OVuEnRGwfk1ggjM5NRe6qd7ytqA1X4RGIM=
github.com/ViBiOh/auth/v2 v2.12.5 h1:agTnD5A4o9kW4VA/BHpXCIzXv7OLHFdcVMWhE040IBA=
Expand Down Expand Up @@ -177,12 +177,12 @@ github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/X
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.14.2 h1:S0OHlFk/Gbon/yauFJ4FfJJF5V0fc5HbBTJazi28pRw=
github.com/klauspost/compress v1.14.2/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/compress v1.14.1 h1:hLQYb23E8/fO+1u53d02A97a8UnsddcvYzq4ERRU4ds=
github.com/klauspost/compress v1.14.1/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.11 h1:i2lw1Pm7Yi/4O6XCSyJWqEHI2MDw2FzUK6o/D21xn2A=
github.com/klauspost/cpuid/v2 v2.0.11/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
Expand Down Expand Up @@ -563,8 +563,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.66.4 h1:SsAcf+mM7mRZo2nJNGt8mZCjG8ZRaNGMURJw7BsIST4=
gopkg.in/ini.v1 v1.66.4/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.66.3 h1:jRskFVxYaMGAMUbN0UZ7niA9gzL9B49DOqE78vg0k3w=
gopkg.in/ini.v1 v1.66.3/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
33 changes: 9 additions & 24 deletions pkg/webhook/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/ViBiOh/ChatPotte/discord"
"github.com/ViBiOh/ChatPotte/slack"
absto "github.com/ViBiOh/absto/pkg/model"
"github.com/ViBiOh/fibr/pkg/provider"
"github.com/ViBiOh/fibr/pkg/thumbnail"
Expand Down Expand Up @@ -118,9 +119,7 @@ func (a *App) discordHandle(ctx context.Context, webhook provider.Webhook, event

func (a *App) slackHandle(ctx context.Context, webhook provider.Webhook, event provider.Event) (int, error) {
if event.Type != provider.UploadEvent && event.Type != provider.RenameEvent {
return send(ctx, webhook.ID, request.Post(webhook.URL), slackPayload{
Text: a.eventText(event),
})
return send(ctx, webhook.ID, request.Post(webhook.URL), slack.NewResponse(a.eventText(event)))
}

url := event.GetURL()
Expand All @@ -130,40 +129,26 @@ func (a *App) slackHandle(ctx context.Context, webhook provider.Webhook, event p
}

var description string
fields := []slackText{newText(fmt.Sprintf("*item*\n%s", event.GetName()))}
var extraField slack.Text

switch event.Type {
case provider.UploadEvent:
description = "💾 A file has been uploaded"
case provider.RenameEvent:
description = "✏️ An item has been renamed"
fields = append(fields, newText(fmt.Sprintf("*to*\n%s", event.GetTo())))
extraField = slack.NewText(fmt.Sprintf("*to*\n%s", event.GetTo()))
}

section := slackSection{
Type: "section",
Text: newText(description),
Fields: fields,
section := slack.NewSection(slack.NewText(description)).AddField(slack.NewText(fmt.Sprintf("*item*\n%s", event.GetName())))
if len(extraField.Text) != 0 {
section = section.AddField(extraField)
}

if a.thumbnailApp.CanHaveThumbnail(event.Item) {
section.Accessory = &slackImage{
Type: "image",
URL: url + "?thumbnail",
Alt: fmt.Sprintf("Thumbnail of %s", event.Item.Name),
}
section.Accessory = slack.NewAccessory(url+"?thumbnail", fmt.Sprintf("Thumbnail of %s", event.Item.Name))
}

return send(ctx, webhook.ID, request.Post(webhook.URL), slackPayload{
Text: a.eventText(event),
Blocks: []slackSection{
{
Type: "section",
Text: newText(fmt.Sprintf("*<%s?browser|%s>*", url, title)),
},
section,
},
})
return send(ctx, webhook.ID, request.Post(webhook.URL), slack.NewResponse(a.eventText(event)).AddBlock(slack.NewSection(slack.NewText(fmt.Sprintf("*<%s?browser|%s>*", url, title)))).AddBlock(section))
}

func (a *App) telegramHandle(ctx context.Context, webhook provider.Webhook, event provider.Event) (int, error) {
Expand Down
31 changes: 0 additions & 31 deletions pkg/webhook/slack.go

This file was deleted.

0 comments on commit cfdf8a3

Please sign in to comment.