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