1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-mock.git synced 2024-11-09 23:54:27 +00:00
cchat-mock/server.go

53 lines
998 B
Go
Raw Normal View History

2020-05-20 07:13:12 +00:00
package mock
import (
"math/rand"
2020-05-20 21:23:44 +00:00
"strconv"
"sync/atomic"
2020-05-20 07:13:12 +00:00
"github.com/Pallinder/go-randomdata"
"github.com/diamondburned/cchat"
)
type Server struct {
session *Service
2020-05-20 21:23:44 +00:00
id uint32
2020-05-20 07:13:12 +00:00
name string
children []cchat.Server
}
var (
_ cchat.Server = (*Server)(nil)
_ cchat.ServerList = (*Server)(nil)
)
2020-05-20 21:23:44 +00:00
func (sv *Server) ID() string {
return strconv.Itoa(int(sv.id))
}
2020-05-20 07:13:12 +00:00
func (sv *Server) Name() (string, error) {
return sv.name, nil
}
func (sv *Server) Servers(container cchat.ServersContainer) error {
container.SetServers(sv.children)
return nil
}
func GenerateServers(s *Service) []cchat.Server {
return generateServers(s, rand.Intn(45))
}
func generateServers(s *Service, amount int) []cchat.Server {
var channels = make([]cchat.Server, amount)
for i := range channels {
channels[i] = &Server{
session: s,
2020-05-20 21:23:44 +00:00
id: atomic.AddUint32(&s.lastid, 1),
2020-05-20 07:13:12 +00:00
name: randomdata.Noun(),
children: generateChannels(s, rand.Intn(12)),
}
}
return channels
}