Skip to content

Commit b2e6e74

Browse files
committed
Migrate to using jcal
* Updates dockerfile for timezone * Updates templates * Update github workflow
1 parent 58d9898 commit b2e6e74

File tree

12 files changed

+138
-2781
lines changed

12 files changed

+138
-2781
lines changed

.github/workflows/go.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ jobs:
1919
timezoneMacos: "Europe/Berlin"
2020
timezoneWindows: "Europe/Berlin"
2121
- name: Set up Go
22-
uses: actions/setup-go@v3
22+
uses: actions/setup-go@v5
2323
with:
24-
go-version: 1.19.6
24+
go-version: 1.22
2525
cache: true
2626
- name: Test
2727
run: go test -v ./...

Dockerfile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
##
22
## Build
33
##
4-
FROM golang:1.18-alpine AS build
4+
FROM golang:1.22-alpine AS build
55

66
WORKDIR /app
77

@@ -22,6 +22,7 @@ FROM alpine
2222

2323
WORKDIR /
2424
RUN apk add --no-cache tzdata
25+
RUN ln -s /usr/share/zoneinfo/Europe/Berlin /etc/localtime
2526
RUN adduser -D calendar-bot
2627
USER calendar-bot
2728
COPY --from=build /calendar-bot /calendar-bot

cmd/calendar-bot/calendar-bot.go

+18-8
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ import (
1818

1919
const flags = log.Ldate | log.Ltime | log.Lmsgprefix
2020

21-
var errLog = log.New(os.Stderr, "[ERROR] ", flags|log.Lshortfile)
22-
var infoLog = log.New(os.Stdout, "[INFO] ", flags)
21+
var (
22+
errLog = log.New(os.Stderr, "[ERROR] ", flags|log.Lshortfile)
23+
infoLog = log.New(os.Stdout, "[INFO] ", flags)
24+
)
2325

24-
var configFile = flag.String("config", "", "Path to config file")
25-
var htmlTmplPath = flag.String("html", "", "Path to html template file")
26-
var txtTmplPath = flag.String("txt", "", "Path to txt template file")
26+
var (
27+
configFile = flag.String("config", "", "Path to config file")
28+
htmlTmplPath = flag.String("html", "", "Path to html template file")
29+
txtTmplPath = flag.String("txt", "", "Path to txt template file")
30+
)
2731

2832
func main() {
2933
flag.Parse()
@@ -94,15 +98,17 @@ func main() {
9498
timezone := time.Local
9599
s := gocron.NewScheduler(timezone)
96100
infoLog.Printf("Scheduling notifications for %s", notifyTime.Format("15:04"))
97-
s.Every(1).Day().At(notifyTime).Do(func() {
101+
_, err = s.Every(1).Day().At(time.Now().Add(2 * time.Second)).Do(func() {
98102
infoLog.Println("Start Notification")
99-
cal, err := calendar.ImportCalendar(conf.Calendar, infoLog)
103+
cal, err := calendar.NewNextcloudCalendar(conf.Calendar)
100104
if err != nil {
101-
errLog.Printf("Could not read calendar info from %s\n", conf.Calendar)
105+
errLog.Println(err)
106+
return
102107
}
103108
todayEvents, err := cal.GetEventsOn(time.Now())
104109
if err != nil {
105110
errLog.Println(err)
111+
return
106112
}
107113
if len(todayEvents) == 0 {
108114
infoLog.Println("No events today!")
@@ -127,5 +133,9 @@ func main() {
127133
}
128134
}
129135
})
136+
if err != nil {
137+
errLog.Println(err)
138+
return
139+
}
130140
s.StartBlocking()
131141
}

go.mod

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
module github.com/gueldenstone/calendar-bot
22

3-
go 1.18
3+
go 1.23.0
44

55
require (
6-
github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f
7-
github.com/go-co-op/gocron v1.13.0
6+
github.com/go-co-op/gocron v1.37.0
7+
github.com/xHain-hackspace/go-jcal v0.0.3
88
gopkg.in/yaml.v3 v3.0.1
99
maunium.net/go/mautrix v0.11.0
1010
)
1111

1212
require (
13-
github.com/kr/text v0.2.0 // indirect
14-
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
13+
github.com/google/uuid v1.4.0 // indirect
1514
github.com/robfig/cron/v3 v3.0.1 // indirect
16-
github.com/teambition/rrule-go v1.7.2 // indirect
15+
go.uber.org/atomic v1.9.0 // indirect
1716
golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9 // indirect
1817
golang.org/x/net v0.0.0-20220513224357-95641704303c // indirect
19-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
20-
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
2118
)

go.sum

+32-13
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,49 @@
11
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
2+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
23
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3-
github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f h1:feGUUxxvOtWVOhTko8Cbmp33a+tU0IMZxMEmnkoAISQ=
4-
github.com/emersion/go-ical v0.0.0-20220601085725-0864dccc089f/go.mod h1:2MKFUgfNMULRxqZkadG1Vh44we3y5gJAtTBlVsx1BKQ=
5-
github.com/go-co-op/gocron v1.13.0 h1:BjkuNImPy5NuIPEifhWItFG7pYyr27cyjS6BN9w/D4c=
6-
github.com/go-co-op/gocron v1.13.0/go.mod h1:GD5EIEly1YNW+LovFVx5dzbYVcIc8544K99D8UVRpGo=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
5+
github.com/go-co-op/gocron v1.37.0 h1:ZYDJGtQ4OMhTLKOKMIch+/CY70Brbb1dGdooLEhh7b0=
6+
github.com/go-co-op/gocron v1.37.0/go.mod h1:3L/n6BkO7ABj+TrfSVXLRzsP26zmikL4ISkLQ0O8iNY=
7+
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
8+
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
9+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
10+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
11+
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
12+
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
713
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
814
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
915
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1016
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
11-
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
12-
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
17+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
1318
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
19+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1420
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
1521
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
16-
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
17-
github.com/teambition/rrule-go v1.7.2 h1:goEajFWYydfCgavn2m/3w5U+1b3PGqPUHx/fFSVfTy0=
18-
github.com/teambition/rrule-go v1.7.2/go.mod h1:mBJ1Ht5uboJ6jexKdNUJg2NcwP8uUMNvStWXlJD3MvU=
22+
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
23+
github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg=
24+
github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o=
25+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
26+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
27+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
28+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
29+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
30+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
31+
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
32+
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
33+
github.com/xHain-hackspace/go-jcal v0.0.3 h1:2FcfP0FimmhMOUCHQ6uXCWgNJnk3OQImbZSFKt8zBbI=
34+
github.com/xHain-hackspace/go-jcal v0.0.3/go.mod h1:TtrDntq5LuHqIYYnPTBmM5fAD0EMWRf+ZS7H+3XpwHM=
35+
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
36+
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
1937
golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9 h1:NUzdAbFtCJSXU20AOXgeqaUwg8Ypg4MPYmL+d+rsB5c=
2038
golang.org/x/crypto v0.0.0-20220513210258-46612604a0f9/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
2139
golang.org/x/net v0.0.0-20220513224357-95641704303c h1:nF9mHSvoKBLkQNQhJZNsc66z2UzAMUbLGjC95CF3pU0=
2240
golang.org/x/net v0.0.0-20220513224357-95641704303c/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
23-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
24-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
2541
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
26-
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
27-
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
42+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
43+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
44+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
45+
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
46+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2847
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
2948
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3049
maunium.net/go/mautrix v0.11.0 h1:B1FBHcvE4Mud+AC+zgNQQOw0JxSVrt40watCejhVA7w=

internal/config/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99

1010
type Config struct {
1111
Homeserver string `yaml:"homeserver"`
12-
Rooms []string `yaml:"rooms"`
1312
Calendar string `yaml:"calendarURL"`
1413
NotifyTime string `yaml:"nofifyTime"`
1514
Username string `yaml:"username"`
1615
Password string `yaml:"password"`
16+
Rooms []string `yaml:"rooms"`
1717
}
1818

1919
func Parse(path string) (Config, error) {

internal/message/message.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"time"
88

99
"github.com/gueldenstone/calendar-bot/pkg/calendar"
10-
1110
"maunium.net/go/mautrix/event"
1211
)
1312

@@ -24,9 +23,9 @@ type Event struct {
2423
}
2524

2625
type TemplatedMessage struct {
27-
Events []Event
2826
htmlTemplate *template.Template
2927
txtTemplate *template.Template
28+
Events []Event
3029
}
3130

3231
func NewTemplatedMessage(htmlTemplate, txtTemplate string, events []calendar.Event, tz *time.Location) (TemplatedMessage, error) {
@@ -36,7 +35,7 @@ func NewTemplatedMessage(htmlTemplate, txtTemplate string, events []calendar.Eve
3635
Summary: evt.Summary,
3736
StartTime: evt.Start.In(tz).Format(timeLayout),
3837
EndTime: evt.End.In(tz).Format(timeLayout),
39-
HtmlDescription: strings.ReplaceAll(strings.ReplaceAll(evt.Description, "\\n", "<br>"), "\\", ""),
38+
HtmlDescription: strings.ReplaceAll(strings.ReplaceAll(evt.Description, "\n", "<br>"), "\\", ""),
4039
TxtDescription: evt.Description,
4140
}
4241

@@ -72,6 +71,7 @@ func (t TemplatedMessage) RenderTxt() (string, error) {
7271
err := t.txtTemplate.Execute(&buf, t)
7372
return buf.String(), err
7473
}
74+
7575
func (t TemplatedMessage) Render() (html string, txt string, err error) {
7676
html, err = t.RenderHtml()
7777
if err != nil {

0 commit comments

Comments
 (0)