コード例 #1
0
ファイル: BotCommandResponse.cs プロジェクト: petmat/UberBot
 public void Execute(IrcBot bot, BotCommand botCommand)
 {
     if (this.SendDataAction != null)
     {
         this.SendDataAction(bot, botCommand);
     }
 }
コード例 #2
0
        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;
        }
コード例 #3
0
ファイル: BotCommand.cs プロジェクト: petmat/UberBot
        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;
        }
コード例 #4
0
ファイル: BotCommand.cs プロジェクト: petmat/UberBot
 public static BotCommand Parse(IrcCommand ircCommand)
 {
     BotCommand botCommand = new BotCommand();
     SetProperties(ircCommand, botCommand);
     return botCommand;
 }
コード例 #5
0
ファイル: IrcBot.cs プロジェクト: petmat/UberBot
        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));
                        }
                    }
                }
            }
        }