Inheritance: StandardIrcClient
Example #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);
        }
Example #2
0
 public Connection()
 {
     Client = new TwitchIrcClient();
     Client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
     Client.Connected += ConnectionEvents.OnConnected;
     Client.Disconnected += ConnectionEvents.OnDisconnected;
     Client.Registered += ConnectionEvents.OnRegistered;
     Client.ConnectFailed += ConnectionEvents.OnConnectFailed;
     Client.RawMessageReceived += ConnectionEvents.RawMessageReceived;
     _logger = PluginStore.Container.GetExport<ILog>().Value;
 }
Example #3
0
        public static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: twitchirc <username> <oauth>");
                Console.WriteLine("Use http://twitchapps.com/tmi/ to generate an <oauth> token!");
                return;
            }

            var server   = "irc.twitch.tv";
            var username = args[0];
            var password = args[1];

            Console.WriteLine("Starting to connect to twitch as {0}.", username);

            using (var client = new IrcDotNet.TwitchIrcClient())
            {
                client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
                client.Disconnected  += IrcClient_Disconnected;
                client.Registered    += IrcClient_Registered;
                // Wait until connection has succeeded or timed out.
                using (var registeredEvent = new ManualResetEventSlim(false))
                {
                    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 = username,
                            Password = password,
                            UserName = username
                        });
                        if (!connectedEvent.Wait(10000))
                        {
                            Console.WriteLine("Connection to '{0}' timed out.", server);
                            return;
                        }
                    }
                    Console.Out.WriteLine("Now connected to '{0}'.", server);
                    if (!registeredEvent.Wait(10000))
                    {
                        Console.WriteLine("Could not register to '{0}'.", server);
                        return;
                    }
                }

                Console.Out.WriteLine("Now registered to '{0}' as '{1}'.", server, username);
                HandleEventLoop(client);
            }
        }
Example #4
0
        public static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Usage: twitchirc <username> <oauth>");
                Console.WriteLine("Use http://twitchapps.com/tmi/ to generate an <oauth> token!");
                return;
            }

            var server = "irc.twitch.tv";
            var username = args[0];
            var password = args[1];
            Console.WriteLine("Starting to connect to twitch as {0}.", username);

            using (var client = new IrcDotNet.TwitchIrcClient())
            {
                client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
                client.Disconnected += IrcClient_Disconnected;
                client.Registered += IrcClient_Registered;
                // Wait until connection has succeeded or timed out.
                using (var registeredEvent = new ManualResetEventSlim(false))
                {
                    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 = username,
                                Password = password,
                                UserName = username });
                        if (!connectedEvent.Wait(10000))
                        {
                            Console.WriteLine("Connection to '{0}' timed out.", server);
                            return;
                        }
                    }
                    Console.Out.WriteLine("Now connected to '{0}'.", server);
                    if (!registeredEvent.Wait(10000))
                    {
                        Console.WriteLine("Could not register to '{0}'.", server);
                        return;
                    }
                }

                Console.Out.WriteLine("Now registered to '{0}' as '{1}'.", server, username);
                HandleEventLoop(client);
            }
        }
Example #5
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;
                }
            }
        }
		void Start() {
			settingsFilePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/" + settingsFileName;

			loadSettings();

			twitchApiHeaders.Add("Accept", "application/vnd.twitchtv.v3+json");
			twitchApiHeaders.Add("Authorization", "OAuth " + settings.twitchOAuthToken);
			twitchApiHeaders.Add("Client-ID", twitchClientID);

			ircClient = new TwitchIrcClient();
			// Twitch doesn't allow sending more than 20 messages within 30 seconds
			ircClient.FloodPreventer = new IrcStandardFloodPreventer(1, (long)((30f / 20) * 1000));

			ircClient.Connected += onIrcConnected;
			ircClient.Disconnected += onIrcDisconnected;
			ircClient.Registered += onIrcRegistered;
			ircClient.Error += onIrcError;
			ircClient.ErrorMessageReceived += onIrcErrorMessageReceived;
			ircClient.RawMessageReceived += onIrcRawMessageReceived;
		}
Example #7
0
 public void ConnectToTwitch()
 {
     var sServer = "irc.twitch.tv";
     var username = "******";
     var password = "******";
     isExit = false;
     using (var client = new IrcDotNet.TwitchIrcClient())
     {
         client.FloodPreventer = new IrcStandardFloodPreventer(2, 2500);
         client.Disconnected += IrcClient_Disconnected;
         client.Registered += IrcClient_Registered;
         using (var registeredEvent = new ManualResetEventSlim(false))
         {
             using (var connectedEvent = new ManualResetEventSlim(false))
             {
                 client.Connected += (sender2, e2) => connectedEvent.Set();
                 client.Registered += (sender2, e2) => registeredEvent.Set();
                 client.Connect(sServer, false,
                     new IrcUserRegistrationInfo()
                     {
                         NickName = username,
                         Password = password,
                         UserName = username
                     });
                 if (!connectedEvent.Wait(10000))
                 {
                     return;
                 }
             }
             if (!registeredEvent.Wait(10000))
             {
                 return;
             }
         }
         LocalClient = client;
         HandleEventLoop(client, sChannel);
     }
 }
 public ChatAPI(string server, string password, string channel, string username)
 {
     Server       = server;
     Password     = password;
     Channel      = channel;
     Username     = username;
     TwitchClient = new IrcDotNet.TwitchIrcClient();
     TwitchClient.FloodPreventer = new IrcStandardFloodPreventer(4, 2000);
     TwitchClient.Disconnected  += IrcClient_Disconnected;
     TwitchClient.Registered    += IrcClient_Registered;
     // Wait until connection has succeeded or timed out.
     using (var registeredEvent = new ManualResetEventSlim(false))
     {
         using (var connectedEvent = new ManualResetEventSlim(false))
         {
             TwitchClient.Connected  += (sender2, e2) => connectedEvent.Set();
             TwitchClient.Registered += (sender2, e2) => registeredEvent.Set();
             TwitchClient.Connect(Server, false, new IrcUserRegistrationInfo()
             {
                 NickName = Username,
                 Password = Password,
                 UserName = Username
             });
             if (!connectedEvent.Wait(10000))
             {
                 throw new InvalidOperationException($"Connection to '{Server}' timed out.");
             }
         }
         Console.Out.WriteLine("Now connected to '{0}'.", Server);
         if (!registeredEvent.Wait(10000))
         {
             throw new InvalidOperationException($"Could not register to '{Server}'.");
         }
         Console.Out.WriteLine("Now registered to '{0}' as '{1}'.", Server, Username);
     }
 }
Example #9
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);
                }

            }

        }