public static IrcCommand ParseIrcCommand(string value) { IrcCommand command = new IrcCommand(); if (!string.IsNullOrEmpty(value)) { string[] data = value.Split(new char[] { ' ' }, 4); string identity = data[0]; string[] identityData = identity.Split('!'); if (identityData.Length > 1) { command.Nick = identityData[0].TrimStart(':'); command.User = identityData[1]; } else { command.Nick = identity; } if (data.Length > 1) { command.Command = data[1]; } if (data.Length > 3) { command.Parameter = data[3]; } } return(command); }
public static IrcCommand ParseIrcCommand(string value) { IrcCommand command = new IrcCommand(); if (!string.IsNullOrEmpty(value)) { string[] data = value.Split(new char[] { ' ' }, 4); string identity = data[0]; string[] identityData = identity.Split('!'); if (identityData.Length > 1) { command.Nick = identityData[0].TrimStart(':'); command.User = identityData[1]; } else { command.Nick = identity; } if (data.Length > 1) { command.Command = data[1]; } if (data.Length > 3) { command.Parameter = data[3]; } } return command; }
public void Listen() { while (this.IsRunning) { string dataLine = this._streamReader.ReadLine(); if (!string.IsNullOrEmpty(dataLine)) { Console.WriteLine(dataLine); char[] charSeparator = new char[] { ' ' }; string[] data = dataLine.Split(charSeparator, 5); if (this.IsPing(data)) { this.SendPong(data); } else if (data.Length > 1) { IrcCommand ircCommand = IrcCommandHelper.ParseIrcCommand(dataLine); if (IrcCommandHelper.IsBotCommand(ircCommand)) { BotCommand botCommand = new BotCommand(ircCommand); BotCommandResponse botCommandResponse = this._botCommandResponses.SingleOrDefault(r => r.Command == botCommand.Command); if (botCommandResponse != null && this.AuthorizeUser(botCommand.Nick, botCommand.User)) { botCommandResponse.Execute(this, botCommand); } this.PrevCommandNick = botCommand.Nick; } else if (this.IsError(ircCommand.Command) && !string.IsNullOrEmpty(this.PrevCommandNick)) { this.SendPrivateMessage(this.PrevCommandNick, this.GetErrorMessage(ircCommand.Command)); } } } } }
public static bool IsBotCommand(IrcCommand ircCommand) { return(ircCommand.Command == IrcCommandName.PrivateMessage && !string.IsNullOrEmpty(ircCommand.Parameter) && ircCommand.Parameter.StartsWith(":!")); }
public static bool IsBotCommand(IrcCommand ircCommand) { return (ircCommand.Command == IrcCommandName.PrivateMessage && !string.IsNullOrEmpty(ircCommand.Parameter) && ircCommand.Parameter.StartsWith(":!")); }