Categorygithub.com/fridim/cabot
repositorypackage
0.0.0-20250112113502-35f26b84d253
Repository: https://github.com/fridim/cabot.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author

# README

#+TITLE: cabot, a simple IRC framework written in whatever you want #+AUTHOR: Guillaume Coré (fridim) [email protected]

  • 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=

#+BEGIN_SRC 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 #+END_SRC

  • 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 [[https://github.com/vivien/modulo][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:

  • [[file:plugins_examples/ping/ping.go][ping.go]]: reply to PONG from server and send =SIGUSR1= to parent process if last pong is too old
  • [[file:plugins_examples/freenode_register_join.rb][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:

#+BEGIN_SRC 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 #+END_SRC

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

#+BEGIN_SRC $ go build *.go #+END_SRC

You will also need the ping plugin

#+BEGIN_SRC $ cd plugins_examples/ping $ go build ping.go $ cp ping ../../plugins/ #+END_SRC

** 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

#+BEGIN_SRC $ ./bot -server=chat.freenode.net:6697 -ssl #+END_SRC

  • Install dependencies

** Alpine

#+BEGIN_SRC apk add git go ruby-dev perl python3 py3-pip perl-libwww gem install tzinfo gem install io-console gem install etc pip install googletrans #+END_SRC