-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
88 lines (72 loc) · 1.37 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"context"
"fmt"
"log"
"net/url"
"os"
"time"
"github.com/dazeus/dazeus-go"
)
func main() {
if len(os.Args) != 3 {
log.Printf("Usage: %s socket carddavurl", os.Args[0])
return
}
network := "kassala"
channel := "#ru"
socket := os.Args[1]
carddavurl := os.Args[2]
u, err := url.Parse(carddavurl)
if err != nil {
log.Fatal(err)
}
username := u.User.Username()
password, _ := u.User.Password()
u.User = nil
endpoint := u.String()
birthdays, err := NewBirthdays(username, password, endpoint)
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
dz, err := dazeus.Connect(socket)
if err != nil {
log.Fatal(err)
}
if err := birthdays.Start(ctx); err != nil {
log.Fatal(err)
}
for {
chs, err := dz.Channels(network)
if err != nil {
log.Fatal(err)
}
var joined bool
for _, ch := range chs {
if ch == channel {
joined = true
break
}
}
if joined {
break
}
if err := dz.Join(network, channel); err != nil {
log.Fatal(err)
}
log.Printf("Waiting until we've joined %s/%s...", network, channel)
time.Sleep(time.Second * 5)
}
for {
bs, err := birthdays.Wait(ctx)
if err != nil {
log.Fatal(err)
}
// TODO: add everyone in bs to the topic
for _, b := range bs {
log.Printf(b.Nick)
dz.Message(network, channel, fmt.Sprintf("Gefeliciteerd %s! \\o/", b.Nick))
}
}
}