예제 #1
0
        static void send_twitch_message(string account, string message)
        {
            var server = "irc.twitch.tv";

            var username = account.Split('#')[0];
            var oauth    = account.Split('#')[1];


            var client = new IrcDotNet.TwitchIrcClient();

            client.Connect(server, false, new IrcUserRegistrationInfo()
            {
                NickName = username, Password = oauth, UserName = username
            });


            client.SendRawMessage("PASS " + oauth + "\n");
            client.SendRawMessage("NICK " + username + "\n");
            client.SendRawMessage("JOIN #" + victim + "\n");


            string say = ":[email protected] PRIVMSG #CHANNEL :MESSAGE";

            say = say.Replace("USER", username);
            say = say.Replace("CHANNEL", victim);
            say = say.Replace("MESSAGE", message);
            client.SendRawMessage(say);
        }
예제 #2
0
        public void Start(TwitchIrcClient client, ICommandQueue queue)
        {
            while (!stopRunning)
            {
                var command = queue.DequeueCommand();

                if (string.IsNullOrWhiteSpace(command))
                {
                    _resetEvent.WaitOne();
                }
                if (command != "exit")
                {
                    client.SendRawMessage(command);
                }
                else if (command == "exit")
                {
                    stopRunning = true;
                }
            }
        }
        public void HandleEventLoop()
        {
            JoinChannel(TwitchClient, Channel);
            bool isExit = false;

            while (!isExit)
            {
                Console.Write("> ");
                var command = Console.ReadLine();
                switch (command)
                {
                case "exit":
                    isExit = true;
                    SendMessageInChannel("Dehydration Bot Offline BibleThump");
                    File.WriteAllText("persist.json", JsonConvert.SerializeObject(new { Time = Program.Time }));
                    Thread.Sleep(1000);
                    Environment.Exit(0);
                    break;

                default:
                    if (!string.IsNullOrEmpty(command))
                    {
                        if (command.StartsWith("/") && command.Length > 1)
                        {
                            TwitchClient.SendRawMessage(command.Substring(1));
                        }
                        else if (command.StartsWith("#") && command.Length > 1)
                        {
                            SendMessageInChannel(TwitchClient, Channel, command.Substring(1));
                        }
                        else
                        {
                            Console.WriteLine("unknown command '{0}'", command);
                        }
                    }
                    break;
                }
            }
            TwitchClient.Disconnect();
        }
예제 #4
0
        public void StartBot()
        {
            string server = BotSettings.TwitchIRC;
            logger.Debug("Connecting to IRC...");
            Console.WriteLine("Connecting...");
            Console.WriteLine("");
            using (var client = new TwitchIrcClient())
            {
                client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
                client.Registered += IrcClient_Registered;
                // Wait until connection has succeeded or timed out.
                using (var registeredEvent = new ManualResetEventSlim(false))
                {
                    //Group chat - for whisper (not using)
                    //byte[]ip = {199,9,253,119};
                    //IPAddress p = new IPAddress(ip);
                    //IPEndPoint i = new IPEndPoint(p, 443);

                        using (var connectedEvent = new ManualResetEventSlim(false))
                        {
                            client.Connected += (sender2, e2) => connectedEvent.Set();
                            client.Registered += (sender2, e2) => registeredEvent.Set();
                            client.Connect(server, false,
                                new IrcUserRegistrationInfo()
                                {
                                    NickName = BotSettings.UserName,
                                    Password = BotSettings.OAuthChat,
                                    UserName = BotSettings.UserName
                                });
                            if (!connectedEvent.Wait(3000))
                            {
                                isConnectedToIRC = false;
                                DisplayConnectionError(server);
                                OpenSettingsWindow();
                                Console.WriteLine();
                                Console.WriteLine();
                                Console.WriteLine("Press Enter to restart Bot and apply new settings..");
                                Console.WriteLine();
                                Console.ReadLine();
                                Restart = true;
                        }
                    }

                    if (!registeredEvent.Wait(3000))
                    {
                        if (isConnectedToIRC)
                        {
                            isConnectedToIRC = false;
                            DisplayConnectionError(server);
                            OpenSettingsWindow();
                            Console.WriteLine();
                            Console.WriteLine();
                            Console.WriteLine("Press Enter to restart Bot and apply new settings.");
                            Console.WriteLine();
                            Console.ReadLine();
                            Restart = true;
                        }
                    }
                }

                if (isConnectedToIRC)
                {
                    logger.Debug("Connected, about to join channel.");
                    twitchAPI = new TwitchAPI(BotSettings.BotOAuth, BotSettings.BotClientID);
                    client.SendRawMessage("CAP REQ :twitch.tv/membership");  //request to have Twitch IRC send join/part & modes.
                    client.Join(MAINCHANNEL);
                    HandleEventLoop(client);
                }

            }

        }