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 TwitchBot_2._0
- {
- public partial class Form1 : Form
- {
- #region Variables
- private static string userName = BotnameBox.Text.ToLower();
- private static string Streamer = ChannelBox.Text.ToLower();
- #region hiddenpassword
- private static string password = OauthBox.Text.ToLower();
- #endregion
- IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, userName, password);
- NetworkStream serverStream = default(NetworkStream);
- string readData = "";
- Thread chatThread;
- List<string> BannedWords = new List<string> { "penis", "dick", "fuck"};
- List<string> AntiChatSpamBots = new List<string> { "streamer"};
- #endregion
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- irc.leaveRoom();
- serverStream.Dispose();
- Environment.Exit(0);
- }
- private void getMessage()
- {
- serverStream = irc.tcpClient.GetStream();
- int buffsize = 0;
- byte[] instream = 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
- {
- string[] separator = new string[] { "#trolin720 :" };
- string[] singlesep = new string[] { ":","!" };
- if (readData.Contains("PRIVMSG"))
- {
- string username = readData.Split(singlesep, StringSplitOptions.None)[1];
- string message = readData.Split(separator, StringSplitOptions.None)[1];
- if (BannedWordFilter(userName, message)) return;
- if (AntiSpamBotKiller(userName, message)) return;
- if (message[0] == '!')
- commands(username, message);
- chatBox.Text = chatBox.Text + username + ": " + message + Environment.NewLine;
- }
- }
- }
- private void commands(string username, string message)
- {
- string command = message.Split(new[] { ' ', '!'}, StringSplitOptions.None)[1];
- switch(command.ToLower())
- {
- case "bot":
- irc.sendChatMessage("This bot was made by Trolin720 and will be able to be downloaded soon...");
- break;
- case "flabs":
- irc.sendChatMessage("Go watch Flabmania and drop him a follow at Twitch.tv/Flabmania");
- break;
- default:
- break;
- }
- }
- private void botMsg_TextChanged(object sender, EventArgs e)
- {
- botMsg.ForeColor = Color.White;
- if (botMsg.Text == "Send a Message...")
- {
- botMsg.ForeColor = Color.Gray;
- }
- else if (botMsg.Text == "")
- {
- botMsg.ForeColor = Color.White;
- }
- else
- {
- //idk
- }
- }
- private void botMsg_MouseHover(object sender, EventArgs e)
- {
- if (botMsg.Text == "Send a Message...")
- {
- botMsg.Text = "";
- }
- else
- {
- botMsg.Text = botMsg.Text;
- }
- botMsg.ForeColor = Color.White;
- }
- private void botMsg_MouseLeave(object sender, EventArgs e)
- {
- if (botMsg.Text == "")
- {
- botMsg.Text = "Send a Message...";
- }
- else
- {
- botMsg.Text = botMsg.Text;
- }
- botMsg.ForeColor = Color.Gray;
- }
- private void botSend_Click(object sender, EventArgs e)
- {
- irc.sendChatMessage(botMsg.Text);
- chatBox.Text = chatBox.Text + userName + ": " + botMsg.Text + Environment.NewLine;
- if (botMsg.Text == "/clear")
- {
- MessageBox.Show("Deleteing Chat...");
- chatBox.Text = "";
- }
- }
- private bool BannedWordFilter(string username, string message)
- {
- foreach(string word in BannedWords)
- {
- if (message.Contains(word))
- {
- string command = "/timeout " + username + " 300";
- irc.sendChatMessage(command);
- irc.sendChatMessage(username + " that is a Banned Word.");
- return true;
- }
- }
- return false;
- }
- private bool AntiSpamBotKiller(string username, string message)
- {
- foreach (string word in AntiChatSpamBots)
- {
- if (message.Contains(word))
- {
- string command = "/timeout " + username + " 600";
- irc.sendChatMessage(command);
- return true;
- }
- }
- return false;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- irc.joinRoom(ChannelBox.Text.ToLower());
- chatThread = new Thread(getMessage);
- chatThread.Start();
- }
- }
- 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;
- }
- }
- }
- RAW Paste Data
- 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 TwitchBot_2._0
- {
- public partial class Form1 : Form
- {
- #region Variables
- private static string userName = BotnameBox.Text.ToLower();
- private static string Streamer;
- #region hiddenpassword
- private static string password;
- #endregion
- IrcClient irc = new IrcClient("irc.chat.twitch.tv", 6667, userName, password);
- NetworkStream serverStream = default(NetworkStream);
- string readData = "";
- Thread chatThread;
- List<string> BannedWords = new List<string> { "penis", "dick", "fuck"};
- List<string> AntiChatSpamBots = new List<string> { "streamer"};
- #endregion
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void Form1_FormClosing(object sender, FormClosingEventArgs e)
- {
- irc.leaveRoom();
- serverStream.Dispose();
- Environment.Exit(0);
- }
- private void getMessage()
- {
- serverStream = irc.tcpClient.GetStream();
- int buffsize = 0;
- byte[] instream = 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
- {
- string[] separator = new string[] { "#trolin720 :" };
- string[] singlesep = new string[] { ":","!" };
- if (readData.Contains("PRIVMSG"))
- {
- string username = readData.Split(singlesep, StringSplitOptions.None)[1];
- string message = readData.Split(separator, StringSplitOptions.None)[1];
- if (BannedWordFilter(userName, message)) return;
- if (AntiSpamBotKiller(userName, message)) return;
- if (message[0] == '!')
- commands(username, message);
- chatBox.Text = chatBox.Text + username + ": " + message + Environment.NewLine;
- }
- }
- }
- private void commands(string username, string message)
- {
- string command = message.Split(new[] { ' ', '!'}, StringSplitOptions.None)[1];
- switch(command.ToLower())
- {
- case "bot":
- irc.sendChatMessage("This bot was made by Trolin720 and will be able to be downloaded soon...");
- break;
- case "flabs":
- irc.sendChatMessage("Go watch Flabmania and drop him a follow at Twitch.tv/Flabmania");
- break;
- default:
- break;
- }
- }
- private void botMsg_TextChanged(object sender, EventArgs e)
- {
- botMsg.ForeColor = Color.White;
- if (botMsg.Text == "Send a Message...")
- {
- botMsg.ForeColor = Color.Gray;
- }
- else if (botMsg.Text == "")
- {
- botMsg.ForeColor = Color.White;
- }
- else
- {
- //idk
- }
- }
- private void botMsg_MouseHover(object sender, EventArgs e)
- {
- if (botMsg.Text == "Send a Message...")
- {
- botMsg.Text = "";
- }
- else
- {
- botMsg.Text = botMsg.Text;
- }
- botMsg.ForeColor = Color.White;
- }
- private void botMsg_MouseLeave(object sender, EventArgs e)
- {
- if (botMsg.Text == "")
- {
- botMsg.Text = "Send a Message...";
- }
- else
- {
- botMsg.Text = botMsg.Text;
- }
- botMsg.ForeColor = Color.Gray;
- }
- private void botSend_Click(object sender, EventArgs e)
- {
- irc.sendChatMessage(botMsg.Text);
- chatBox.Text = chatBox.Text + userName + ": " + botMsg.Text + Environment.NewLine;
- if (botMsg.Text == "/clear")
- {
- MessageBox.Show("Deleteing Chat...");
- chatBox.Text = "";
- }
- }
- private bool BannedWordFilter(string username, string message)
- {
- foreach(string word in BannedWords)
- {
- if (message.Contains(word))
- {
- string command = "/timeout " + username + " 300";
- irc.sendChatMessage(command);
- irc.sendChatMessage(username + " that is a Banned Word.");
- return true;
- }
- }
- return false;
- }
- private bool AntiSpamBotKiller(string username, string message)
- {
- foreach (string word in AntiChatSpamBots)
- {
- if (message.Contains(word))
- {
- string command = "/timeout " + username + " 600";
- irc.sendChatMessage(command);
- return true;
- }
- }
- return false;
- }
- private void button1_Click(object sender, EventArgs e)
- {
- irc.joinRoom(ChannelBox.Text.ToLower());
- chatThread = new Thread(getMessage);
- chatThread.Start();
- }
- }
- 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