コード例 #1
0
ファイル: BotController.cs プロジェクト: Luke-Wolf/wolfybot
 /// <summary>
 /// Handler for Scripts to Attatch to, Hooks up to the OnMessageSent Handler
 /// For Internal Usage Only
 /// </summary>
 public void ScriptMessageHandler(Object sender, IRCMessage e)
 {
     OnMessageSent(e);
 }
コード例 #2
0
ファイル: IRCServer.cs プロジェクト: Luke-Wolf/wolfybot
        /// <summary>
        /// Establish a connection to the IRC Server and read from it
        /// </summary>
        public async void Connect()
        {
            using (var client = new TcpClient(Host, Port)) {
                if (SSL)
                {
                    //need to disable the validation callback otherwise it errors due to the fact
                    //that IRC certificates will cause SslStream to error off otherwise hence the
                    //lamda function
                    var stream = new SslStream(client.GetStream(), false, (a, b, c, d) => true);

                    stream.AuthenticateAsClient(Host, null,
                                                System.Security.Authentication.SslProtocols.Default, false);
                    reader = new StreamReader(stream);
                    writer = new StreamWriter(stream)
                    {
                        NewLine = "\r\n", AutoFlush = true
                    };
                }
                else
                {
                    var stream = client.GetStream();
                    reader = new StreamReader(stream);
                    writer = new StreamWriter(stream)
                    {
                        NewLine = "\r\n", AutoFlush = true
                    };
                }
                //Identify Bot to IRC Server
                if (Password != String.Empty)
                {
                    SendMessageHandler(this, IRCMessageFactory.BuildSendPassMessage(Password));
                }
                SendMessageHandler(this, IRCMessageFactory.BuildSetNickMessage(Nick));
                SendMessageHandler(this, IRCMessageFactory.BuildUserMessage(Nick, Nick));

                String channelsString = String.Empty;
                if (Channels.Count == 1)
                {
                    channelsString = Channels [0].ChannelName;
                }
                else
                {
                    foreach (var item in Channels)
                    {
                        channelsString = String.Concat(item.ChannelName, ",", channelsString);
                    }
                }
                SendMessageHandler(this, IRCMessageFactory.BuildJoinChannelMessage(channelsString));

                while (client.Connected)
                {
                    var line = await reader.ReadLineAsync();

                    var msg = new IRCMessage(line);
                    if (msg.Channel == String.Empty)
                    {
                        Log(msg);
                    }
                    OnMessageReceived(msg);
                }
            }
        }
コード例 #3
0
        public void HandleReceiveMessages(object sender, IRCMessage e)
        {
            //QUIT Commands are Global to server
            if (e.Command == "QUIT")
            {
                RemoveUser(e.Sender);
                return;
            }
            if (e.Channel == String.Empty)
            {
                return;
            }
            //If it's not our channel don't care about it
            if (e.Channel != ChannelName)
            {
                return;
            }
            Log(e);

            var server = sender as IRCServer;

            if (e.Command == "353" || e.Command == "366")
            {
                HandleJoinMessage(e);
                return;
            }
            else if (e.Command == "332" || e.Command == "TOPIC")
            {
                Topic = e.TrailingParameters;
                return;
            }
            else if (e.Command == "JOIN")
            {
                ParsePermission(e.Sender);
                return;
            }
            else if (e.Command == "PART")
            {
                RemoveUser(e.Sender);
                return;
            }
            else if (e.Command == "MODE")
            {
                if (e.Parameters [1] == "+v")
                {
                    var user = FindUser(e.Sender);
                    user.Mode = SecureLevelEnum.Voice;
                    return;
                }
                else if (e.Parameters [1] == "+h")
                {
                    var user = FindUser(e.Sender);
                    user.Mode = SecureLevelEnum.HalfOp;
                    return;
                }
                else if (e.Parameters [1] == "+o")
                {
                    var user = FindUser(e.Sender);
                    user.Mode = SecureLevelEnum.Op;
                    return;
                }
                else if (e.Parameters [1] == "+a")
                {
                    var user = FindUser(e.Sender);
                    user.Mode = SecureLevelEnum.SuperOp;
                    return;
                }
                else if (e.Parameters [1] == "+q")
                {
                    var user = FindUser(e.Sender);
                    user.Mode = SecureLevelEnum.ChannelOwner;
                    return;
                }
                return;
            }
            else if (e.Command == "NICK")
            {
                ChangeNick(e.Sender, e.TrailingParameters);
            }
            else if (e.Command == "PRIVMSG" && e.TrailingParameters.Contains("!shutup") &&
                     e.TrailingParameters.Contains(server.Nick))
            {
                Muted = true;
                return;
            }
            else if (e.Command == "PRIVMSG" && e.TrailingParameters.Contains("!talk") &&
                     e.TrailingParameters.Contains(server.Nick))
            {
                Muted = false;
                return;
            }
        }