PDA

View Full Version : problem with the bot...


inkedmn
11-07-2002, 03:20 PM
ok, this is kinda involved, i hope you guys have the patience to ge through it (i probably wouldn't :))...

i'm working on the implementation of modules. I've got an interface called JoanaModule that each module will implement. It defines one member variable (a String called 'regex') and one method called handler() that will do the actual handling of the messages. now, i've got one of these modules working (for the most part), and some of you might've seen it in #cf (the "movie" deal where the bot spits out a random movie quote). so here's where i actually shut up and get to the question...

at the beginning of PrivMsgHandler (the class that will handle all PRIVMSG's), i create a new instance of the Movie object and put it into an array of JoanaModule objects:

Movie movie = new Movie();
JoanaModule[] modules = {movie};


now, the idea is that (eventually) this list will contain all the modules the implement JoanaModule and (subesquently) each have a regex var and handler method.

near the end of the file (after the message itself is parsed into an array), i do the following:

public void run() {
for (int i = 0; i < modules.length; i++) {
System.out.println(modules[i].regex);
if (type.equalsIgnoreCase(modules[i].regex)) {
c.rawSend(modules[i].handler(c, db, target, parts));
}
}
}


now, IN THEORY this method should iterate over the list of modules and check for a match with each module's regex. if there's a match, the module's handler method is called. this isn't really working. it compiles and runs, but when i run it (you'll notice the print statement just inside the for loop), it spits out the regex defined in JoanaModule (something like "override this regex, jackass") instead of ".*movie.*" or whatever...

anybody have any ideas? am i going about this all wrong?

if you need to see some of the other code, or need more info that what i've given, let me know

thanks !

Strike
11-07-2002, 04:05 PM
You should make the regex in JoanaModule abstract, I think. I'm not sure on the nitty-gritty details of class inheritance in Java, but if something is abstract, not overridden (which may be a syntax error), and then someone tries to access it, it should at least throw an exception.

inkedmn
11-07-2002, 04:08 PM
first of all, Stuka freakin' pwnz.

now, having said that, here's the solution (for instruction's sake)...

the problem stems from the fact that member variables in a java interface can't be overriden. so, i removed the regex var from the interface and added a method called getRegex(). each module that implements the interface will have to add it's regex var, but that's no big deal.

once i changed the related code in PrivMsgHandler and the Movie module, it worked like a champ...