Preface

Internet Relay Chat (IRC) has continued to grow in popularity since its inception way back in 1988. Millions of people all over the world now use IRC to chat with friends, discuss projects, and collaborate on research. With a simple, clearly defined protocol, IRC has become one of the most accessible chat environments, with clients written for a multitude of operating systems.

Users of alternative chat systems will find IRC pretty easy to pick up and may even be surprised to find that it is more powerful, allowing not just chat between pairs of users, but among groups of hundreds, even thousands. It is the scalable nature of IRC that has helped it to succeed and to make it the most mature chat system on this planet.

This book presents an opportunity to learn how IRC works and how to make best use of some of its features. IRC Hacks delves deep into the possibilities, featuring contributions from some of the most renowned IRC hackers. Many of the contributors collaborated on IRC, grouping together to form the channel #irchacks on the freenode IRC network (irc.freenode.net). We look forward to seeing you there and hearing how you’ve used this book.

Why IRC Hacks?

The term hacking has a bad reputation in the press. They use it to refer to someone who breaks into systems or wreaks havoc with computers as their weapon. Among people who write code, though, the term hack refers to a “quick-and-dirty” solution to a problem, or a clever way to get something done. And the term hacker is taken very much as a compliment, referring to someone as being creative, having the technical chops to get things done. The Hacks series is an attempt to reclaim the word, document the good ways people are hacking, and pass the hacker ethic of creative participation on to the uninitiated. Seeing how others approach systems and problems is often the quickest way to learn about a new technology.

While IRC is easy to get into, it is evident that there is a demand for better understanding. Many people are happy to use it without being aware of what’s happening beneath the scenes, but others hunger for more knowledge, and this book is for them. IRC is more than just a simple chat system—it is a network of intercommunicating servers, allowing thousands of clients to connect from anywhere in the world using the IRC protocol.

Some hacks in this book are designed to demonstrate the IRC protocol and how to exploit it—not in bad ways, but in ways that facilitate better use of IRC. Not only will you be shown how to enhance several of the most popular IRC clients, but you can also experiment with scripting some autonomous IRC clients, or IRC bots. It is quite exciting to see your very own IRC bot, crafted by your own fine hands, connecting to a server and joining a channel for the first time. Many of the hacks then show you how to add extra features to create useful or fun IRC bots.

Each hack has been created to save you time and show you how to perform new tricks on IRC without having to look up the information. This collection of hacks should appeal to people who are just about to experience IRC for the first time, as well as those who consider themselves to be more seasoned users. IRC Hacks provides hands-on solutions to problems faced, and solved, by people who use IRC on a daily basis.

How to Use This Book

You can read the book from cover to cover if you like, but you may be better served by picking an interesting item from the table of contents and just diving in.

If you’re relatively new to IRC, you should consider starting with a few hacks from each progressive chapter. Chapter 1 starts you off by showing you how to connect to IRC, while Chapter 2 acquaints you with the everyday concepts you’ll need to use IRC effectively. Chapter 3 is all about users and channels, and it introduces the first pieces of code. Chapter 4 shows you how to make useful enhancements to IRC clients. Chapter 5 is where you will learn the basics about creating IRC bots, with Chapter 6-Chapter 12 introducing more complex bots that can be used for logging, servicing communities, searching, announcing, networking, managing channels, or simply having fun. Chapter 13 delves into the IRC protocol in more detail, and Chapter 14 demonstrates some interesting alternative methods for connecting to IRC. Finally, Chapter 15 will move you on to new pastures by showing you how to set up your own IRC server.

How This Book Is Organized

There are several different areas you need to master to become a true IRC hacker. At the core is the conceptual model of IRC, while layered around that are the protocols and clients used to access the IRC networks. The book is divided into 15 chapters, starting with the basics and progressing to cover interesting hacks involving bots and client enhancements:

Chapter 1, Connecting to IRC

Before embarking on the journey through the rest of the hacks, it’s important to make sure you know how to connect to IRC. This chapter shows you how to use a variety of IRC clients, on a variety of operating systems, to connect to an IRC server and join the #irchacks channel.

Chapter 2, Using IRC

To use IRC effectively, you need to be aware of how users, channels, servers, and networks fit into the equation. This chapter also introduces you to the common abbreviations and acronyms that you are likely to encounter on a foray through IRC. You will also learn how to protect your channel and nickname using Services.

Chapter 3, Users and Channels

One common question asked by IRC newcomers is, “What channels should I join?” This chapter shows you how to find channels that are relevant to you, either by searching on a specific network or through all the networks in the world. You will also be shown how to perform some investigative work to find out where a user is from and to generate amusing statistics for your channel.

Chapter 4, Enhancing IRC Clients

IRC clients have a lot of functionality built in, and this chapter helps to expose those features. Some of these hacks make use of client scripts to perform useful tasks that would otherwise not be possible. As you read through this chapter, you’ll soon start to realize that if an IRC client doesn’t do what you want it to do, you can easily add the feature yourself.

Chapter 5, Writing IRC Bots

IRC bots are autonomous clients that run without direct human input. This chapter explores what needs to be done to write an autonomous client that can connect to IRC, using Perl, Java, and Python. You will also be introduced to some popular libraries that simplify the process of writing IRC bots.

Chapter 6, Logging Bots

Bots that log IRC activity come in various guises. This chapter demonstrates how to create bots that use logging in different ways to achieve useful results, such as remembering when people were last active, logging URLs, running blogs, and recapping conversations.

Chapter 7, Community Bots

IRC is a chat system that is inherently amenable for use by communities. These communities can be served by IRC bots that perform useful tasks. Some of these applications are fun, such as generating social network diagrams of a community, while others are more useful, such as being able to pass messages on to other users.

Chapter 8, Search and Query Bots

IRC bots are often used to provide a gateway or interface to another service. This chapter shows you how to make bots to search Google and look up words on FOLDOC, the Free Online Dictionary of Computing. Web services can be used to make bots that search for books on Amazon, check the weather, translate languages, or convert currencies. On a more local scale, you can also create a bot to find out whether users are connected to an IRC network.

Chapter 9, Fun Bots

One reason for getting into IRC is that it is fun to chat. We reinforce this principle by demonstrating some fun bots that create comic strips, calculate mathematical expressions, and even act as a quizmaster. You can even try to fool your friends with the artificial intelligence bot described in this chapter.

Chapter 10, Announcement Bots

IRC bots are ideal for making announcements. They don’t argue back if you disagree with them. With the growing popularity of RSS, this chapter shows you how to create an IRC bot that reads news into a channel from RSS feeds. Other hacks show you how to announce items posted to newsgroups or even events happening on a game server.

Chapter 11, Network Bots

As IRC bots run on machines with Internet access, it seems foolish not to make use of this fact. This chapter shows you how to link bots together to share information and provide remote resources to users of your bots, letting them get remote shells and tail log files over IRC.

Chapter 12, Channel Management Bots

As IRC is accessible by anybody, you occasionally find the odd user who is intent on causing trouble. The primary target of such abuse is usually a channel, where messages may be spammed or topics may be changed. This chapter shows you how to take care of such troublemakers by using bots to thwart their evil intentions.

Chapter 13, The IRC Protocol

Having already explored the possibilities of bots, this chapter goes into more detail about the IRC protocol, which is essential if you wish to write your own IRC applications. This chapter covers some of the points you will need to consider when writing IRC bots or clients.

Chapter 14, Other Ways to Connect to IRC

Chapter 1 covered the “conventional” IRC clients that most people use to connect to IRC. This chapter provides alternatives, such as web-based clients that do not require users to install any software, IRC clients that can run on mobile phones and Pocket PCs, and access to IRC through a proxy.

Chapter 15, Servers and Services

IRC servers play an obviously important role in the whole story of IRC, allowing clients to connect to them and chat with one another. This chapter shows you how to run your own IRC server and let people connect to it from the Internet. For greater resilience, you can even network more than one server. You can also find out how to access MSN, ICQ, and AIM from your IRC client.

Conventions Used in this Book

The following is a list of the typographical conventions used in this book:

Italic

Used to indicate new terms, URLs, filenames, file extensions, directories, and program names. For example, a path in the filesystem will appear as /Developer/Applications.

Constant width

Used to show code examples, commands and options, the contents of files, and the output from commands.

Constant width bold

Used for emphasis and user input in code.

Constant width italic

Used in examples and tables to show text that should be replaced with user-supplied values.

You should pay special attention to notes set apart from the text with the following icons:

Tip

This is a tip, suggestion, or general note. It contains useful supplementary information about the topic at hand.

Warning

This is a warning or note of caution.

The thermometer icons, found next to each hack, indicate the relative complexity of the hack:

beginner
moderate
expert

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "IRC Hacks by Paul Mutton. Copyright 2004 O’Reilly Media, Inc., 0-596-00687-X.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

How to Contact Us

We have tested and verified the information in this book to the best of our ability, but you may find that features have changed (or even that we have made mistakes!). As a reader of this book, you can help us to improve future editions by sending us your feedback. Please let us know about any errors, inaccuracies, bugs, misleading or confusing statements, and typos that you find anywhere in this book.

Please also let us know what we can do to make this book more useful to you. We take your comments seriously and will try to incorporate reasonable suggestions into future editions. You can write to us at:

O’Reilly Media
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the U.S. or Canada)
(707) 829-0515 (international/local)
(707) 829-0104 (fax)

To ask technical questions or to comment on the book, send email to:

The web site for IRC Hacks lists examples, errata, and plans for future editions. You can find this page at:

http://www.oreilly.com/catalog/irchks

For more information about this book and others, see the O’Reilly web site:

http://www.oreilly.com

Got a Hack?

To explore Hacks books online or to contribute a hack for future titles, visit:

http://hacks.oreilly.com

Get IRC Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.