Guest User

Form1.cs

a guest
Jan 9th, 2017
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using System.Net;
  12. using System.Net.Sockets;
  13. using System.IO;
  14. using System.Threading;
  15. using System.Text.RegularExpressions;
  16. using System.Runtime.InteropServices;
  17. using System.Media;
  18. using System.Diagnostics;
  19.  
  20. namespace WindowsFormsApplication1
  21. {
  22. public partial class Form1 : Form
  23. {
  24. #region variables
  25. public static string userName = "blahblah";
  26. public static string password = "oauth:blahblah";
  27. private static IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, userName, password);
  28. NetworkStream serverStream = default(NetworkStream);
  29. string readData = "";
  30. Thread chatThread;
  31. public Form1()
  32. {
  33. InitializeComponent();
  34. }
  35.  
  36. private void Form1_Load(object sender, EventArgs e)
  37. {
  38. irc.joinRoom("larklen");
  39. chatThread = new Thread(getMessage);
  40. chatThread.Start();
  41. }
  42.  
  43. private void getMessage()
  44. {
  45. serverStream = irc.tcpClient.GetStream();
  46. int buffsize = 0;
  47. byte[] inStream = new byte[10025];
  48. buffsize = irc.tcpClient.ReceiveBufferSize;
  49. while (true)
  50. {
  51. try
  52. {
  53. readData = irc.readMessage();
  54. msg();
  55. }
  56. catch (Exception)
  57. {
  58.  
  59. }
  60. }
  61. }
  62.  
  63. private void msg()
  64. {
  65. if (this.InvokeRequired) this.Invoke(new MethodInvoker(msg));
  66. else
  67. {
  68. string[] separator = new string[] { "#larklen :" };
  69. string[] singlesep = new string[] { ":", "!" };
  70.  
  71. if (readData.Contains("PRIVMSG"))
  72. {
  73. string username = readData.Split(singlesep, StringSplitOptions.None)[1];
  74. string message = readData.Split(separator, StringSplitOptions.None)[1];
  75.  
  76.  
  77. richTextBox1.Text = richTextBox1.Text + username + "> " + message + Environment.NewLine;
  78.  
  79. int num = richTextBox1.Lines.Count();
  80. if (richTextBox1.Lines.Count() > 301)
  81. {
  82. var foos = new List<string>(richTextBox1.Lines);
  83. foos.RemoveAt(0);
  84. richTextBox1.Lines = foos.ToArray();
  85. }
  86. }
  87. }
  88. }
  89.  
  90. }
  91. }
  92. #endregion
Add Comment
Please, Sign In to add comment