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/03 05:52] nanodano | programming:irc [2022/03/13 16:49] (current) nanodano | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| IRC stands for Internet Relay Chat. | IRC stands for Internet Relay Chat. | ||
| - | ===== DevDungeon IRC Server ===== | ||
| - | |||
| - | Connect to the DevDungeon IRC server at '' | ||
| - | |||
| - | < | ||
| - | irc.devdungeon.com | ||
| - | </ | ||
| ===== 2-minute Intro to IRC ===== | ===== 2-minute Intro to IRC ===== | ||
| Line 19: | Line 12: | ||
| </ | </ | ||
| + | ===== Using IRC with netcat ===== | ||
| + | |||
| + | < | ||
| + | < | ||
| + | <iframe width=" | ||
| + | </ | ||
| + | </ | ||
| ===== Basics ===== | ===== Basics ===== | ||
| Line 48: | Line 48: | ||
| * [[https:// | * [[https:// | ||
| * [[other: | * [[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(' | ||
| + | } | ||
| + | |||
| + | }); | ||
| + | </ | ||