+ static enum How {
+ OTHER, // Unknown message type
+ CHANNEL, // Normal message to a channel
+ MENTION, // User was mentioned in message text
+ DIRECT, // Message directed towards user
+ PRIVMSG, // Private message to user only
+ SENT // Message was sent by the user
+ };
+
+ /* Structures */
+ static class Color {
+ public int code;
+ public String hex;
+ public String name;
+
+ public Color(int code, String hex, String name)
+ {
+ this.code = code;
+ this.hex = hex;
+ this.name = name;
+ }
+ };
+
+ static class Format implements Cloneable {
+ public boolean bold;
+ public boolean italic;
+ public boolean strike;
+ public boolean underline;
+ public boolean reverse;
+ public Color fg;
+ public Color bg;
+ public String txt;
+
+ public Format clone()
+ {
+ try {
+ return (Format)super.clone();
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public String toString()
+ {
+ return (fg!=null ? fg.hex : "xxxxxx") + ":" +
+ (bg!=null ? bg.hex : "xxxxxx") + ":" +
+ (bold ? "b" : "-" ) +
+ (italic ? "i" : "-" ) +
+ (strike ? "s" : "-" ) +
+ (underline ? "u" : "-" ) +
+ (reverse ? "r" : "-" ) + ":" +
+ "[" + txt + "]";
+ }
+ };
+
+ /* Colors */
+ private static final Color colors[] = {
+ new Color(0x0, "FFFFFF", "White"),
+ new Color(0x1, "000000", "Black"),
+ new Color(0x2, "000080", "Navy Blue"),
+ new Color(0x3, "008000", "Green"),
+ new Color(0x4, "FF0000", "Red"),
+ new Color(0x5, "804040", "Brown"),
+ new Color(0x6, "8000FF", "Purple"),
+ new Color(0x7, "808000", "Olive"),
+ new Color(0x8, "FFFF00", "Yellow"),
+ new Color(0x9, "00FF00", "Lime Green"),
+ new Color(0xA, "008080", "Teal"),
+ new Color(0xB, "00FFFF", "Aqua Light"),
+ new Color(0xC, "0000FF", "Royal Blue"),
+ new Color(0xD, "FF00FF", "Hot Pink"),
+ new Color(0xE, "808080", "Dark Gray"),
+ new Color(0xF, "C0C0C0", "Light Gray"),
+ };
+
+ /* Constants */
+ private static final String reMsg = "(:([^ ]+) +)?(([A-Z0-9]+) +)(([^ ]+)[= ]+)?(([^: ]+) *)?(:(.*))?";
+ private static final String reFrom = "([^! ]+)!.*";
+ private static final String reTo = "(([^ :,]*)[:,] *)?(.*)";
+ private static final String reCmd = "/([a-z]+)( +(.*))?";
+
+ private static final Pattern ptMsg = Pattern.compile(reMsg);
+ private static final Pattern ptFrom = Pattern.compile(reFrom);
+ private static final Pattern ptTo = Pattern.compile(reTo);
+ private static final Pattern ptCmd = Pattern.compile(reCmd);
+
+ private static final String cReNum = "1[0-5]|0?[0-9]";
+ private static final String cReFmt = "[\\002\\011\\017\\023\\025\\026\\037]";
+ private static final String cReClr = "[\\003\\013]("+cReNum+")?(,("+cReNum+"))?";
+ private static final String cRegex = cReFmt + "|" + cReClr + "|$";
+ private static final Pattern cPtrn = Pattern.compile(cRegex);