Esempio n. 1
0
        static void Main(string[] args)
        {
            // --- FOR LOCAL TESTING -----

            //Console.Write("Enter test command : ");
            //string btn = Console.ReadLine();

            //FocusWindow();
            //MapKeys(btn);

            //Main(args);
            // --- END LOCAL TESTING ----

            // ---  START PROGRAM ----
            //Popup the log window for commands
            Thread formThread = new Thread(StartWindow);

            formThread.Start();

            //Get your oauth info for IRC chat.  http://twitchapps.com/tmi/
            //TODO: Add OAuth automatically
            //Read .ini file
            string  inifilepath = Application.StartupPath + "\\settings.ini";
            INIFile ini         = new INIFile(inifilepath);
            string  TOauth      = ini.Read("Twitch", "Oauth");

            if (TOauth == "")
            {
                Console.WriteLine("Please config the app in config.ini");
                Sleep(1000);
                return;
            }
            //--------------
            Console.Write(TOauth);
            string pass = TOauth;

            //Start IRC process
            RunIRC(pass);
        }
Esempio n. 2
0
        public static void RunIRC(string pass)
        {
            int    port;
            string buf, nick, owner, server, chan;

            System.Net.Sockets.TcpClient sock = new System.Net.Sockets.TcpClient();
            System.IO.TextReader         input;
            System.IO.TextWriter         output;

            //Read .ini file
            string  inifilepath = Application.StartupPath + "\\settings.ini";
            INIFile ini         = new INIFile(inifilepath);
            string  TUsername   = ini.Read("Twitch", "Username");

            //--------------
            nick   = TUsername;
            owner  = TUsername;
            server = "irc.twitch.tv";
            port   = 6667;
            chan   = "#" + TUsername;

            Console.Clear();

            //Connect to irc server and get input and output text streams from TcpClient.
            sock.Connect(server, port);
            if (!sock.Connected)
            {
                Console.WriteLine("Failed to connect!");
                return;
            }
            else
            {
                Console.WriteLine("Conected to " + chan);
            }
            input  = new System.IO.StreamReader(sock.GetStream());
            output = new System.IO.StreamWriter(sock.GetStream());

            //Starting USER and NICK login commands
            output.Write(
                "USER " + nick + "\n" +
                "PASS " + pass + "\r\n" +
                "NICK " + nick + "\r\n"
                );
            output.Flush();

            //Process each line received from irc server
            while ((buf = input.ReadLine()) != null)
            {
                //Display received irc message
                //
                if (buf != null)
                {
                    //Console.WriteLine(buf);
                    checkCommands(buf);

                    //Send pong reply to any ping messages
                    if (buf.StartsWith("PING ") || (buf.Contains("PING") && buf.Contains("mwax321")))
                    {
                        output.Write(buf.Replace("PING", "PONG") + "\r\n"); output.Flush();
                    }

                    if (buf.Contains("mwax321") && buf.Contains("clear"))
                    {
                        Console.Clear();
                    }

                    if (buf[0] != ':')
                    {
                        continue;
                    }

                    /* IRC commands come in one of these formats:
                     * :NICK!USER@HOST COMMAND ARGS ... :DATA\r\n
                     * :SERVER COMAND ARGS ... :DATA\r\n
                     */

                    //After server sends 001 command, we can set mode to bot and join a channel
                    if (buf.Split(' ')[1] == "001")
                    {
                        output.Write(
                            "MODE " + nick + " +B\r\n" +
                            "JOIN " + chan + "\r\n"
                            );
                        output.Flush();
                    }
                }
                else
                {
                    Console.WriteLine("Null detected... ");
                    RunIRC(pass);
                }
            }
            Console.WriteLine("Null detected... ");
            RunIRC(pass);
        }