Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Irc = require('irc-framework');
- /**
- * Example middleware structure to handle NickServ authentication
- * Accepts a `services` object from the client connect() options
- */
- function ServiceX() {
- return function(client, raw_events, parsed_events) {
- raw_events.use(rawEventHandler);
- client.on('connecting', () => {
- var services = client.options.services;
- if (!services || !services.username) {
- return;
- }
- var modes = [];
- modes.push(services.hide_hostmask ? '+x' : '-x');
- modes.push(services.login_required ? '+!' : '-!');
- client.options.password = modes.join('') + ' ' +
- services.username + ' ' +
- services.password;
- });
- };
- function rawEventHandler(command, event, raw, client, next) {
- if (command === 'IS THERE A AUTH SUCCESS / FAIL COMMAND?') {
- client.emit('auth_success');
- }
- next();
- }
- }
- var bot = new Irc.Client();
- bot.use(ServiceX());
- bot.connect({
- host: '127.0.0.1',
- port: 6667,
- ssl: false,
- nick: 'servicextest',
- services: {
- username: 'username',
- password: 'password',
- // Service X specific options below
- login_required: true,
- hide_hostmask: true,
- },
- });
- bot.on('registered', function() {
- console.log('Connected and registered!');
- bot.join('#test');
- });
- bot.on('debug', (line) => console.log('[irc-fw] ' + line));
- bot.on('raw', (event) => console.log((event.from_server ? '[s]' : '[c]') + ' ' + event.line));
- bot.on('irc error', function(error) {
- console.log('[irc error]', error);
- });
- bot.on('close', function(had_error) {
- console.log('Connection close. had_error:', had_error);
- });
- bot.on('message', function(event) {
- var time = event.time ? new Date(event.time) : new Date();
- console.log((event.from_server?'server ':'') + time.toString() + ' <' + event.target + '/' + event.nick + '>', event.message);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement