remove UI stuff, turn into CLI
[barnard.git] / client.go
1 package main
2
3 import (
4         "fmt"
5         "net"
6         "os"
7
8         "layeh.com/gumble/gumble"
9         "layeh.com/gumble/gumbleopenal"
10         "layeh.com/gumble/gumbleutil"
11 )
12
13 func (b *Barnard) start() {
14         b.Config.Attach(gumbleutil.AutoBitrate)
15         b.Config.Attach(b)
16
17         var err error
18         _, err = gumble.DialWithDialer(new(net.Dialer), b.Address, b.Config, &b.TLSConfig)
19         if err != nil {
20                 fmt.Fprintf(os.Stderr, "%s\n", err)
21                 os.Exit(1)
22         }
23
24         // Audio
25         if os.Getenv("ALSOFT_LOGLEVEL") == "" {
26                 os.Setenv("ALSOFT_LOGLEVEL", "0")
27         }
28         if stream, err := gumbleopenal.New(b.Client); err != nil {
29                 fmt.Fprintf(os.Stderr, "%s\n", err)
30                 os.Exit(1)
31         } else {
32                 b.Stream = stream
33         }
34 }
35
36 func (b *Barnard) OnConnect(e *gumble.ConnectEvent) {
37         b.Client = e.Client
38
39         b.UpdateInputStatus(fmt.Sprintf("To: %s", e.Client.Self.Channel.Name))
40         b.AddOutputLine(fmt.Sprintf("Connected to %s", b.Client.Conn.RemoteAddr()))
41         if e.WelcomeMessage != nil {
42                 b.AddOutputLine(fmt.Sprintf("Welcome message: %s", esc(*e.WelcomeMessage)))
43         }
44         if (b.DefaultChannel != "") {
45                 b.Client.Self.Move(b.Client.Channels.Find(b.DefaultChannel))
46         }
47
48 }
49
50 func (b *Barnard) OnDisconnect(e *gumble.DisconnectEvent) {
51         var reason string
52         switch e.Type {
53         case gumble.DisconnectError:
54                 reason = "connection error"
55         }
56         if reason == "" {
57                 b.AddOutputLine("Disconnected")
58         } else {
59                 b.AddOutputLine("Disconnected: " + reason)
60         }
61         b.UiTree.Rebuild()
62         b.Ui.Refresh()
63 }
64
65 func (b *Barnard) OnTextMessage(e *gumble.TextMessageEvent) {
66         b.AddOutputMessage(e.Sender, e.Message)
67 }
68
69 func (b *Barnard) OnUserChange(e *gumble.UserChangeEvent) {
70         if e.Type.Has(gumble.UserChangeChannel) && e.User == b.Client.Self {
71                 b.UpdateInputStatus(fmt.Sprintf("To: %s", e.User.Channel.Name))
72         }
73         b.UiTree.Rebuild()
74         b.Ui.Refresh()
75 }
76
77 func (b *Barnard) OnChannelChange(e *gumble.ChannelChangeEvent) {
78         b.UiTree.Rebuild()
79         b.Ui.Refresh()
80 }
81
82 func (b *Barnard) OnPermissionDenied(e *gumble.PermissionDeniedEvent) {
83         var info string
84         switch e.Type {
85         case gumble.PermissionDeniedOther:
86                 info = e.String
87         case gumble.PermissionDeniedPermission:
88                 info = "insufficient permissions"
89         case gumble.PermissionDeniedSuperUser:
90                 info = "cannot modify SuperUser"
91         case gumble.PermissionDeniedInvalidChannelName:
92                 info = "invalid channel name"
93         case gumble.PermissionDeniedTextTooLong:
94                 info = "text too long"
95         case gumble.PermissionDeniedTemporaryChannel:
96                 info = "temporary channel"
97         case gumble.PermissionDeniedMissingCertificate:
98                 info = "missing certificate"
99         case gumble.PermissionDeniedInvalidUserName:
100                 info = "invalid user name"
101         case gumble.PermissionDeniedChannelFull:
102                 info = "channel full"
103         case gumble.PermissionDeniedNestingLimit:
104                 info = "nesting limit"
105         }
106         b.AddOutputLine(fmt.Sprintf("Permission denied: %s", info))
107 }
108
109 func (b *Barnard) OnUserList(e *gumble.UserListEvent) {
110 }
111
112 func (b *Barnard) OnACL(e *gumble.ACLEvent) {
113 }
114
115 func (b *Barnard) OnBanList(e *gumble.BanListEvent) {
116 }
117
118 func (b *Barnard) OnContextActionChange(e *gumble.ContextActionChangeEvent) {
119 }
120
121 func (b *Barnard) OnServerConfig(e *gumble.ServerConfigEvent) {
122 }