The One and the Many

Ruby interpreter IRC bot script for Eggdrop

I've been learning a bit of Ruby recently.

One thing that has aided in my Tcl usage has been having a script for my eggdrop which acts as a "safe" Tcl interpreter to evaluate Tcl commands and outputs the results to a channel. This allows for easy multi-user debugging and demonstration of some small examples. (Found here by the way.)

So I wanted to have the same thing for Ruby. Unfortunately, the one bot that I found in my searching, kirby, seems to be no longer working and, frankly, a very unsatisfactory solution even if it was. This kirby bot worked by passing all requests to a website (a variant of it appears) which then would send back the result. I don't think this way is especially efficient or even maintainable.

Then again, kirby has/had one advantage over the solution I came up with (which is an eggdrop tcl script.) Kirby was safe to have running and allow anyone in a channel to use it to run commands.

My eggdrop script is very unsafe in this regard. All it does is pipe commands to a running irb process on the local machine. Thus, since both I/O and networking are available and anything one could do on the local shell is present, this script is not suitable to be run in a channel with people who may be even slightly untrustworthy. Luckily for me I only wanted the script for a small channel.

The script could be run in a more public channel if the binds were set to only listen for users flagged on the bot, but then this kind of defeats the purpose. And it's hard to have that level of trust.

I suppose some kind of parsing could conceivably be done to make it safer, but I'm not particularly interested in doing the work for that!

The real nice project would be having something similar to Tcl's safe interpreter which allows for the nice Tcl interpreter version of this script. Yet another reason why Tcl is such a great language. Not that I'm going to do this either. Or maybe there is already this feature in some project or Ruby itself and I am just ignorant!

Perhaps it is a bit strange to write a script to run a Ruby interpreter in Tcl, but I am already running one bot so I don't see much reason to run another just for the Ruby interpreter. (Though I am working on a bot all in Ruby to replace some bots I run.)

Anyway to run the script you will need Ruby installed on the machine that runs the eggdrop bot. Make sure you read the header of the script as usual!

Here's the script: irb.tcl

Tags: ruby, eggdrop, tcl, code