Previous Section  < Day Day Up >  Next Section

Hack 44 Infer Social Networks from IRC

figs/beginner.gif figs/hack44.gif

Most IRC channels are like small communities, and communities make patterns. Use this hack to produce pretty drawings of the social structure in your channel.

If you see a group of people talking to one another in real life, it is reasonable to assume there is some kind of relationship or friendship between them. The same principles can be applied to IRC channels. By drawing lines between users, you can produce some interesting visualizations of the social networks present.

PieSpy (http://www.jibble.org/piespy) is a tool that can be used to generate these diagrams automatically. It is an IRC bot that monitors a set of channels and attempts to estimate what the social network structure should look like. It does this by guessing who is talking to whom. The name of the bot originates from a channel called #pie, where it was first used to "spy" on the channel inhabitants and produce social network diagrams.

7.2.1 Installing PieSpy

You can download PieSpy from http://www.jibble.org/piespy. It is precompiled, but the source code is also available if you feel like hacking it yourself. Unzip the archive into a new directory.

If you have Java installed, the bot is ready to run by executing the run.bat file on Windows or run.sh on Linux/Unix.

The README.txt file briefly describes the bot and the commands that it accepts.

7.2.2 Configuring PieSpy

All configuration settings are specified in config.ini. Open this file in your favorite text editor.

You will need to change the server settings so you can tell the bot which server to connect to, which channel to join and so on:

# Server Settings:



Nick = HackSpy

Server = irc.freenode.net

ServerPassword = 

Port = 6667

ChannelSet = #irchacks

The Nick field sets the nickname of the bot. The bot will connect to the specified Port on the Server, using the ServerPassword if required (some IRC servers are password protected). When the bot connects to the server, it will join all channels listed in the ChannelSet.

PieSpy is capable of running in multiple channels. If you want to add extra channels to the ChannelSet, simply separate them with commas, for example:

ChannelSet = #irchacks,#jibble

You need to change just one other setting, the administrator password:

# Administrator settings:



Password = password

The default value is "password," so you may wish to change it. This is the password that is used to remotely control the bot over IRC.

7.2.3 Running PieSpy

Windows users can run PieSpy by double-clicking on the run.bat file. On Linux/Unix, you can run PieSpy by executing the run.sh script, like so:

% chmod u+x run.sh % ./run.sh

The bot will then connect to the server and join the appropriate channels.

If you are running the bot in a Linux/Unix terminal window without access to an X server, you may need to edit run.sh so that it has -Djava.awt.headless=true as a parameter to the java command. If you do not do this, the bot will be unable to draw anything!


7.2.4 Getting Output from PieSpy

PieSpy will generate output in PNG (Portable Network Graphics) format. All modern web browsers can view these types of files. The default output directory is ./images/, and the bot will create new directories inside this one for each channel it's in.

Each time the bot detects a change in the structure of the social network for a channel, it will write a new image. If your bot is in #irchacks, the most recent image for that channel will always be called irchacks-current.png. An archive is also kept, allowing you to piece together frames to create animations. Archive images are saved as irchacks-00000000.png, irchacks-00000001.png, and so on.

The bot will also save a file called irchacks-restore.dat. This contains information about the data used to create the images and allows the bot to save its state between invocations. If your machine crashes for some reason, you can restart the bot, and it will continue from where it left off without having to rebuild the social network from scratch.

If your output directory is visible to a web server, you can tell people to look at irchacks-current.png, and they will always see the latest state of the social network for #irchacks.

7.2.5 Controlling PieSpy

PieSpy can be controlled remotely if you know the administrator password. If you have left it as the default of "password," other people may be able to take control of your bot.

Each command you send to the bot must be sent as a private message. For example, you can get information about the graphs being made by the bot by sending the stats command. Each command must be prefixed by the password, like so:

/msg HackSpy  password  stats

The bot will respond by saying how much data it has collected for each channel:

<HackSpy> #irchacks: Graph: 11 nodes and 0 edges.

<HackSpy> #jibble: Graph: 17 nodes and 6 edges.

If there are not yet any edges in the graph, the bot will not be able to generate any output. You will have to wait until people start chatting in that channel.

If you want to remove the bot from a channel, send the part command:

/msg HackSpy  password  part #irchacks 

* HackSpy has left #irchacks

To make the bot go back to that channel, send the join command:

/msg HackSpy  password  join #irchacks * HackSpy has joined #irchacks

If someone is being silly on the channel and you want the bot to ignore her, you can add her nickname to the ignore list in config.ini. You can also add nicknames to the bot's ignore list while it is running, by using the ignore command. It is sometimes useful to add so-called welcome bots to the ignore list; otherwise, they end up looking rather popular with everybody:

/msg HackSpy  password  ignore WelcomeBot

WelcomeBot will now be ignored whenever it says anything, so it won't be included in the social network. If WelcomeBot already existed in the graph, it would have been removed when you used the ignore command.

If you do not have direct access to the file store on which the bot is running, you can tell it to send you the current image via DCC:

/msg HackSpy   password  draw  #jibble 

<HackSpy> Trying to send "jibble-00000014.png"... If you have difficulty in

    receiving this file via DCC, there may be a firewall between us.

The bot will then send the file to you via DCC. Note the warning about firewalls—if you are unable to connect directly to the bot, you will not be able to receive the image.

Using the raw command, you can tell the bot to send a raw line to the IRC server. If you know enough about the IRC protocol, you will be able to get the bot to do practically anything you want with this command. For example, to get the bot to send a message to the channel, you could do this:

/msg HackSpy  

password

 raw PRIVMSG #irchacks  :Hello, I'm a PieSpy bot! 

7.2.6 The Results

When you look at the output from the PieSpy bot, you will see a collection of nodes scattered about. Some of these nodes will have lines connecting them to show that there is some kind of relationship present.

The diagram shown in Figure 7-1 was taken a couple of days after the O'Reilly Emerging Technology Conference in 2004. A large number of attendees used the channel to chat with one another. The graph shows only the active users at that time. In particular, note how popular the user "jibot" seems—jibot is an IRC bot that introduces people when they join the channel, so PieSpy infers relationships between them.

Figure 7-1. PieSpy running in #etech after the O'Reilly Emerging Technology Conference in 2004
figs/irch_0701.gif


Strong relationships are represented with thicker, shorter lines with more opacity. PieSpy uses temporal decay to ensure that each relationship slowly fades away over time, resulting in much more exciting animations. If you are feeling adventurous, you can try changing the temporal decay settings in the config.ini file.

    Previous Section  < Day Day Up >  Next Section