Clean up BaseCommand interface. Make NickServ a Service.

This commit is contained in:
Jeremy Latt 2013-05-09 09:12:03 -07:00
parent 4b0cfa816c
commit 39f815df01
5 changed files with 79 additions and 77 deletions

View file

@ -10,28 +10,27 @@ type ServiceCommand interface {
HandleService(*Service)
}
type PrivMsgCommandFunc func(*PrivMsgCommand)
type Service struct {
server *Server
name string
commands chan<- ServiceCommand
Handle PrivMsgCommandFunc
}
func NewService(s *Server, name string, Handle PrivMsgCommandFunc) *Service {
func NewService(s *Server, name string) *Service {
commands := make(chan ServiceCommand)
service := &Service{
server: s,
name: name,
commands: commands,
Handle: Handle,
}
go service.receiveCommands(commands)
s.services[name] = service
return service
}
func (service *Service) HandleMsg(m *PrivMsgCommand) {
}
func (service *Service) receiveCommands(commands <-chan ServiceCommand) {
for command := range commands {
log.Printf("%s %T %+V", service.Id(), command, command)
@ -60,5 +59,5 @@ func (service *Service) Reply(client *Client, message string) {
//
func (m *PrivMsgCommand) HandleService(s *Service) {
s.Handle(m)
s.HandleMsg(m)
}