Advanced IRC Chat Guide

From Remeis-Wiki
Jump to navigation Jump to search
Advanced IRC Chat Guide

This article describes, how to set up the [[1]] IRC client to join the Remeis-chat at startup. In addition, the Irssi session is embedded within a [[2]] session in order to avoid joining and leaving the chat (if one uses a computer at the observatory or, in general, one which is never powered off). As an advantage, messages in the chat, which has been sent "over night", can be read the next day. Finally as the cherry on top, a simple [[3]] script will either create a new screen-Irssi session or use a running one. This script is at the end executed automatically after starting a new [[4]] session.
It is recommended to read [Guide to Efficiently Using Irssi and Screen] for further informations and to even do more tricks.

Irssi autojoin at startup

In the following, an Irssi-configuration file will be described, which allows to automatically join the Remeis-chat. Further informations about the configuration files can be found in the [documentation].

Create a default configuration
First of all, configuration files are saved in the hidden folder .irssi in the user's home directory. If it does not exist, don't worry. Irssi will create it automatically if we call it to explicitly use a configuration file:

 irssi --config=~/.irssi/remeis

This will create a default configuration file remeis, which will be edited to automatically join the Remeis-chat. But first of all, the opened Irssi session has to be closed by, e.g., entering

 /exit

into the Irssi command line.

Setting up autojoin
Once the previously created configuration file remeis is opened with an editor of choice, several lines has to be added and/or modified. By default, the file contains several configurations already. The goal is to add a server, a chatnet, a channel and a window to the file. Each of these are configured similar to a structure in S-Lang. Those structures can be grouped to an array also:

 configuration = {
   field1 = value1;
   ...
 };
 
 array_of_configurations = (
   { field = value; ... },
   ...
 );

To get the Remeis-chat working, the server irc.freenode.net has to be added first to the servers array:

 servers = (
   ...
   { address = "irc.freenode.net"; chatnet = "freenode"; port = "6667"; autoconnect = "yes"; }
 )

The field autoconnect = "yes" causes Irssi to connect to that server at startup. This server is also assign to the chatnet = "freenode", which has to be added to the corresponding structure:

 chatnets = {
   ...
   freenode = { type = "IRC"; };
 };

Here, the freenode chatnet itself is a structure, making chatnets a structure of structures. Now that a chatnet exists, which will be applied to the server irc.freenode.net, we can add channels to it via the channels array:

 channels = (
   ...
   { name = "#remeis"; chatnet = "freenode"; autojoin = "yes"; }
 )

The last thing one has to do now, is to create a new window at startup via the windows structure, which will join the previously defined channel #remeis:

 windows = {
   1 = {
     items = (
       {
         type = "CHANNEL";
         chat_type = "IRC";
         name = "#remeis";
         tag = "freenode";
       }
     );
   }

This will use the first window in Irssi (the dafault one) to connect to the Remeis-chat. Finally, one should set a proper nickname within the core structure, which itself is found within the settings structure. That's it! But remember, Irssi has to be called with this configuration file as parameter:

 irssi --config=~/.irssi/remeis
 
Irssi in a screen session

Screen can be used to open one or multiple virtual shells within an active shell. Each virtuell shell can be detached from the active shell, which sends it into the background. Even more, the virtual shell is independent from the active shell, which means that it is not terminated after active shell is closed! In combination with Irssi (or any other IRC client), the user will stay in the chat even he or she logs out from the system! This has several advantages:

 * messages sent after the user logged out can still be read after the screen session is attached again
 * reduces the join/left messages within the chat (reduces spam for the user users, doesn't it?)

The command to create a new screen session, where itself Irssi is used to connect to the Remeis-chat using the configuration file above, is simply:

 screen irssi --config=~/.irssi/remeis

The Irssi session will not look different compared if one does not use screen, but there is, among others, a shortcut available, which detaches the virtual shell:

 Ctrl + A + D

Now, Irssi will continue working in the background and independent from the active shell. To attach this virtual shell again, one may use

 screen -r -d

in any other active shell. This will bring up the Irssi session and one is able to read, what happened since the session was detached.

screen-Irssi Bash-script

Now, it would be very comfortable to simply run one command, which either creates a new screen-Irssi session or detaches an existing one. Here, the script is not described step by step, instead the full (and hopefully working) code is shown in the following. Simple copy and paste it into any file, e.g., ~/bin/runIrcChat:

 #!/bin/bash
 # runs either irssi in a screen session or (re)attaches an active one
 set irssi_session_name=remeis_irssi_$USER
 #only execute on ara
 #if "$HOST" != "ara" ; then exit; fi
 # run screen if no session exists
 run=`screen -list | grep .$irssi_session_name`
 if "$run" == "" ; then
   echo "running new irssi screen session: $irssi_session_name"
   xterm -title '#remeis@irc.freenode.net' -e "screen -S $irssi_session_name irssi --config=~/.irssi/remeis"
 else
 # otherwise, attach the session
   echo "attaching irssi screen session: $irssi_session_name"
   xterm -title '#remeis@irc.freenode.net' -e "screen -r -d $irssi_session_name"
 fi

Finally, the above script file has to be made executable:

 chmod +x ~/bin/runIrcChat

Note, that for personal liking and hostoric reasons, the screen session is created in an xterm session. Who doesn't like xterm may modify the corresponding lines, of course.

KDE autostart of Bash-script

To execute the above script automatically after the user logs into KDE, a symbolic link has to be created in the KDE-autostart folder:

 ln -s ~/bin/runIrcChat ~/.kde/Autostart/

Unbelievable, but that's all! Now each time the user logs into KDE, a window will open showing the Remeis-IRC-chat! To even configure the stuff further, one may right-click on the window's title, select Advanced -> Special Window Settings... Using the slide Geometry, the xterm window titled "#remeis@irc.freenode.net" can be configured such, that it will appear, e.g., on Desktop 4 always at initialization or with a different window size, like 800x600 pixels. There are many possibilities for personal likings...

To prevent the script to be executed on another host than ones (usual) working machine, the following line may be added to the beginning of the script:

 if "$HOST" != "ara" ; then exit; fi

Here, 'ara' has to be replaced with the proper hostname of the working machine. This modifications is quite useful, if you log into several machines simultaneously.