diff --git a/client.go b/client.go index 90ad5f6..2e5f58c 100644 --- a/client.go +++ b/client.go @@ -1224,9 +1224,6 @@ func (client *Client) handleEvent(event *Event) { clientHandlers := client.handlers client.mutex.RUnlock() - for _, handler := range globalHandlers { - handler(event, client) - } for _, handler := range clientHandlers { handler(event, client) } diff --git a/client_test.go b/client_test.go index bf768c3..8ad3f62 100644 --- a/client_test.go +++ b/client_test.go @@ -3,18 +3,15 @@ package irc_test import ( "context" "errors" + "github.com/gissleh/irc/handlers" "testing" "github.com/gissleh/irc" - "github.com/gissleh/irc/handlers" "github.com/gissleh/irc/internal/irctest" ) // Integration test below, brace yourself. func TestClient(t *testing.T) { - irc.AddHandler(handlers.Input) - irc.AddHandler(handlers.MRoleplay) - client := irc.New(context.Background(), irc.Config{ Nick: "Test", User: "Tester", @@ -23,6 +20,9 @@ func TestClient(t *testing.T) { SendRate: 1000, }) + client.AddHandler(handlers.Input) + client.AddHandler(handlers.MRoleplay) + t.Logf("Client.ID = %#+v", client.ID()) if client.ID() == "" { t.Fail() diff --git a/cmd/ircrepl/main.go b/cmd/ircrepl/main.go index 6f442f7..83b22c9 100644 --- a/cmd/ircrepl/main.go +++ b/cmd/ircrepl/main.go @@ -27,9 +27,6 @@ func main() { flag.Parse() - irc.AddHandler(handlers.Input) - irc.AddHandler(handlers.MRoleplay) - client := irc.New(ctx, irc.Config{ Nick: *flagNick, User: *flagUser, @@ -37,13 +34,16 @@ func main() { Password: *flagPass, }) + client.AddHandler(handlers.Input) + client.AddHandler(handlers.MRoleplay) + err := client.Connect(*flagServer, *flagSsl) if err != nil { fmt.Fprintf(os.Stderr, "Failed to connect: %s", err) } var target irc.Target - irc.AddHandler(func(event *irc.Event, client *irc.Client) { + client.AddHandler(func(event *irc.Event, client *irc.Client) { if event.Name() == "input.target" { name := event.Arg(0) diff --git a/handle.go b/handle.go index d9492e2..7099b71 100644 --- a/handle.go +++ b/handle.go @@ -3,18 +3,3 @@ package irc // A Handler is a function that is part of the irc event loop. It will receive all // events. type Handler func(event *Event, client *Client) - -var globalHandlers = make([]Handler, 0, 8) - -// AddHandler adds a new handler to the irc handling. The handler may be called from multiple threads at the same -// time, so external resources should be locked if there are multiple clients. Adding handlers is not thread -// safe and should be done prior to clients being created. Also, this handler will block the individual -// client's event loop, so long operations that include network requests and the like should be done in a -// goroutine with the needed data **copied** from the handler function. -func AddHandler(handler Handler) { - globalHandlers = append(globalHandlers, handler) -} - -func init() { - globalHandlers = make([]Handler, 0, 8) -} diff --git a/state.go b/state.go index 1f13174..45b6c58 100644 --- a/state.go +++ b/state.go @@ -23,3 +23,7 @@ type TargetState struct { Name string `json:"name"` Users []list.User `json:"users,omitempty"` } + +type EventData struct { + +} \ No newline at end of file