Table of Contents

IRC

IRC stands for Internet Relay Chat.

2-minute Intro to IRC

Using IRC with netcat

Basics

Once you are connected to an IRC server like irc.devdungeon.com you can start running commands. Commands start with a /. Here are the essential commands you need to know.

Other commands:

Clients

There are many clients out there, but here are a few:

Node.js Bot

simple_irc_bot.js
var net = require('net');  // https://nodejs.org/dist/latest/docs/api/net.html
 
var BOT_NAME = 'mybot2';
var BOT_CHANNEL = '#bots';
 
var client = new net.Socket();
 
client.connect(6667, 'irc.devdungeon.com', function() {
  client.write('USER ' + BOT_NAME +  ' 0 * :' + BOT_NAME + '\n');
  client.write('NICK ' + BOT_NAME + '\n'); // Must wait a second to register
 
  setTimeout(function(){ 
      client.write('JOIN ' + BOT_CHANNEL + '\n');
      client.write('PRIVMSG ' + BOT_CHANNEL + ' Hello my Node.js bot is online!\n');
   }, 3000);
 
});
 
client.on('data', function(data) {
  console.log('MESSAGE_FROM_SERVER: ' + data);
 var text = data.toString();
 var splitText = text.split(' ');
  // If data starts with PING, respond with PONG :whatever
  if (text.startsWith('PING')) {
    client.write('PONG ' + text.substring(5));  // Remove `PING ` and pong back what it sent me
    console.log('Recieved PING. PONGED.');
  } else if (splitText[1] == 'PRIVMSG') { // PM or chat room
    // If data comes from a channel (#general):
    //   :nanodano!johnd@107.181.165.217 PRIVMSG #general :Hello bot
    // If data comes from privmsg (dano):
    //   :nanodano!johnd@107.181.165.217 PRIVMSG danobot :hey
    console.log('Destination:' + splitText[2])
    // Was it a direct message or to the channel?
    if (splitText[2] == BOT_CHANNEL) {
       console.log('message was from ' + BOT_CHANNEL)
    } 
    if (splitText[2] == BOT_NAME) {
       console.log('message was directly to me (' + BOT_NAME + ')')
    }
    // Was the message a command?
    if (splitText[3].substring(1).startsWith('!')) {
      console.log('Command detected with ! prefix')
      // Cut off first character, and check command. Run appropriate function. !bitcoin. !ping !8-ball
      var command = splitText[3].substring(2).trim().toLowerCase();
      console.log('Command: `' + command + '`');
      if (command == 'ping') { 
        console.log('Ping command detected! Ponging.');
        client.write('PRIVMSG ' + BOT_CHANNEL + ' Pong\n');
      }
    }
    console.log('PrivMsg: ' + splitText[3].substring(1)); // Cut off : in front    
  } else {
    console.log('Discarded unexpected/unimportant message.');
  }
 
});

Inspircd

Inspircd is software for running your own IRC server.

Quick setup notes:

setup_inspircd.sh
# Get latest .deb from https://github.com/inspircd/inspircd/releases
cd ~
wget https://github.com/inspircd/inspircd/releases/download/v3.10.0/inspircd_3.10.0.deb10u1_amd64.deb
apt install ./inspircd_3.10.0.deb10u1_amd64.deb
cp /usr/share/doc/inspircd/inspircd.conf.example.gz ~
gunzip inspircd.conf.example.gz
mv inspircd.conf.example /etc/inspircd/inspircd.conf
echo "Welcome!" > /etc/inspircd/motd.txt
vim /etc/inspircd/inspircd.conf
  # Edit bind ip
  # Edit server name
  # Edit motd text file path to ''motd.txt''
systemctl start inspircd
# Then connect on port 6667

Anope is the partner service that should be installed for NickServ and ChanServ for people to register nicknames and channels.