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"
|
2020-06-04 04:36:46 +00:00
|
|
|
"github.com/diamondburned/cchat/text"
|
2020-05-20 07:13:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Server struct {
|
2020-05-23 02:44:50 +00:00
|
|
|
session *Session
|
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-06-09 03:58:12 +00:00
|
|
|
func (sv *Server) Name() text.Rich {
|
|
|
|
return text.Rich{Content: sv.name}
|
2020-05-20 07:13:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (sv *Server) Servers(container cchat.ServersContainer) error {
|
|
|
|
container.SetServers(sv.children)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-23 02:44:50 +00:00
|
|
|
func GenerateServers(s *Session) []cchat.Server {
|
2020-06-07 17:45:14 +00:00
|
|
|
return generateServers(s, rand.Intn(45)+2)
|
2020-05-20 07:13:12 +00:00
|
|
|
}
|
|
|
|
|
2020-05-23 02:44:50 +00:00
|
|
|
func generateServers(s *Session, amount int) []cchat.Server {
|
2020-06-04 04:36:46 +00:00
|
|
|
var servers = make([]cchat.Server, amount)
|
|
|
|
for i := range servers {
|
|
|
|
servers[i] = &Server{
|
2020-05-20 07:13:12 +00:00
|
|
|
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(),
|
2020-06-07 17:45:14 +00:00
|
|
|
children: generateChannels(s, rand.Intn(12)+2),
|
2020-05-20 07:13:12 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-04 04:36:46 +00:00
|
|
|
return servers
|
2020-05-20 07:13:12 +00:00
|
|
|
}
|