示例#1
0
        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);
        }
示例#2
0
        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;
        }
示例#3
0
        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));
                        }
                    }
                }
            }
        }
示例#4
0
 public static bool IsBotCommand(IrcCommand ircCommand)
 {
     return(ircCommand.Command == IrcCommandName.PrivateMessage &&
            !string.IsNullOrEmpty(ircCommand.Parameter) &&
            ircCommand.Parameter.StartsWith(":!"));
 }
示例#5
0
 public static bool IsBotCommand(IrcCommand ircCommand)
 {
     return (ircCommand.Command == IrcCommandName.PrivateMessage
         && !string.IsNullOrEmpty(ircCommand.Parameter)
         && ircCommand.Parameter.StartsWith(":!"));
 }