当前位置: 首页>>代码示例>>C#>>正文


C# IrcClient.SendRawMessage方法代码示例

本文整理汇总了C#中IrcDotNet.IrcClient.SendRawMessage方法的典型用法代码示例。如果您正苦于以下问题:C# IrcClient.SendRawMessage方法的具体用法?C# IrcClient.SendRawMessage怎么用?C# IrcClient.SendRawMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IrcDotNet.IrcClient的用法示例。


在下文中一共展示了IrcClient.SendRawMessage方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HandleEventLoop

        private static void HandleEventLoop(IrcClient client)
        {
            _ircLocaluser = client.LocalUser;
              _hostNameToWebSockets.Add("", new WebSocketListenerClient(PrivateConstants.TestAccountWebsocketAuth));
              _hostNameToWebSockets[""].Run(sendToIrcProcessor);

              bool isExit = false;
              while (!isExit) {
            Console.Write("> ");
            var command = Console.ReadLine();
            switch (command) {
              case "exit":
            isExit = true;
            break;
              default:
            if (!string.IsNullOrEmpty(command)) {
              if (command.StartsWith("/") && command.Length > 1) {
                client.SendRawMessage(command.Substring(1));
              } else {
                Console.WriteLine($"Unknown command '{command}'");
              }
            }
            break;
            }
              }
              client.Disconnect();
        }
开发者ID:destinygg,项目名称:bot,代码行数:27,代码来源:Program.cs

示例2: Bot

        public Bot()
        {
            commands = Command.GetCommands(this);
            IsInChannel = false;
            IsIdentified = false;
            IsRunning = true;

            // Initialize commands
            foreach(Command command in commands)
                command.Initialize();

            client = new IrcClient
            {
                FloodPreventer = new IrcStandardFloodPreventer(4, 2000)
            };

            // TODO Nasty...
            connectedEvent = new ManualResetEventSlim(false);
            client.Connected += (sender, e) => connectedEvent.Set();

            client.Connected += (sender, args) => Console.WriteLine("Connected!");
            client.Disconnected += (sender, args) =>
            {
                const int MaxRetries = 16;
                int tries = 0;

                if (!IsRunning)
                {
                    Console.WriteLine("Disconnected and IsRunning == false, assuming graceful shutdown...");
                    return;
                }

                IsInChannel = false;
                IsIdentified = false;

                // Wait a little so the server doesn't block us from rejoining (flood control)
                Console.WriteLine("Lost connection, attempting to reconnect in 6 seconds...");
                client.Disconnect();
                Thread.Sleep(6000);

                // Reconnect
                Console.Write("Reconnecting... ");
                while (!Connect(Configuration.Server) && tries++ < MaxRetries)
                {
                    Console.Write("\rReconnecting, attempt {0}...", tries);
                    Thread.Sleep(1);
                }

                if (tries == MaxRetries)
                {
                    Console.WriteLine("Failed.");
                    Quit("Failed to reconnect.");
                    return;
                }

                Console.WriteLine("Connected");
                Console.Write("Joining channel... ");

                if (JoinChannel(Configuration.Channel))
                    Console.WriteLine("Success");
                else
                {
                    Console.WriteLine("Failed");
                    Quit("Failed to rejoin channel.");
                }
            };

            client.Registered += (sender, args) =>
            {
                IrcClient localClient = (IrcClient)sender;

                // Identify with server
                client.SendRawMessage(String.Format("ns identify {0}", Configuration.Password));

                localClient.LocalUser.NoticeReceived += (o, eventArgs) =>
                {
                    if (eventArgs.Text.StartsWith("Password accepted"))
                        IsIdentified = true;

                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine(eventArgs.Text);
                    Console.ForegroundColor = ConsoleColor.Gray;
                };

                localClient.LocalUser.JoinedChannel += (o, eventArgs) =>
                {
                    IrcChannel channel = localClient.Channels.FirstOrDefault();
                    if (channel == null)
                        return;

                    Console.WriteLine("Joined channel!");

                    channel.MessageReceived += HandleMessage;
                    channel.UserJoined += (sender1, userEventArgs) =>
                    {
                        string joinMessage = String.Format("Used joined: {0}", userEventArgs.Comment ?? "No comment");

                        foreach (Command command in commands)
                            command.HandlePassive(joinMessage, userEventArgs.ChannelUser.User.NickName);
                    };
//.........这里部分代码省略.........
开发者ID:ponglesesquire,项目名称:Assbot,代码行数:101,代码来源:Bot.cs

示例3: Connect

        /// <summary>
        /// Connect to the given stream, returns true if we successfully connected.  Note
        /// that this function executes synchronously, and will block until fully connected
        /// to the IRC server.
        /// </summary>
        /// <param name="stream">The stream to connect to.</param>
        /// <param name="user">The twitch username this connection will use.</param>
        /// <param name="auth">The twitch API token used to log in.  This must begin with 'oauth:'.</param>
        public bool Connect(string stream, string user, string auth)
        {
            user = user.ToLower();
            m_stream = stream.ToLower();

            // Create client and hook up events.
            string server = "irc.twitch.tv";
            int port = 6667;

            WriteDiagnosticMessage("Attempting to connect to server...");

            m_client = new IrcClient();
            m_client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);

            m_client.Connected += client_Connected;
            m_client.ConnectFailed += client_ConnectFailed;
            m_client.Disconnected += client_Disconnected;
            m_client.Error += client_Error;
            m_client.Registered += client_Registered;
            m_client.ErrorMessageReceived += client_ErrorMessageReceived;

            // Connect to server.
            IPHostEntry hostEntry = Dns.GetHostEntry(server);
            m_client.Connect(new IPEndPoint(hostEntry.AddressList[0], port), false, new IrcUserRegistrationInfo()
            {
                NickName = user,
                UserName = user,
                RealName = user,
                Password = auth
            });

            // Wait for the server to connect.  The connect function on client operates asynchronously, so we
            // wait on s_connectedEvent which is set when client_Connected is called.
            if (!m_connectedEvent.Wait(10000))
            {
                WriteDiagnosticMessage("Connection to '{0}' timed out.", server);
                return false;
            }

            /// Wait for the client to be registered.
            if (!m_registeredEvent.Wait(10000))
            {
                WriteDiagnosticMessage("Registration timed out.", server);
                return false;
            }

            // Attempt to join the channel.  We'll try for roughly 10 seconds to join.  This really shouldn't ever fail.
            m_client.Channels.Join("#" + m_stream);
            int max = 40;
            while (m_client.Channels.Count == 0 && !m_joinedEvent.Wait(250))
            {
                max--;
                if (max < 0)
                {
                    WriteDiagnosticMessage("Failed to connect to {0}  Please press Reconnect.", m_stream);
                    return false;
                }
            }

            WriteDiagnosticMessage("Connected to channel {0}.", m_stream);

            // This command tells twitch that we are a chat bot capable of understanding subscriber/turbo/etc
            // messages.  Without sending this raw command, we would not get that data.
            m_client.SendRawMessage("TWITCHCLIENT 2");

            UpdateMods();
            return true;
        }
开发者ID:BigAbboTT,项目名称:WinterBot,代码行数:76,代码来源:TwitchClient.cs

示例4: Connect

        /// <summary>
        /// Connect to the given stream, returns true if we successfully connected.  Note
        /// that this function executes synchronously, and will block until fully connected
        /// to the IRC server.
        /// </summary>
        /// <param name="stream">The stream to connect to.</param>
        /// <param name="user">The twitch username this connection will use.</param>
        /// <param name="auth">The twitch API token used to log in.  This must begin with 'oauth:'.</param>
        public ConnectResult Connect(string stream, string user, string auth, int timeout = 10000)
        {
            if (m_shutdown)
                throw new InvalidOperationException("Attempted to connect while disconnecting.");

            user = user.ToLower();
            m_stream = stream.ToLower();

            if (m_data == null)
                m_data = new TwitchUsers(m_stream);

            // Create client and hook up events.
            m_client = new IrcClient();

            m_client.Connected += client_Connected;
            m_client.UnsuccessfulLogin += m_client_UnsuccessfulLogin;
            m_client.ConnectFailed += client_ConnectFailed;
            m_client.Error += client_Error;
            m_client.Registered += client_Registered;
            m_client.ErrorMessageReceived += client_ErrorMessageReceived;
            m_client.PongReceived += m_client_PongReceived;
            m_client.PingReceived += m_client_PingReceived;

            m_flood = new FloodPreventer(this);
            m_flood.RejectedMessage += m_flood_RejectedMessage;
            m_client.FloodPreventer = m_flood;

            int currTimeout = timeout;
            DateTime started = DateTime.Now;

            m_connectedEvent.Reset();
            m_registeredEvent.Reset();
            m_joinedEvent.Reset();

            // Connect to server.
            m_client.Connect("irc.twitch.tv", 6667, false, new IrcUserRegistrationInfo()
            {
                NickName = user,
                UserName = user,
                RealName = user,
                Password = auth
            });

            // Wait for the server to connect.  The connect function on client operates asynchronously, so we
            // wait on s_connectedEvent which is set when client_Connected is called.
            if (!m_connectedEvent.Wait(currTimeout))
            {
                WriteDiagnosticMessage("Connecting to the Twitch IRC server timed out.");
                return ConnectResult.NetworkFailed;
            }

            currTimeout = timeout - (int)started.Elapsed().TotalMilliseconds;
            /// Wait for the client to be registered.
            if (!m_registeredEvent.Wait(currTimeout))
            {
                // Shouldn't really happen
                WriteDiagnosticMessage("Registration timed out.");
                return ConnectResult.Failed;
            }

            if (m_loginFailed)
                return ConnectResult.LoginFailed;

            // Attempt to join the channel.  We'll try for roughly 10 seconds to join.  This really shouldn't ever fail.
            m_client.Channels.Join("#" + m_stream);
            currTimeout = timeout - (int)started.Elapsed().TotalMilliseconds;
            if (!m_joinedEvent.Wait(currTimeout))
            {
                // Shouldn't really happen
                WriteDiagnosticMessage("Failed to join channel {0}.", m_stream);
                return ConnectResult.Failed;
            }

            TwitchSource.Log.Connected(stream);

            // This command tells twitch that we are a chat bot capable of understanding subscriber/turbo/etc
            // messages.  Without sending this raw command, we would not get that data.
            m_client.SendRawMessage("TWITCHCLIENT 3");

            UpdateMods();
            return ConnectResult.Success;
        }
开发者ID:NitroXenon,项目名称:WinterBot,代码行数:90,代码来源:TwitchClient.cs


注:本文中的IrcDotNet.IrcClient.SendRawMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。