Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Net;
- using System.Net.Sockets;
- using System.IO;
- using System.Threading;
- using System.Text.RegularExpressions;
- using System.Runtime.InteropServices;
- using System.Media;
- using System.Diagnostics;
- namespace DorpBot
- {
- public partial class Form1 : Form
- {
- #region Variables
- private static string userName = "dorpbot";
- private static string password = "MyToken";
- IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, userName, password);
- NetworkStream serverStream = default(NetworkStream);
- string readDATA = "";
- Thread chatThread;
- #endregion
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- irc.joinRoom("xiff_");
- chatThread = new Thread(getMessage);
- chatThread.Start();
- }
- private void getMessage()
- {
- serverStream = irc.tcpClient.GetStream();
- int buffsize = 0;
- byte[] intStream = new byte[10025];
- buffsize = irc.tcpClient.ReceiveBufferSize;
- while (true)
- {
- try
- {
- readDATA = irc.readMessage();
- msg();
- }
- catch (Exception e)
- {
- }
- }
- }
- private void msg()
- {
- if (this.InvokeRequired)
- this.Invoke(new MethodInvoker(msg));
- else
- {
- chatBox.Text = chatBox.Text + readDATA.ToString() + Environment.NewLine;
- }
- }
- }
- class IrcClient
- {
- private string userName;
- private string channel;
- public TcpClient tcpClient;
- private StreamReader InputStream;
- private StreamWriter OutputStream;
- public IrcClient(string ip, int port, string userName, string password)
- {
- tcpClient = new TcpClient(ip, port);
- InputStream = new StreamReader(tcpClient.GetStream());
- OutputStream = new StreamWriter(tcpClient.GetStream());
- OutputStream.WriteLine("PASS " + password);
- OutputStream.WriteLine("NICK " + userName);
- OutputStream.WriteLine("USER " + userName + " 8 * :" + userName);
- OutputStream.WriteLine("CAP REQ :twitch.tv/membership");
- OutputStream.WriteLine("CAP REQ :twitch.tv/commands");
- OutputStream.Flush();
- }
- public void joinRoom(string channel)
- {
- this.channel = channel;
- OutputStream.WriteLine("JOIN #" + channel);
- OutputStream.Flush();
- }
- public void leaveRoom()
- {
- OutputStream.Close();
- InputStream.Close();
- }
- public void sendIrcMessage(string message)
- {
- OutputStream.WriteLine(message);
- OutputStream.Flush();
- }
- public void sendChatMessage(string message)
- {
- sendIrcMessage(":" + userName + "!" + userName + "@" + userName + ".tmi.twitch.tv PRIVMSG #" + channel + " :" + message);
- }
- public void PingResponse()
- {
- sendIrcMessage("PONG tmi.twitch.tv\r\n");
- }
- public string readMessage()
- {
- string message = "";
- message = InputStream.ReadLine();
- return message;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement