This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| programming:irc [2021/06/02 08:36] nanodano | programming:irc [2022/03/13 16:49] (current) nanodano | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| IRC stands for Internet Relay Chat. | IRC stands for Internet Relay Chat. | ||
| + | |||
| + | |||
| + | ===== 2-minute Intro to IRC ===== | ||
| < | < | ||
| Line 9: | Line 12: | ||
| </ | </ | ||
| - | ===== DevDungeon | + | ===== Using IRC with netcat | 
| - | If you're looking for an existing server to join, connect to '' | + | < | 
| + | < | ||
| + | <iframe width=" | ||
| + | </ | ||
| + | </ | ||
| - | < | + | ===== Basics | 
| - | irc.devdungeon.com | + | |
| - | # or | + | |
| - | 192.53.170.182 | + | |
| - | </ | + | |
| - | + | ||
| - | ===== Clients | + | |
| - | + | ||
| - | There are many clients out there, but here are a few: | + | |
| - | + | ||
| - | * [[http:// | + | |
| - | * [[https:// | + | |
| - | * [[https:// | + | |
| - | + | ||
| - | ==== Basics | + | |
| Once you are connected to an IRC server like '' | Once you are connected to an IRC server like '' | ||
| Line 47: | Line 40: | ||
| + | |||
| + | ===== Clients ===== | ||
| + | |||
| + | There are many clients out there, but here are a few: | ||
| + | |||
| + | * [[http:// | ||
| + | * [[https:// | ||
| + | * [[other: | ||
| + | * netcat - You can use netcat as a client if you understand the IRC protocol. Check out my video tutorial [[https:// | ||
| + | |||
| + | |||
| + | ===== Node.js Bot ===== | ||
| + | |||
| + | <code javascript simple_irc_bot.js> | ||
| + | var net = require(' | ||
| + | |||
| + | var BOT_NAME = ' | ||
| + | var BOT_CHANNEL = '# | ||
| + | |||
| + | var client = new net.Socket(); | ||
| + | |||
| + | client.connect(6667, | ||
| + | client.write(' | ||
| + | client.write(' | ||
| + | |||
| + | setTimeout(function(){ | ||
| + | client.write(' | ||
| + | client.write(' | ||
| + | }, 3000); | ||
| + | |||
| + | }); | ||
| + | |||
| + | client.on(' | ||
| + | console.log(' | ||
| + | var text = data.toString(); | ||
| + | var splitText = text.split(' | ||
| + | // If data starts with PING, respond with PONG :whatever | ||
| + | if (text.startsWith(' | ||
| + | client.write(' | ||
| + | console.log(' | ||
| + | } else if (splitText[1] == ' | ||
| + | // If data comes from a channel (#general): | ||
| + | //   : | ||
| + | // If data comes from privmsg (dano): | ||
| + | //   : | ||
| + | console.log(' | ||
| + | // Was it a direct message or to the channel? | ||
| + | if (splitText[2] == BOT_CHANNEL) { | ||
| + |  | ||
| + | } | ||
| + | if (splitText[2] == BOT_NAME) { | ||
| + |  | ||
| + | } | ||
| + | // Was the message a command? | ||
| + | if (splitText[3].substring(1).startsWith(' | ||
| + | console.log(' | ||
| + | // Cut off first character, and check command. Run appropriate function. !bitcoin. !ping !8-ball | ||
| + | var command = splitText[3].substring(2).trim().toLowerCase(); | ||
| + | console.log(' | ||
| + | if (command == ' | ||
| + | console.log(' | ||
| + | client.write(' | ||
| + | } | ||
| + | } | ||
| + | console.log(' | ||
| + | } else { | ||
| + | console.log(' | ||
| + | } | ||
| + | |||
| + | }); | ||
| + | </ | ||