Created
July 18, 2016 16:52
-
-
Save StollD/0c220c353f5332a0678ee930df8cc0bf to your computer and use it in GitHub Desktop.
Node.js Unicode IRC Bot. Requires the node irc library.
This file contains hidden or 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
// 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