예제 #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
        public void OnRegistered()
        {
            //We have to catch errors in our delegates because Thresher purposefully
            //does not handle them for us. Exceptions will cause the library to exit if they are not
            //caught.
            try {
                //Don't need this anymore in this example but this can be left running
                //if you want.
                Identd.Stop();

                connection.Sender.PrivateMessage("nickserv", String.Format("identify bluebird"));

                //The connection is ready so lets join a channel.
                //We can join any number of channels simultaneously but
                //one will do for now.
                //All commands are sent to IRC using the Sender object
                //from the Connection.
                connection.Sender.Join(chatChannel);
                connection.Sender.Join(staffChannel);

                EventSink.Login            += new LoginEventHandler(EventSink_Login);
                EventSink.CharacterCreated += new CharacterCreatedEventHandler(EventSink_CharacterCreated);
            }
            catch (Exception e) {
                Console.WriteLine("Error in OnRegistered(): " + e);
            }
        }
예제 #3
0
        public void Start()
        {
            //Notice that by having the actual connect call here
            //the constructor can add the necessary listeners before
            //the connection process begins. If listeners are added
            //after connecting they may miss certain events. the OnRegistered()
            //event will certainly be missed.

            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("Combot connected.");
                //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.
            }
            catch (Exception e) {
                Console.WriteLine("Error during connection process.");
                Console.WriteLine(e);
                Identd.Stop();
            }
        }
예제 #4
0
        /// <summary>
        /// Stops the chat bot
        /// </summary>
        public void StopBot()
        {
            //Check to see that the bot has not already been stopped
            if (!_running)
            {
                return;
            }

            //Turn off the Identd server
            if (Identd.IsRunning())
            {
                Identd.Stop();
            }

            //Disconnects the IRC bot
            if (_irc.Connected)
            {
                _irc.Disconnect("Bot Stopped");
            }

            //Clear user lists
            ResetUsers();

            //Set running flag to false
            _running = false;
        }
예제 #5
0
        /// <summary>
        /// Method called upon the irc connection registering to the IRC server
        /// </summary>
        private void IrcRegistered()
        {
            //Turn off the Identd Server
            if (Identd.IsRunning())
            {
                Identd.Stop();
            }

            //Join the corresponding channel
            _irc.Sender.Join("#" + _channel.ToLower());
        }
예제 #6
0
파일: Bot.cs 프로젝트: nebez/TwitchBot
 public void OnRegistered()
 {
     try
     {
         //Dispose of identd server
         Identd.Stop();
     }
     catch (Exception e)
     {
         Logger.Log.Write("Error in OnRegistered(): " + e.ToString(), ConsoleColor.Red);
     }
 }
예제 #7
0
        /// <summary>
        /// Method called upon the irc connection registering to the IRC server
        /// </summary>
        private void IrcRegistered()
        {
            //Turn off the Identd Server
            if (Identd.IsRunning())
            {
                Identd.Stop();
            }

            //Join the corresponding channel
            _irc.Sender.Join("#" + _channel.ToLower());
            HandleEvent(string.Format("Connected! Joining #{0}", _channel.ToLower()), EventListItem.SuccessColor);
        }
예제 #8
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();
        }
예제 #9
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");
            }
        }
예제 #10
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);
        }
예제 #11
0
        public void OnRegistered()
        {
            //We have to catch errors in our delegates because Thresher purposefully
            //does not handle them for us. Exceptions will cause the library to exit if they are not
            //caught.
            try
            {
                //Don't need this anymore in this example but this can be left running
                //if you want.
                Identd.Stop();

                //The connection is ready so lets join a channel.
                //We can join any number of channels simultaneously but
                //one will do for now.
                //All commands are sent to IRC using the Sender object
                //from the Connection.
                connection.Sender.Join("#" + channelBox.Text);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error in OnRegistered(): " + e);
                this.Invoke(new Action(() => this.chatMessage.Text += "[SYSTEM] Error in OnRegistered(): " + e + "\n"));
            }
        }
예제 #12
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();
            }
        }