예제 #1
0
        private void CreateConnection()
        {
            //The hostname of the IRC server
            string server = "irc.darkmyst.org";

            //The bot's nick on IRC
            string nick = "ComBot";

            //Fire up the Ident server for those IRC networks
            //silly enough to use it.
            Identd.Start(nick);

            //A ConnectionArgs contains all the info we need to establish
            //our connection with the IRC server and register our bot.
            //This line uses the simplfied contructor and the default values.
            //With this constructor the Nick, Real Name, and User name are
            //all set to the same value. It will use the default port of 6667 and no server
            //password.
            ConnectionArgs cargs = new ConnectionArgs(nick, server);

            //When creating a Connection two additional protocols may be
            //enabled: CTCP and DCC. In this example we will disable them
            //both.
            connection = new Connection(cargs, false, false);

            //NOTE
            //We could have created multiple Connections to different IRC servers
            //and each would process messages simultaneously and independently.
            //There is no fixed limit on how many Connection can be opened at one time but
            //it is important to realize that each runs in its own Thread. Also,  separate event
            //handlers are required for each connection, i.e. the
            //same OnRegistered() handler cannot be used for different connection
            //instances.
        }
예제 #2
0
파일: Bot.cs 프로젝트: nebez/TwitchBot
        public void Connect(string host, int port, string botnickname, string serverpassword)
        {
            //Create Identd server
            Identd.Start(botnickname);

            //Create connection args
            ircArgs                = new ConnectionArgs();
            ircArgs.Hostname       = host;
            ircArgs.Port           = port;
            ircArgs.ClientName     = "TWITCHCLIENT 3"; //yay, twitchclient 3 is out!
            ircArgs.Nick           = botnickname;
            ircArgs.RealName       = botnickname;
            ircArgs.UserName       = botnickname;
            ircArgs.ServerPassword = serverpassword;

            //Create ircConnection
            ircConnection = new Connection(ircArgs, false, false);

            //Setup our irc event handlers
            ircConnection.Listener.OnRegistered        += new RegisteredEventHandler(OnRegistered);
            ircConnection.Listener.OnPublic            += new PublicMessageEventHandler(OnPublic);
            ircConnection.Listener.OnPrivate           += new PrivateMessageEventHandler(OnPrivate);
            ircConnection.Listener.OnChannelModeChange += new ChannelModeChangeEventHandler(OnChannelModeChange);
            ircConnection.Listener.OnError             += new ErrorMessageEventHandler(OnError);
            ircConnection.Listener.OnDisconnected      += new DisconnectedEventHandler(OnDisconnected);
            ircConnection.Listener.OnAction            += new ActionEventHandler(OnAction);

            //Let's try connecting!
            try
            {
                Logger.Log.Write("Connecting to " + host + ":" + port + "...", ConsoleColor.DarkGray);
                ircConnection.Connect();
            }
            catch (Exception e)
            {
                Logger.Log.Write("Error connecting to network, exception: " + e.ToString(), ConsoleColor.Red);
                Identd.Stop();
                return;
            }

            //We made it!
            Logger.Log.Write("Connected to " + host, ConsoleColor.DarkGray);

            //Create our message queue poller
            messageQueue = new Queue <KeyValuePair <Channel, string> >();
            previousMessageTimestamps = new List <int>();
            messageThread             = new Thread(new ThreadStart(MessagePoller));
            messageThread.Start();
        }
예제 #3
0
        /// <summary>
        /// Starts the chat bot with pre-designated settings
        /// </summary>
        public void StartBot()
        {
            //Check to see that the bot has not already been started
            if (_running)
            {
                return;
            }

            //Check requirements
            if (string.IsNullOrEmpty(_botUsername))
            {
                throw new Exception("No bot account info defined");
            }

            //Message about mod req
            if (!Commands.RequiresMod)
            {
                HandleEvent("This bot does not require channel mod.", EventListItem.WarningColor);
            }

            //Reset user lists
            ResetUsers();

            //Starts the Identd server - Not necessary, but may be implemented by Twitch at some point
            Identd.Start(_botUsername);
            _irc = new Connection(GetConnArgs(), false, false);

            //Setup irc listeners
            _irc.Listener.OnRegistered        += IrcRegistered;
            _irc.Listener.OnNames             += IrcOnNames;
            _irc.Listener.OnJoin              += IrcJoined;
            _irc.Listener.OnPart              += IrcPart;
            _irc.Listener.OnPublic            += IrcPublic;
            _irc.Listener.OnPrivate           += IrcPrivate;
            _irc.Listener.OnChannelModeChange += Listener_OnChannelModeChange;

            try
            {
                //Attempt a connection the server
                _irc.Connect();

                //Set running flag to true
                _running = true;
            }
            catch (SocketException ex)
            {
                throw new Exception("Unable to connect to the IRC server");
            }
        }
예제 #4
0
        /// <summary>
        /// Starts the chat bot with pre-designated settings
        /// </summary>
        public bool StartBot()
        {
            //Check to see that the bot has not already been started
            if (_running)
            {
                return(false);
            }

            //Check requirements
            if (string.IsNullOrEmpty(_botUsername))
            {
                throw new Exception("No bot account info defined");
            }

            //Reset user lists
            ResetUsers();

            //Starts the Identd server - Not necessary, but may be implemented by Twitch at some point
            if (!Identd.IsRunning())
            {
                Identd.Start(_botUsername);
            }
            _irc = new Connection(GetConnArgs(), false, false);

            //Setup irc listeners
            _irc.Listener.OnRegistered        += IrcRegistered;
            _irc.Listener.OnNames             += IrcOnNames;
            _irc.Listener.OnJoin              += IrcJoined;
            _irc.Listener.OnPart              += IrcPart;
            _irc.Listener.OnPublic            += IrcPublic;
            _irc.Listener.OnPrivate           += IrcPrivate;
            _irc.Listener.OnChannelModeChange += Listener_OnChannelModeChange;
            _irc.Listener.OnError             += Listener_OnError;

            try
            {
                //Attempt a connection the server
                _irc.Connect();

                //Set running flag to true
                _running = true;
            }
            catch (SocketException ex)
            {
                //throw new Exception("Unable to connect to the IRC server");
                return(false);
            }
            return(true);
        }
예제 #5
0
        // IRC COMMANDS
        private void CreateConnection()
        {
            //The hostname of the IRC server
            string server = serverBox.Text;

            //The bot's nick on IRC
            string nick     = usernameBox.Text;
            string password = OAuthBox.Text;

            //Fire up the Ident server for those IRC networks
            //silly enough to use it.
            Identd.Start(nick);

            //A ConnectionArgs contains all the info we need to establish
            //our connection with the IRC server and register our bot.
            //This line uses the simplfied contructor and the default values.
            //With this constructor the Nick, Real Name, and User name are
            //all set to the same value. It will use the default port of 6667 and no server
            //password.
            ConnectionArgs cargs = new ConnectionArgs(nick, server);

            cargs.ServerPassword = password;
            cargs.Port           = 6667;

            //When creating a Connection two additional protocols may be
            //enabled: CTCP and DCC. In this example we will disable them
            //both.
            connection = new Connection(cargs, false, false);

            //NOTE
            //We could have created multiple Connections to different IRC servers
            //and each would process messages simultaneously and independently.
            //There is no fixed limit on how many Connection can be opened at one time but
            //it is important to realize that each runs in its own Thread. Also,separate event
            //handlers are required for each connection, i.e. the
            //same OnRegistered () handler cannot be used for different connection
            //instances.
            try
            {
                //Calling Connect() will cause the Connection object to open a
                //socket to the IRC server and to spawn its own thread. In this
                //separate thread it will listen for messages and send them to the
                //Listener for processing.
                connection.Connect();
                Console.WriteLine("Connected.");
                this.Invoke(new Action(() => this.chatMessage.Text += "[SYSTEM] CONNECTED to " + server + ":6667 #" + channelBox.Text + " with " + nick + "\n"));
                this.Invoke(new Action(() => this.chart1.Series["User(s) in chat"].Points.AddXY(DateTime.Now.ToString("H:mm"), 1)));

                this.Invoke(new Action(() => {
                    this.connectButton.Enabled = false;
                    this.infoPanel.Enabled     = false;
                    this.topPanel.Enabled      = true;
                    this.chatText.Enabled      = true;
                    this.chatButton.Enabled    = true;
                    EnableTab(this.giveawayPage, true);
                    EnableTab(this.bettingPage, true);
                    EnableTab(this.challengePage, true);
                    EnableTab(this.graphPage, true);
                    EnableTab(this.databasePage, true);
                    currentGiveawayBox.Enabled = false;
                    currentBet.Enabled         = false;

                    timer5min          = new System.Timers.Timer(1000);
                    timer5min.Elapsed += new ElapsedEventHandler(timerTick);
                    timer5min.Enabled  = true;                     // Enable it
                    nextSync           = UnixTimeNow() + (60 * 5); // sync every 5 min
                    nextMin            = UnixTimeNow() + 60;
                }));


                //The main thread ends here but the Connection's thread is still alive.
                //We are now in a passive mode waiting for events to arrive.
                connection.Sender.PublicMessage("#" + channelBox.Text, "HugBotty.com is in da house!");
            }
            catch (Exception e)
            {
                Console.WriteLine("Error during connection process.");
                this.Invoke(new Action(() => this.chatMessage.Text += "[SYSTEM] Error during connection process.\n"));
                Console.WriteLine(e);
                Identd.Stop();
            }
        }