using System;
using System.Net.Sockets;
using System.IO;
using System.Windows.Forms;
using System.Threading;
//Thread Shutdown Event
static ManualResetEvent _shutdownEvent = new ManualResetEvent(false);
//Boolean to see if thread is running or not
public bool ChatBotRunning = false;
//Declaring the thread
Thread _thread;
private void StartChatBot()
{
//Loops through the code inside until broken
while (true)
{
try
{
//Reads from a text file containing the user accounts in the same directory as the application.
using (StreamReader TwitchAccountReader = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "/users.txt"))
{
//Declaring strings
string AccountString;
string[] AccountArray;
//Reads a line from the file
AccountString = TwitchAccountReader.ReadLine();
//Basically it will read each line from the text file until it reaches the end
while ((AccountString = TwitchAccountReader.ReadLine()) != null)
{
//Splits the Line in to 2, [0] is the username, [1] is the Oauth
AccountArray = AccountString.Split(':';
//Connects to thw Twitch IRC
using (TcpClient TwitchConnection = new TcpClient("irc.twitch.tv", 6667))
{
//This is what we will use to write commands to the IRC
using (StreamWriter TwitchWriter = new StreamWriter(TwitchConnection.GetStream()))
{
//If the shutdown event is signaled the loop will break and the thread will end
if (_shutdownEvent.WaitOne(0))
break;
//Sets the username
TwitchWriter.WriteLine("USER " + AccountArray[0] + "tmi twitch :" + AccountArray[0]);
//Authorises the account using their Oauth
TwitchWriter.WriteLine("PASS oauth:" + AccountArray[1]);
//Set the Nickname
TwitchWriter.WriteLine("NICK " + AccountArray[0]);
//Joins the twitch channel you're going to be spamming
TwitchWriter.WriteLine("JOIN #" + textBox1.Text);
//Sends your Message through the IRC to the Channel you are spamming
TwitchWriter.WriteLine("PRIVMSG #" + textBox1.Text + " : " + textBox2.Text + " " + R.Next(9999));
}
}
}
//Checks to see if the Account reader has reached the end of the file
if (TwitchAccountReader.EndOfStream == true)
{
//Resets the reader to the beginning so the spam can restart
TwitchAccountReader.DiscardBufferedData();
TwitchAccountReader.BaseStream.Seek(0, SeekOrigin.Begin);
TwitchAccountReader.BaseStream.Position = 0;
}
}
}
catch (Exception ex)
{
//Shows a message box with the exception error
MessageBox.Show(ex.Message);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
//If the Bot is not running
if(ChatBotRunning == false)
{
//Set the Channe Name textbox and Message textbox to disabled
textBox1.Enabled = false;
textBox2.Enabled = false;
//Set our buttons text to 'Stop Chat Bot'
button1.Text = "Stop Chat Bot";
//Set the Boolean StopChatBot to false so it will run
ChatBotRunning = true;
//Start our thread
StartThread();
}
//If the bot is running
else
{
//Set our buttons text to 'Start Chat Bot'
button1.Text = "Start Chat Bot";
//Set the Boolean StopChatBot to true so it will stop
ChatBotRunning = false;
//Set the Channe Name textbox and Message textbox to enabled
textBox1.Enabled = true;
textBox2.Enabled = true;
//Signals the thread shutdown event
StopThread();
}
}
Copyright © 2024, NextGenUpdate.
All Rights Reserved.