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 06:05] 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 ===== | ||
| - | If you're looking for an existing | + | ===== 2-minute Intro to IRC ===== | 
| + | |||
| + | < | ||
| + | < | ||
| + | <iframe width=" | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== Using IRC with netcat ===== | ||
| + | |||
| + | < | ||
| + | < | ||
| + | <iframe width=" | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ===== Basics ===== | ||
| + | |||
| + | Once you are connected to an IRC server | ||
| + | Commands start with a '' | ||
| + | |||
| + | * ''/ | ||
| + | * ''/ | ||
| + | * ''/ | ||
| + | * ''/ | ||
| + | * ''/ | ||
| + | * ''/ | ||
| + | |||
| + | Other commands: | ||
| + | |||
| + | * ''/ | ||
| + | * ''/ | ||
| + | * ''/ | ||
| + | * ''/ | ||
| - | < | ||
| - | irc.devdungeon.com | ||
| - | </ | ||
| ===== Clients ===== | ===== Clients ===== | ||
| - | Recommended | + | There are many clients | 
| * [[http:// | * [[http:// | ||
| - | * [[https:// | + | * [[https:// | 
| - | * [[https:// | + | * [[other:irssi_terminal_chat|irssi]] (Terminal) - For Windows, use Debian WSL. In Debian, install with '' | 
| + | * netcat - You can use netcat as a client if you understand the IRC protocol. Check out my video tutorial [[https:// | ||
| - | ==== Basics ==== | ||
| - | Commands start with a ''/'' | + | ===== Node.js Bot ===== | 
| - | * ''/ | + | <code javascript simple_irc_bot.js> | 
| - | * ''/ | + | var net = require('net'); | 
| - | * '' | + | |
| - | * '' | + | |
| - | * '' | + | |
| - | * '' | + | |
| - | Tag someone by starting the message with their username and a colon. This will usually ping their client and is similar to tagging someone. | + | var BOT_NAME = ' | 
| + | var BOT_CHANNEL = '# | ||
| - | < | + | var client = new net.Socket(); | 
| - | nanodano: hey! | + | |
| - | </ | + | |
| - | ==== Other commands ==== | + | client.connect(6667, | 
| + | client.write(' | ||
| + | client.write(' | ||
| - |  | + |  | 
| - |  | + | client.write('JOIN ' | 
| - | * ''/ | + |  | 
| - | * ''/ | + | }, 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(' | ||
| + | } | ||
| + | }); | ||
| + | </ | ||