Last active
August 16, 2018 06:43
-
-
Save kupp1/6ae2678a3b020e0cfcc26b459b17903c to your computer and use it in GitHub Desktop.
coffeescript irc (telnet) sample
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
net = require 'net' | |
host = 'irc.run.net' | |
port = 6660 | |
pingRegExp = RegExp("^PING : #{host}\r\n$") | |
sendMsg = (socket, data) -> | |
socket.write(data + '\r\n') | |
matchPing = (data) -> | |
match = pingRegExp.test(data) | |
return match | |
connection = net.createConnection port, host | |
connection.on 'connect', () -> | |
console.log "Opened connection to #{host}:#{port}." | |
sendMsg connection, 'NICK kupp[test]' | |
sendMsg connection, 'USER test test test :test test' | |
stdin = process.stdin | |
stdin.setEncoding 'utf8' | |
connection.on 'data', (data) -> | |
message = "#{data}" | |
console.log message | |
if matchPing message | |
sendMsg connection, 'PONG :' + host | |
stdin = process.openStdin() | |
stdin.on 'data', (data) -> | |
sendMsg connection, data | |
connection.on 'end', (data) -> | |
console.log 'Connection closed' | |
process.exit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment