Skip to content
/ cabot Public
forked from fridim/cabot

a simple IRC framework written in whatever you want

License

Notifications You must be signed in to change notification settings

Arsnael/cabot

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cabot, a simple IRC framework written in whatever you want

About

This is a minimalist IRC bot written in Go as an exercice to learn the language. The core codebase (in Go) has very few features :

  • connect to a server
  • plugins:
    • run all executable files located in plugins/
    • dispatch input to all plugins located in the plugins/ directory
    • Example output of ps
3551 pts/2    Sl+    0:00  \_ ./bot -server=irc.freenode.org:6667
3558 pts/2    Sl+    0:00      \_ /usr/bin/ruby plugins/register_and_join.rb
3561 pts/2    Sl+    0:00      \_ /usr/bin/ruby plugins/url.rb
3566 pts/2    Sl+    0:00      \_ /usr/bin/ruby plugins/date.rb
3577 pts/2    Sl+    0:00      \_ /usr/bin/ruby plugins/hello.rb
3579 pts/2    Sl+    0:00      \_ plugins/ping
  • signals:
    • SIGHUP will kill and reload all plugins
    • SIGUSR1 to reconnect

I have absolutely no credit, as this program is a clone of vivien’s modulo. Have a look there!

Plugins

Everything other than the previous is done via plugins. Plugins are scripts or compiled programs in the plugins/ directory.

A plugin must:

  • be executable
  • read from STDIN
  • write to STDOUT

Example of plugins:

  • ping.go: reply to PONG from server and send SIGUSR1 to parent process if last pong is too old
  • freenode_register_join.rb: register USER and NICK and JOIN channels
  • reload plugins from IRC by just talking to your bot, plugin will SIGHUP the parent process on a specific input from registered owner.
  • whatever you want, really

Input from the IRC Socket is directly rewritten to the plugin STDIN. The STDOUT of the plugin is then pipelined back to the IRC socket. It’s that simple.

Example of helloworld in Ruby:

#!/usr/bin/ruby
STDOUT.sync = true

STDIN.each_line do |l|
  if l =~ /PRIVMSG (#\w+) :(.+)/
    channel = $1
    message = $2
    if message =~ /^hello/i
      puts "PRIVMSG #{channel} :Hello o/"
    end
  end
end

Do not forget to sync the STDOUT in your plugin otherwise, the bot will probably not reply when you imagine it would.

Getting started

Build

$ go build *.go

You will also need the ping plugin

$ cd plugins_examples/ping
$ go build ping.go
$ cp ping ../../plugins/

Minimal configuration

Everything related to IRC will be dealt with by plugins.

You will find examples of plugin in plugins_examples/ directory. For freenode, you can just edit plugins_examples/freenode_register_join.rb and set channels to join and Nickserv password in a file.

Run

$ ./bot -server=chat.freenode.net:6697 -ssl

About

a simple IRC framework written in whatever you want

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 75.4%
  • C 10.1%
  • Ruby 8.7%
  • Python 3.7%
  • Perl 2.1%