Welcome to the IRCBot homepage
IRCBot is an IRC bot written in Ruby. It is very small, around 300 lines of code. It is also extensible with plugins that are easy to write. You don't need to modify the kernel of the bot, you simply modify its behavior through the plugins and the basic settings in the bot. Also, instead of implementing a console for the bot it uses irb (interactive ruby).
The necessary files can be downloaded from the subversion repository. Here's a brief description of their functionality:
- ircbot.rb: The kernel of the bot. You need this file.
- plugins.rb: Some simple plugins I have implemented. They are necessary for good bot operation, although you can choose not to use any or all of them.
Here's how you would compose your own bot. Let's put all the code in a file called movbot.rb:
require 'ircbot'
require 'plugins'
class MOVBot < IRCBot
include AdminPlugin
include CTCPPlugin
include PingPlugin
include ChannelJoinerPlugin
end
That's enough to define your bot. It will load the plugins you specified. Now you can try starting your bot:
$ irb --simple-prompt >> require 'movbot' >> b = MOVBot.new "movbot", "irc.efnet.nl" >> b.channels << "#movschannel" >> b.admins << "user-vcauk22.dsl.mindspring.com" >> b.boot
That should be enough to start the bot. After connecting to irc.efnet.nl it will join #movschannel and listen for admin commands from *!*@user-vcauk22.dsl.mindspring.com.
The bot can be accessed and modified from the irb console using the b object. If you don't want to write this stuff in irb every time you're starting the bot you can put it in a script instead. Call the script botstart.rb. This is what the script should look like:
require 'movbot' @b = MOVBot.new "movbot", "irc.efnet.nl" @b.channels << "#movschannel" @b.admins << "user-vcauk22.dsl.mindspring.com" @b.boot
Then you just do:
$ irb -r botstart.rb
And that will drop you into an irb with the bot running. The bot can now be accessed and modified through the @b object.
You might have noticed the udpbot.rb file in the repository. This is a bot that listens on a local UDP port for packets and outputs their content to all the channels it's on. It can be started as illustrated above. The udp-notice.rb script is a subversion hook for sending UDP packets to a listener on post-commit. These can be combined to produce a subversion info bot.
Another nice consequence of using irb as the console is that the bot can be extended dynamically at runtime, without even having to restart it. Let's do an example. Say you want the bot to respond to everyone saying hello to it. Then you could first construct a module like this in hello.rb:
module HelloPlugin
def helloplugin_initialize
@hooks.merge!( { { :type => /^1$/, :text => /hello/ } =>
"helloplugin_greet" } );
end
def helloplugin_greet rec
if rec[:who] == @nick
# Private message to the bot.
send "PRIVMSG #{rec[:user]} :Hello #{rec[:user]}!"
else
# Message to a channel the bot is in.
send "PRIVMSG #{rec[:who]} " +
":Hello #{rec[:user]}, welcome to #{rec[:who]}!"
end
end
end
Now you need to extend the bot class with you new module and run the necessary setup methods:
... >> require 'hello' >> class MOVBot >> include HelloPlugin >> end >> b.helloplugin_initialize
That's it. The hook should be installed and the bot should greet people saying hello now. Nice, eh? :)
I'm open for comments, ideas and feedback. Remember, this is not an eggdrop or something, this is a small kernel that you can extend as you wish. Only use this if you know what you need. Also, it's good if you know how to program Ruby.