go-tsviewer/service/client.go

61 lines
1.1 KiB
Go
Raw Normal View History

2019-01-15 00:46:39 +00:00
package service
import (
"errors"
2019-01-17 00:35:51 +00:00
"git.cliffbreak.de/Cliffbreak/tsviewer/features/client"
2019-01-15 00:46:39 +00:00
"github.com/multiplay/go-ts3"
)
func (s Service) Client(id int) (*client.Client, error) {
clients, err := s.TSClient.Server.ClientList()
if err != nil {
return nil, err
}
var c *client.Client
for _, client := range clients {
2019-01-16 22:07:38 +00:00
if client.DatabaseID == id {
2019-01-15 00:46:39 +00:00
c = convertClient(client)
break
}
}
if c == nil {
return nil, errors.New("client does not exist")
}
2019-01-16 22:07:38 +00:00
/* if _, err := s.TSClient.Server.ExecCmd(ts3.NewCmd(fmt.Sprintf("clientinfo clid=%d", c.ID)).WithResponse(&c)); err != nil {
return nil, err
} */
2019-01-15 00:46:39 +00:00
return c, nil
}
func (s Service) Clients() ([]*client.Client, error) {
clients, err := s.TSClient.Server.ClientList()
if err != nil {
return nil, err
}
var cc []*client.Client
for _, client := range clients {
cc = append(cc, convertClient(client))
}
return cc, nil
}
func convertClient(c *ts3.OnlineClient) *client.Client {
return &client.Client{
DatabaseID: c.DatabaseID,
2019-01-16 22:07:38 +00:00
ChannelID: c.ID,
2019-01-15 00:46:39 +00:00
Nickname: c.Nickname,
Type: c.Type,
Away: c.Away,
AwayMessage: c.AwayMessage,
}
}