Chapter 6. Logging Bots
Introduction: Hacks #40-43
Logging is a natural function for bots and clients alike. Many IRC clients offer the ability to append messages to log files, and it is trivial to add such features to a bot. The secret of effective logging is to work out what you want to log and how people can access the information. This provides some quite creative ideas that go beyond the simple task of merely logging every message to a file.
A bot that monitors all messages sent to a channel is effectively monitoring the activity of all users in that channel. By providing an interface that lets people talk to the bot, you can let them find out when a particular user was last seen and what that user said in the channel. This chapter shows you how to implement such a bot using the PircBot package covered in Chapter 5.
It is perhaps surprising to learn that bots can even be written in shell scripts. This chapter shows you how to write a basic bot that uses bash to connect to IRC and log all URLs that it sees. Another bot written in Java can tell you what people were talking about before you joined a channel, so you will never feel as if you’ve blindly wandered into the middle of a conversation.
A more complicated example uses a Java bot to run a group blog, logging URLs to a MySQL database. A web-based frontend then lets people view the logged URLs.
Keep Tabs on People
Keep track of when visitors to a channel last spoke and what they said.
People aren’t always online and, even if ...
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.