Created
May 14, 2024 15:37
-
-
Save ItsOnlyBinary/a171695cd33685eedfaab64a00bcc3cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var IRC = require('irc-framework'); | |
var bot = new IRC.Client(); | |
bot.use(ExampleMiddleware()); | |
// Overload connection write so we can log outgoing messages | |
let originalWrite = bot.connection.write; | |
bot.connection.write = function write(data, callback) { | |
console.log(Date.now(), '[C]', data); | |
originalWrite.apply(bot.connection, [data, callback]); | |
} | |
bot.connect({ | |
host: 'irc.freenode.net', | |
port: 6697, | |
tls: true, | |
nick: 'irc-fw-testbot' | |
}); | |
bot.on('registered', function(event) { | |
bot.join('#testers'); | |
}); | |
bot.on('message', function(event) { | |
if (event.message.indexOf('hello') === 0) { | |
event.reply('Hi!'); | |
} | |
if (event.message.match(/^!join /)) { | |
var to_join = event.message.split(' '); | |
event.reply('Joining ' + to_join + '..'); | |
bot.join(to_join); | |
} | |
}); | |
// Or a quicker to match messages... | |
bot.matchMessage(/^hi/, function(event) { | |
event.reply('hello there!'); | |
}); | |
function ExampleMiddleware() { | |
return function(client, rawEvents, parsedEvents) { | |
rawEvents.use(rawMiddleware) | |
} | |
function rawMiddleware(command, event, rawLine, client, next) { | |
console.log(Date.now(), '[S]', rawLine.trim()); | |
next(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment