View Full Version : [JAVA] Help with phraseing a line in IRC
Lusfr_
July 11th, 2010, 17:57
String host = "", text = "", cmd = "";
try {
String[] split = currLine.split(":");
host = split[1].split(" ")[0];
text = currLine.substring(1 + split[1].length() + 1);
String[] tmp = text.split(" ");
cmd = tmp[0];
} catch(Exception e) {
}
My Failed Attempt.
This is like half of how i need it.
I was hoping for
Nick =
Ident =
Host =
Chan =
Msg =
Pie`
July 11th, 2010, 19:56
It's times like this that I made this class:
package com.pie.jotta.irc;
import java.util.ArrayList;
public class IRCMessage {
private String in;
public IRCMessage(String in) {
this.in = in;
}
public String setMessage(String in) {
in.replace((char)1, ' ').replace((char)2, ' ').replace((char)3, ' ');
return this.in = in.trim();
}
public String getSource() {
if(in.split(" ")[0].charAt(0) == 'P') {
return in.split(" ")[1];
} else {
return (in.split(" ")[2].startsWith("#")) ? in.split(" ")[2] : getSender();
}
}
public String getSender() {
return in.split("!")[0].replace(":", "");
}
public String getMode() {
return in.split(" ")[3].charAt(0) == '+' || in.split(" ")[3].charAt(0) == '-'? in.split(" ")[3] : null;
}
public String getModeOn() {
return (in.split(" ").length > 4) && (in.split(" ")[3].charAt(0) != ':') ? in.split(" ")[4] : null;
}
public String getCommand() {
return (in.split(" ")[0].charAt(0) == 'P') ? "PING" : in.split(" ")[1];
}
public boolean isBotCommand() {
return getMessage().charAt(0) == '$';
}
public boolean isAction() {
return getMessage().charAt(0) == (char)1 && getMessage().charAt(1) == 'A';
}
public boolean isUserPing() {
return getMessage().charAt(0) == (char)1 && getMessage().charAt(1) == 'P';
}
public boolean isWelcomeMessage() {
return getCommand().equals("001");
}
public long getPingTime() {
return Long.parseLong(getMessage().substring(5).trim());
}
public String getAction() {
return getMessage().substring(7).trim();
}
public String getCmd() {
return getMessage().split(" ")[0];
}
public String getMessage() {
return (in.indexOf(":", 1) > -1) ? in.substring(in.indexOf(":", 1)+1) : null;
}
public String getHost() {
return in.split(" ")[0].substring(getSender().length()+2);
}
public ArrayList<String> getMessageArgs() {
ArrayList<String> args = new ArrayList<String>();
for(String arg : getMessage().split(" ")) {
if(!(arg.trim().equals("")) && arg != null) {
args.add(arg);
}
}
if(args.size() > 0)
args.remove(0);
return args;
}
public String toString() {
return this.in;
}
}
ps. hi lusfr_ :)
Lusfr_
July 11th, 2010, 20:23
Thanks Pie` and I should be able to recreate my own method using this thanks.
Powered by vBulletin® Version 4.1.9 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.