[Cherbot-commit] SF.net SVN: cherbot: [80] trunk/src/net/sf/cherbot/IRCConnection.java
Status: Alpha
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2007-06-17 20:33:20
|
Revision: 80
http://svn.sourceforge.net/cherbot/?rev=80&view=rev
Author: christianhujer
Date: 2007-06-17 13:33:19 -0700 (Sun, 17 Jun 2007)
Log Message:
-----------
Changed IRCConnection to use delegation based on redel.
Modified Paths:
--------------
trunk/src/net/sf/cherbot/IRCConnection.java
Modified: trunk/src/net/sf/cherbot/IRCConnection.java
===================================================================
--- trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-17 20:32:19 UTC (rev 79)
+++ trunk/src/net/sf/cherbot/IRCConnection.java 2007-06-17 20:33:19 UTC (rev 80)
@@ -15,8 +15,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+import net.sf.cherbot.redel.PatternDelegator;
+import net.sf.cherbot.redel.Patterns;
import net.sf.japi.io.args.ArgParser;
import net.sf.japi.io.args.Option;
import org.jetbrains.annotations.NotNull;
@@ -109,26 +109,10 @@
for (final String channelName : args) {
join(channelName);
}
- final Pattern pattern = Pattern.compile("^:([^!]+)!([^ ]+) PRIVMSG ([^ ]+) :(.*)$");
- final Matcher matcher = pattern.matcher("");
+ final PatternDelegator delegator = new PatternDelegator(this);
for (String line; (line = in.readLine()) != null;) {
System.out.println(line);
- matcher.reset(line);
- if (matcher.matches()) {
- final String actor = matcher.group(1);
- if (nickname.equals(actor)) {
- continue;
- }
- final String actorIdentity = matcher.group(2);
- final String channelName = matcher.group(3);
- final String message = matcher.group(4);
- Channel channel = channels.get(channelName);
- if (channel == null) {
- // TODO: Create channel on demand.
- }
- System.out.println(channel);
- //channel.send("You are: " + actorIdentity + " and said: " + message);
- }
+ delegator.process(line);
}
return 0;
} finally {
@@ -136,6 +120,23 @@
}
}
+ /** Processes a PRIVMSG irc message.
+ * @param actor Actor of this message.
+ * @param actorIdentity Identity of the actor.
+ * @param channelName Name of the channel.
+ * @param message Message text.
+ */
+ @Patterns({"^:([^!]+)!([^ ]+) PRIVMSG ([^ ]+) :(.*)$"})
+ public void processPRIVMSG(@NotNull final String actor, @NotNull final String actorIdentity, @NotNull final String channelName, @NotNull final String message) {
+ Channel channel = channels.get(channelName);
+ if (channel == null) {
+ // TODO: Create channel on demand.
+ } else {
+ channel.send(message);
+ }
+ System.out.println(channel);
+ }
+
/** Joins an IRC channel.
* @param rawChannelName name of the channel to join.
* @return The channel that was just joined.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|