PDA

View Full Version : Ruby IRC bot - make modules if you wish


Strike
05-29-2002, 12:16 PM
http://linuxbrit.co.uk/rbot/

cheeky_zombie (from #grasshoppers) pointed this out to me. Looks pretty nice. Lacks some features that moobot has, but also has a thing or two we really need to put in (like online help).

GnuVince
05-29-2002, 12:21 PM
I had already looked at it: more comlpicated than moobot

Strike
05-31-2002, 12:30 PM
More complicated how? Like more featureful, or just less well-structured? Because I don't see how it's any more featureful than moobot barring one or two exceptions, for each of which I can name at least one thing moobot can do that it can't :)

GnuVince
05-31-2002, 12:33 PM
rot13 with rbot:

class RotPlugin < Plugin
def help(plugin, topic="")
"rot13 <string> => encode <string> to rot13 or back"
end
def privmsg(m)
unless(m.params && m.params =~ /^.+$/)
m.reply "incorrect usage: " + help(m.plugin)
return
end
m.reply m.params.tr("A-Za-z", "N-ZA-Mn-za-m");
end
end
plugin = RotPlugin.new
plugin.register("rot13")


and with moobot:

class rot13(MooBotModule):
def __init__(self):
self.regex = "^rot13 .+$"

def handler(self, **args):
"Qbrf n fvzcyr ebg13, abguvat snapl"
from irclib import Event, nm_to_n
if args["type"] == "privmsg": target=nm_to_n(args["source"])
else: target=args["channel"]

from string import maketrans, translate, join
msg = join(args["text"].split(" ")[2:])
table = maketrans(
'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM',
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
newstring = translate(msg, table)
return Event("privmsg", "", target, [newstring])


Beside the msg = join(args["text"].split(" ")[2:]) part, I think moobot is clearer.

Strike
05-31-2002, 01:35 PM
I dunno, I actually kinda like their structure better

recluse
07-02-2002, 12:35 PM
It's a tie! :D

Strike
07-04-2002, 03:51 AM
Funnily enough, I met the rbot creator in #vim on OPN tonight (he'd been there all along). He likes moobot :) We swapped ideas a bit, so we'll see how they both come along (though I'm rather certain he is putting more into his bot than Bradmont and I are into ours)

Bradmont
07-04-2002, 04:16 PM
heh, we haven't really touched moobot in months... well, 'cept my Debian packages.

jemfinch
07-04-2002, 05:41 PM
Moobot's "interface" is very obviously grown up from a very ugly childhood (and, no offense, but from people who were learning Python at the time :)). Rbot's (despite being in Ruby :)) does actually manage to be much cleaner.

Jeremy

Strike
07-05-2002, 12:50 AM
Right, moobot was sort of what taught us Python (it's just nice that Python is simple/good enough to remain workable after the further depths of learning). A rewrite is in order, but I think we're both rather lazy about it . :)

jemfinch
07-05-2002, 03:29 AM
Well, I write IRC bots -- that's about all I ever write (of course, the range of things you can write "for the IRC bot" is so huge...) If you guys want advice or recommendations, I've written my share of IRC bots, some in Python, some in O'Caml, so I'd be happy to offer any possible suggestions.

Jeremy