-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheim-client.go
67 lines (54 loc) · 1.16 KB
/
heim-client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"time"
"euphoria.io/heim-client/client"
"euphoria.io/heim/proto"
"euphoria.io/scope"
)
var (
cookieJar = flag.String("cookies", "~/.heim/cookies", "file to save encrypted cookies in")
server = flag.String("server", "https://euphoria.io", "base URL of heim server")
)
func init() {
flag.Usage = usage
}
func usage() {
fmt.Fprintf(os.Stderr, "usage: %s [options] ROOM\n\n", filepath.Base(os.Args[0]))
flag.PrintDefaults()
}
func main() {
flag.Parse()
args := flag.Args()
if len(args) < 1 {
usage()
os.Exit(2)
}
if err := run(args[0]); err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
}
type sendReceiver struct{}
func (sendReceiver) SendEvent(event *proto.SendEvent) error {
timestamp := time.Now().Format("15:04:05")
fmt.Printf("%s (%s) [%s] %s\n", timestamp, event.Sender.ID, event.Sender.Name, event.Content)
return nil
}
func run(room string) error {
ctx := scope.New()
hc, err := client.DialRoom(ctx, *server, room)
if err != nil {
return err
}
defer hc.Close()
hc.Add(&client.Presence{})
hc.Add(&sendReceiver{})
for {
select {}
}
return nil
}