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

Command Hooks #86

Closed
SamStudio8 opened this issue Dec 29, 2012 · 6 comments
Closed

Command Hooks #86

SamStudio8 opened this issue Dec 29, 2012 · 6 comments

Comments

@SamStudio8
Copy link
Collaborator

No description provided.

@reality
Copy link
Owner

reality commented Dec 29, 2012

This will be implemented as part of #85

@reality
Copy link
Owner

reality commented Jan 10, 2013

So we can achieve something like this relatively simply with a couple of lines in the command module, like so:

dbot.hooks[commandName].each(function(hook) {
    hook();
}.bind(this));

However, the question is - how do we pass relevant information to the hook function? For example, one of our initial hooks is going to be for fixStats upon the calling of ~mergeusers or ~setaliasparent. How do we pass the oldUser value from these commands to the fixStats hook function?

@SamStudio8
Copy link
Collaborator Author

A parameter object maybe?

On Thu, Jan 10, 2013 at 7:00 AM, Luke Slater notifications@github.comwrote:

So we can achieve something like this relatively simply with a couple of
lines in the command module, like so:

dbot.hooks[commandName].each(function(hook) {
hook(); }.bind(this));

However, the question is - how do we pass relevant information to the hook
function? For example, one of our initial hooks is going to be for fixStats
upon the calling of ~mergeusers or ~setaliasparent. How do we pass the
oldUser value from these commands to the hook function?


Reply to this email directly or view it on GitHubhttps://github.com//issues/86#issuecomment-12082987.

@reality
Copy link
Owner

reality commented Jan 10, 2013

You mean pass the params which are passed to the command? That's a little messy as then the hooks will have to do their own parsing of the input.

@reality
Copy link
Owner

reality commented Jan 15, 2013

Going to do this by having commands open to hooks return data at the end for use.

reality added a commit that referenced this issue Jan 15, 2013
* Command API function to addHook(command, callback)
* Commands open to callbacks must return information or indicate failed completion by return false
* Hooks to be added in module onLoad
* Command loop checks for available hooks and return state, then applies with module scope.
* onLoad running moved to end of all module loading to facilitate this without order problems
* Added example for ~qadd dent
@reality
Copy link
Owner

reality commented Jan 15, 2013

Completed with previous commit.

@reality reality closed this as completed Jan 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants