public void Execute(IrcBot bot, BotCommand botCommand) { if (this.SendDataAction != null) { this.SendDataAction(bot, botCommand); } }
public static void SetProperties(IrcCommand source, BotCommand target) { if (source == null) { throw new ArgumentNullException("source"); } if (target == null) { throw new ArgumentNullException("target"); } string[] botCommandParts = source.Parameter.Split(' '); target.Command = botCommandParts[0]; target.IrcCommand = source.Command; target.Nick = source.Nick; foreach (var parameter in botCommandParts.Skip(1)) { target.Parameters.Add(parameter); } target.User = source.User; }
public static void SetProperties(IrcCommand source, BotCommand target) { if (source == null) throw new ArgumentNullException("source"); if (target == null) throw new ArgumentNullException("target"); string[] botCommandParts = source.Parameter.Split(' '); target.Command = botCommandParts[0]; target.IrcCommand = source.Command; target.Nick = source.Nick; foreach (var parameter in botCommandParts.Skip(1)) { target.Parameters.Add(parameter); } target.User = source.User; }
public static BotCommand Parse(IrcCommand ircCommand) { BotCommand botCommand = new BotCommand(); SetProperties(ircCommand, botCommand); return botCommand; }
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)); } } } } }