2012-11-15 18:32:19 -07:00
|
|
|
bot
|
|
|
|
===
|
2011-01-06 22:21:32 -07:00
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
This is a simple C program to assist writing an IRC bot in whatever language(s)
|
|
|
|
you choose. It is based on the Unix principle that one program should do one
|
|
|
|
thing.
|
2011-01-06 22:21:32 -07:00
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
This framework gives you plenty of opportunity to shoot yourself in the foot.
|
|
|
|
If you're not a seasoned programmer, please stick to a language like Python or
|
|
|
|
Lua for your handler. Leave the arcane trivia of proper Bourne Shell quoting
|
|
|
|
rules to the seasoned experts who've learned the hard way how to do it.
|
2011-01-06 22:21:32 -07:00
|
|
|
|
|
|
|
|
2012-05-14 13:37:28 -06:00
|
|
|
Getting Started Quickly
|
|
|
|
=======================
|
2011-01-06 22:21:32 -07:00
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
The example handler script, called `newmont`, will get you started right away.
|
|
|
|
It will set its nickname to `newmont`, join the channel `#newmont`, and respond
|
|
|
|
to any channel message containing the substring "strawberry".
|
2011-01-06 22:21:32 -07:00
|
|
|
|
2012-05-14 13:37:28 -06:00
|
|
|
Start it like so:
|
2011-01-06 22:21:32 -07:00
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
tcpclient YOUR.IRC.SERVER 6667 ./bot contrib/newmont
|
2011-01-06 22:25:02 -07:00
|
|
|
|
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
What's Going On
|
|
|
|
===============
|
2011-01-06 22:25:02 -07:00
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
There are three pieces involved.
|
2011-01-06 22:25:02 -07:00
|
|
|
|
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
tcpclient
|
|
|
|
---------
|
2011-01-06 22:25:02 -07:00
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
`tcpclient' is a program that connects to a TCP port, sets file descriptors 6
|
|
|
|
and 7 to be the input and output channels to that connection, and hands off
|
|
|
|
control to whatever program you specify (in the example above, the `./bot`
|
|
|
|
program with argument `./newmont`). There also exist a `udpclient`,
|
|
|
|
`sslclient`, and probably others. The advantage to this method is that
|
|
|
|
your network client doesn't have to care about the transport mechanism:
|
|
|
|
TCP, UDP, TCP6, SSL, or whatever else.
|
|
|
|
|
|
|
|
bot
|
|
|
|
---
|
2011-01-06 22:25:02 -07:00
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
`bot` reads one line at a time from fd6 (or 0 as a fallback), parses it up,
|
|
|
|
forks, sets some environment variables, and runs the "handler" program provided
|
|
|
|
as the first argument. Whatever that program prints to stdout is sent back to
|
|
|
|
the server, verbatim. As a convenience, it automatically responds to PING
|
|
|
|
messages from the server. It can also rate-limit messages to the server, so
|
|
|
|
your bot doesn't flood itself off IRC. Lastly, it can monitor a directory and
|
|
|
|
send the contents of any new file to the server, deleting the file after. This
|
|
|
|
allows you to write to IRC from a cron job, git post-update hook, or whatever
|
|
|
|
else you dream up.
|
2011-01-06 22:25:02 -07:00
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
`bot` sets the following environment variables:
|
2011-01-06 22:25:02 -07:00
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
prefix IRC line prefix: you probably don't care about this
|
|
|
|
command IRC command or numeric
|
|
|
|
sender nickname to send "private" replies to this message
|
|
|
|
forum nickname to send "public" replies to this message
|
|
|
|
text text of this message, like what's sent to the channel
|
2011-01-06 22:25:02 -07:00
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
Any additional parameters of the message, like with the MODE command, are
|
|
|
|
passed in as arguments to the handler.
|
2011-01-06 22:25:02 -07:00
|
|
|
|
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
handler
|
|
|
|
-------
|
|
|
|
|
|
|
|
The handler is launched once for each incoming message. It should decide
|
|
|
|
what to do based on the environment variables and argv, possibly writing
|
|
|
|
something to stdout, and then it should exit.
|
|
|
|
|
|
|
|
Handlers are launched in parallel to each other. IRC is an asynchronous
|
|
|
|
protocol, and while messages do tend to arrive in a particular order, don't
|
|
|
|
count on it, especially with this framework.
|
2011-01-06 22:25:02 -07:00
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
`newmont` is a very simple handler script to reply to any PRIVMSG with the
|
|
|
|
substring "strawberry", in the (public) forum it was sent.
|
2011-01-06 22:21:32 -07:00
|
|
|
|
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
Caution
|
|
|
|
=======
|
|
|
|
|
|
|
|
Your handler is getting input provided by a potentially malicious adversary.
|
|
|
|
If you're not careful, you could create a remote exploit: a path through your
|
|
|
|
handler script that allows anyone on IRC to do whatever they want on your
|
|
|
|
local computer.
|
2011-01-06 22:21:32 -07:00
|
|
|
|
2012-11-15 18:32:19 -07:00
|
|
|
You can write handlers in bourne shell: it's really easy. It's equally as
|
|
|
|
easy to accidentally allow remote control. There's nothing I can do in the
|
|
|
|
code I provide to prevent you from really hurting yourself, all I can do is
|
|
|
|
warn you.
|
2011-01-06 22:21:32 -07:00
|
|
|
|
2009-03-02 23:26:04 -07:00
|
|
|
|
|
|
|
|
|
|
|
Author
|
2012-05-14 13:37:28 -06:00
|
|
|
======
|
2009-03-02 23:26:04 -07:00
|
|
|
|
|
|
|
Neale Pickett <neale@woozle.org>
|
|
|
|
|
2008-02-08 15:38:31 -07:00
|
|
|
|
|
|
|
|