mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-21 18:41:58 -08:00
Clean up BaseCommand interface. Make NickServ a Service.
This commit is contained in:
parent
4b0cfa816c
commit
39f815df01
5 changed files with 79 additions and 77 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue