forked from Cliffbreak/tsviewer
57 lines
993 B
Go
57 lines
993 B
Go
|
package service
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
|
||
|
"git.cliffbreak.de/haveachin/go-tsviewer/features/client"
|
||
|
"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 {
|
||
|
if client.ID == id {
|
||
|
c = convertClient(client)
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if c == nil {
|
||
|
return nil, errors.New("client does not exist")
|
||
|
}
|
||
|
|
||
|
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{
|
||
|
ID: c.ID,
|
||
|
DatabaseID: c.DatabaseID,
|
||
|
Nickname: c.Nickname,
|
||
|
Type: c.Type,
|
||
|
Away: c.Away,
|
||
|
AwayMessage: c.AwayMessage,
|
||
|
}
|
||
|
}
|