Esempio n. 1
0
        async void ReadFromStream()
        {
            string result = "";

            while (status == Status.Connected)
            {
                reader.InputStreamOptions = InputStreamOptions.Partial;
                //string output = await streamReader.ReadLineAsync();
                //Debug.WriteLine(output);
                //try
                //{
                //    var count = await reader.LoadAsync(512);
                //}
                //catch (Exception ex)
                //{
                //    // shit can be broken here, something about closed streams...
                //    Debug.WriteLine(ex.Message);
                //}
                //byte[] content = new byte[reader.UnconsumedBufferLength];
                //reader.ReadBytes(content);
                //result = Encoding.UTF8.GetString(content, 0, content.Length);
                result = await streamReader.ReadLineAsync();

                //List<string> tmpMessages = await ProcessServerResponses(result);
                //foreach (string m in tmpMessages)
                //{
                //    messages.Add(m);
                //}
                messages.Add(result);

                for (int i = 0; i < messages.Count; i++)
                {
                    MessageHandlerEventArgs message = new MessageHandlerEventArgs();
                    message.Message = messages[i];
                    Message(this, message);
                    Debug.WriteLine(messages[i]);
                    await HandleResponse(messages[i]);

                    messages.RemoveAt(i);
                    i--;
                }
            }
        }
Esempio n. 2
0
        async void client_Message(object source, MessageHandlerEventArgs e)
        {
            if (!sentJoin)
            {
                if (e.Message.Contains("376"))
                {
                    await client.SendJoin();

                    sentJoin = true;
                }
            }

            string ircMessagePrefix  = ":" + loginName + ".tmi.twitch.tv ";
            string modsMessagePrefix = ":jtv MODE #" + channelName + " +o ";

            if (e.Message.StartsWith(ircMessagePrefix))
            {
                string ircCommand = e.Message.Substring(ircMessagePrefix.Length, 3);
                if (ircCommand == "353")
                {
                    string   tmpUsersString = e.Message.Substring((ircMessagePrefix + "353 " + loginName + " = #" + channelName + " :").Length);
                    string[] tmpUsers       = tmpUsersString.Split(' ');
                    foreach (string user in tmpUsers)
                    {
                        users.Add(user);
                    }
                }

                if (ircCommand == "366")
                {
                    await client.SendWho();
                }
            }

            if (e.Message.StartsWith(modsMessagePrefix))
            {
                mods.Add(e.Message.Substring(modsMessagePrefix.Length));
            }

            string name        = "";
            string chatMessage = "";

            if (!e.Message.Contains("JOIN #" + channelName) && !e.Message.Contains("PART #" + channelName))
            {
                //Debug.WriteLine(e.Message);
            }

            if (e.Message.Contains("PRIVMSG"))
            {
                int    indexOf      = e.Message.IndexOf("PRIVMSG");
                string userNamePart = "";
                string rest         = "";
                if (indexOf >= 0)
                {
                    try
                    {
                        userNamePart = e.Message.Substring(0, indexOf - 1);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                    rest = e.Message.Substring(indexOf + "PRIVMSG".Length + 1);
                }
                string msg = "";
                chatMessage = rest;

                if (rest.StartsWith(loginName))
                {
                    // this is a message to us
                    chatMessage = rest;
                }
                else
                {
                    // this is a message from someone else
                    int indexOfChannel = rest.IndexOf(channelName);
                    if (indexOfChannel >= 0)
                    {
                        msg = rest.Substring(indexOfChannel + channelName.Length + 2);
                    }
                }

                string[] splitUsername = userNamePart.Split('!');
                if (splitUsername.Length > 1)
                {
                    string[] realUsername = splitUsername[1].Split('@');
                    name = realUsername[0];
                }
                chatMessage = msg;
            }

            await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                if (!connectedToChat)
                {
                    connectedToChat = true;
                    AddChatMessage("", "Connected to chat", false, false);

                    if (AppConstants.ActiveUser != null)
                    {
                        if (AppConstants.ActiveUser.authorized)
                        {
                            chatBox.IsEnabled        = true;
                            chatSendButton.IsEnabled = true;
                        }
                    }
                }

                if (name != "" && chatMessage != "")
                {
                    if (name != "jtv")
                    {
                        bool boldName = name == channelName;
                        AddChatMessage(name, chatMessage, true, boldName);
                        chatView.UpdateLayout();
                    }
                }
            });
        }
Esempio n. 3
0
 void c_Message(object source, MessageHandlerEventArgs e)
 {
     //Debug.WriteLine(e.Message);
 }