-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Elliot West
committed
Jan 18, 2011
1 parent
96a3b26
commit 3c5b2cb
Showing
2 changed files
with
113 additions
and
54 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/main/java/uk/org/hackspace/ircensus/ChannelControlHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package uk.org.hackspace.ircensus; | ||
|
||
public class ChannelControlHandler extends AbstractIrcHandler { | ||
|
||
public ChannelControlHandler(IrcClient ircClient) { | ||
super(ircClient); | ||
} | ||
|
||
@Override | ||
public String executeCommand(String method, String[] tokens, String sender) { | ||
if ("join".equals(method)) { | ||
return commandJoinChannel(tokens); | ||
} else if ("leave".equals(method)) { | ||
return commandLeaveChannel(tokens); | ||
} else if ("channels".equals(method)) { | ||
return commandChannels(); | ||
} else { | ||
return "Unrecognized command: " + method; | ||
} | ||
} | ||
|
||
private String commandJoinChannel(String[] tokens) { | ||
if (tokens.length == 1) { | ||
ircClient.joinChannel(tokens[0]); | ||
return "Joined channel: " + tokens[0]; | ||
} else if (tokens.length == 2) { | ||
ircClient.joinChannel(tokens[0], tokens[1]); | ||
return "Joined channel: " + tokens[0]; | ||
} else { | ||
return "Usage: join <channel> [<password>]"; | ||
} | ||
} | ||
|
||
private String commandLeaveChannel(String[] tokens) { | ||
if (tokens.length == 1) { | ||
ircClient.partChannel(tokens[0]); | ||
return "Left channel: " + tokens[0]; | ||
} else { | ||
return "Usage: leave <channel>"; | ||
} | ||
} | ||
|
||
private String commandChannels() { | ||
StringBuilder builder = new StringBuilder("Channels: "); | ||
String[] channels = ircClient.getChannels(); | ||
boolean first = true; | ||
for (String channel : channels) { | ||
if (first) { | ||
first = false; | ||
} else { | ||
builder.append(", "); | ||
} | ||
builder.append(channel); | ||
} | ||
return builder.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters