package irc import ( "fmt"; "strings"; ) const ( RplWelcome = "001"; RplYourhost = "002"; RplCreated = "003"; RplMyinfo = "004"; RplBounce = "005"; RplUserhost = "302"; RplAway = "301"; RplUnaway = "305"; RplNowaway = "306"; RplWhoisuser = "311"; RplWhoisserver = "312"; RplWhoisoperator = "313"; RplWhoisidle = "317"; RplEndofwhois = "318"; RplWhoischannels = "319"; RplWhowasuser = "314"; RplEndofwhowas = "369"; RplList = "322"; RplListend = "323"; RplUniqopis = "325"; RplChannelmodeis = "324"; RplNotopic = "331"; RplTopic = "332"; RplInviting = "341"; RplSummoning = "342"; RplInvitelist = "346"; RplEndofinvitelist = "347"; RplExceptlist = "348"; RplEndofexceptlist = "349"; RplVersion = "351"; RplWhoreply = "352"; RplEndofwho = "315"; RplNamereply = "353"; RplEndofnames = "366"; RplLinks = "364"; RplEndoflinks = "365"; RplBanlist = "367"; RplEndofbanlist = "368"; RplInfo = "371"; RplEndofinfo = "374"; RplMotdstart = "375"; RplMotd = "372"; RplEndofmotd = "376"; RplYouroper = "381"; RplRehashing = "382"; RplYourservice = "383"; RplTime = "391"; RplUserstat = "392"; RplUsers = "393"; RplEndofusers = "394"; RplNousers = "395"; ) /* Who - the full name (nick!n=username@host) or server Command - the IRC command Args - the arguments to the command before the last arg that is prefixed by a : LastArg - the final arg that is prefixed by a : (it is stored without the : prefix) */ type IrcMessage struct { Who, Command, LastArg string; Args []string; } /* Parses out string and returns a IrcMessage object. */ func ParseMessage(msg string) *IrcMessage { var parts []string; if (msg[0] == ':') { parts = strings.Split(msg[1:len(msg)], ":", 2); } else { parts = strings.Split(msg, ":", 1); } words := strings.Split(parts[0], " ", 0); ircmsg := new(IrcMessage); ircmsg.Who = words[0]; ircmsg.Command = words[1]; if len(parts) > 1 { ircmsg.LastArg = parts[1]; } ircmsg.Args = words[2:len(words)]; fmt.Printf("%v\n", ircmsg); return ircmsg; } func (msg *IrcMessage) CompileMessage() string { return fmt.Sprintf(":%s %s %s :%s\r\n", msg.Who, msg.Command, strings.Join(msg.Args, " "), msg.LastArg); }