Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow registering a global handler #66

Open
belak opened this issue Jul 28, 2015 · 1 comment
Open

Allow registering a global handler #66

belak opened this issue Jul 28, 2015 · 1 comment

Comments

@belak
Copy link

belak commented Jul 28, 2015

I'm working on a bot plugin framework and it would be useful to register a handler which gets all events so I can dispatch the events with a different handler type (so my own Bot object is available).

@fluffle
Copy link
Owner

fluffle commented Aug 5, 2015

There are ways to achieve this. If you take a look at the way I've done it with sp0rkle you can see an example -- though it's not a great one for your purposes cos I only really care about PRIVMSG, and I expose package-global functions from sp0rkle/bot to make life easier:

https://github.com/fluffle/sp0rkle/blob/master/bot/commandset.go#L86

^^ here is where Handle() for the commandset injects a bot.Context.

https://github.com/fluffle/sp0rkle/blob/master/bot/pollerset.go#L47

^^ pollerset does the same thing, and uses a switch to determine what to do for different events.

https://github.com/fluffle/sp0rkle/blob/master/bot/context.go#L34

^^ context() does the actual wrapping of Conn and Line.

https://github.com/fluffle/sp0rkle/blob/master/bot/bot.go#L47

^^ and here is where the various sets are registered as handlers.

If you are trying to hook all the events the bot receives to inject your own context, that's currently not possible, but I can see reasons why you might want to do that. The client doesn't expose it's own event loop either.

@StalkR has other ways of achieving the same thing: https://github.com/StalkR/goircbot

I don't have a huge amount of spare time to work on this code, but if you have a good idea and a reasonably self-contained pull request i'd be happy to look at it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants