Example #1
0
        static async Task<TwitchChannel[]> ConnectAsync(params string[] channelNames)
        {
            TwitchConnection twitch = new TwitchConnection();

            string[] loginData = File.ReadLines("login.txt").Take(2).ToArray();

            var connectResult = await twitch.ConnectAsync(loginData[0], loginData[1]);
            if (connectResult != ConnectResult.Connected)
            {
                Console.WriteLine("Failed to login.");
                return null;
            }

            //TwitchChannel result = Create(channel);
            //await result.JoinAsync();
            //return result;



            TwitchChannel[] channels = (from channelName in channelNames select twitch.Create(channelName)).ToArray();
            Task[] channelTasks = (from channel in channels select channel.JoinAsync()).ToArray();

            var result = new TwitchChannel[channelTasks.Length];

            for (int i = 0; i < result.Length; ++i)
                await channelTasks[i];

            return channels;
        }
Example #2
0
        internal TwitchChannel(TwitchConnection twitch, string channel)
        {
            channel = channel.ToLower();

            m_twitch = twitch;
            Name = channel;
            m_prvtMsg = string.Format("PRIVMSG #{0} :", channel);

            var user = GetUser(channel);
            user.IsStreamer = true;
            user.IsModerator = true;

            User = GetUser(m_twitch.User);
        }
        private TwitchChannel JoinChannel(TwitchConnection twitch, string name)
        {
            var channel = twitch.Create(name);

            channel.ModeratorJoined += ModJoined;
            channel.UserChatCleared += UserClearChatHandler;
            channel.MessageReceived += ChatMessageReceived;
            channel.MessageSent += ChatMessageReceived;
            channel.StatusMessageReceived += JtvMessageReceived;
            channel.ActionReceived += ChatActionReceived;
            channel.UserSubscribed += SubscribeHandler;
            channel.ChatCleared += ChatCleared;
            channel.SlowModeBegin += SlowModeHandler;
            channel.SlowModeEnd += SlowModeEndHandler;
            channel.SubModeBegin += SubModeBeginHandler;
            channel.SubModeEnd += SubModeEndHandler;
            channel.ModListReceived += ModListReceived;
            
            return channel;
        }
        async Task<TwitchChannel> Connect(string channelName)
        {
            Debug.Assert(m_channel == null);

            var twitch = new TwitchConnection(ClientType.Full);
            var connection = twitch.ConnectAsync(m_options.User, m_options.Pass);

            var channel = JoinChannel(twitch, channelName);

            var result = await connection;
            if (result == ConnectResult.LoginFailed)
            {
                WriteStatus("Failed to login, please change options.ini and restart the application.");
                return null;
            }

            while (result != ConnectResult.Connected)
            {
                if (result == ConnectResult.LoginFailed)
                {
                    WriteStatus("Failed to login, please change options.ini and restart the application.");
                    return null;
                }
                else if (result == ConnectResult.NetworkError)
                {
                    if (!NativeMethods.IsConnectedToInternet())
                    {
                        WriteStatus("Not connected to the internet.");
                        do
                        {
                            await Task.Delay(5000);
                        } while (!NativeMethods.IsConnectedToInternet());

                        WriteStatus("Re-connected to the internet.");
                    }
                    else
                    {
                        WriteStatus("Failed to connect: network error");
                    }
                }

                await Task.Delay(5000);
                result = await twitch.ConnectAsync(m_options.User, m_options.Pass);
            }

            await channel.JoinAsync();
            WriteStatus("Connected to channel {0}.", channel.Name);
            return channel;
        }
Example #5
0
        public static IEnumerable<string> TestInput(IEnumerable<string> lines, TwitchConnection.ChannelCreatedHandler chanCreated)
        {
            List<string> errors = new List<string>();

            TwitchConnection twitch = new TwitchConnection(ClientType.Full);
            twitch.ChannelCreated += chanCreated;

            IrcConnection conn = new IrcConnection(ClientType.Full);
            
            foreach (var line in lines)
            {
                int userStart;
                int userEnd;
                string command;
                int args;

                if (ParseLine(line, out userStart, out userEnd, out command, out args))
                {
                    if (!conn.ProcessCommand(line, userStart, userEnd, command, args))
                        errors.Add(line);
                }
                else
                {
                    errors.Add(line);
                }
            }

            return errors;
        }