Skip to content

Instantly share code, notes, and snippets.

@StollD
Created July 18, 2016 16:52
Show Gist options
  • Save StollD/0c220c353f5332a0678ee930df8cc0bf to your computer and use it in GitHub Desktop.
Save StollD/0c220c353f5332a0678ee930df8cc0bf to your computer and use it in GitHub Desktop.
Node.js Unicode IRC Bot. Requires the node irc library.
// Unibot - IRC Bot that enforces non Unicode communication in #NoBasicLatin on Esper.NET
// Copyright (c) 2016 Dorian Stoll
// Licensed as MIT
// Messages for kicking
var messages = [
'This channel is Unicode only.',
'No basic Latin here!',
'Learn your Unicode.',
'Down with American Mainstream!'
];
var irc = require('irc')
var client = new irc.Client('irc.esper.net',
'Unibot',
{
debug: true,
autoRejoin: true,
channels: ['#NoBasicLatin']
});
// Register handlers
var authed = false;
client.addListener('names',
function (from, message) {
if (!authed) {
client.say('NickServ', "identify ##PASSWORD##");
authed = true;
}
});
function checkASCII(from, to, message) {
console.log(from + ' => ' + message);
if (isASCII(message)) {
client.send('KICK', '#NoBasicLatin', from, messages[Math.floor(Math.random() * messages.length)]);
console.warn(from + ' got kicked for using ASCII!');
}
}
client.addListener('message', checkASCII);
client.addListener('action', checkASCII);
function isASCII(str) {
if (typeof (str) !== 'string') {
return false;
}
for (var i = 0; i < str.length; i++) {
if (str.charCodeAt(i) > 127) {
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment