-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add class to encapsulate event listeners #29
Conversation
… into event-listener-class
862fae0
to
bc8cd1b
Compare
No longer relies on that TS issue, because I just copy-pasted Eris's event typings into the Methods for loading commands from files have been expanded to work with event listeners as well, and have also been renamed to reflect that (though the old names are still there as deprecated aliases, to be removed in the next semver-major release). All in all, this should be usable as: // someListener.ts
import {EventListener} from 'yuuko';
export default new EventListener('messageReactionAdd', (message, emoji, userID) => {
// All parameters have their types properly inferred
});
// client.ts
import {Client} from 'yuuko';
const bot = new Client({...});
bot.addFile('/path/to/someListener.ts');
// alternatively: `bot.addCommandFile('/path/to/someListener.ts');` will also work
bot.connect(); Install via |
Last few commits make the These commits also split the command handling section of the code into its own function, and provides an option to disable all default message handling so you can define a completely custom process and choose which messages you want to process commands from. For example: import {Client, EventListener} from 'yuuko';
const bot = new Client({
disableDefaultMessageListener: true, // new option
...
});
bot.on('messageCreate', message => {
// Filter out some messages
if (someBlacklist.includes(message.author.id)) return;
// Look for commands in messages that didn't get filtered - this call will execute any commands
bot.processCommand(message);
});
bot.connect(); Note that when |
This will be easy for JS consumers but relies on microsoft/TypeScript#32164 for typings to be right for TS consumers. Will also need client changes to accomodate registering event listeners in this manner.
This branch also includes the fix for #32, namely that there is now an option to disable the default command handler, allowing you to define your own message handling flow and choose whether or not to execute commands on a per-message basis separately from command requirements. This is useful for implementing blacklists or command cooldowns.