So I am making a bot that connects to a twitch irc chat. Here is the code:
Console.WriteLine("Joining Room");
IrcClient irc = new IrcClient("irc.twitch.tv", 6667, "ScottBots", "oauth:asdasd");
irc.joinRoom("ScottBots");
Console.WriteLine("Joined Room");
int i = 0;
while (true)
{
string message = irc.readMessage();
if(message.Contains("!helps"))
{
irc.sendChatMessage("Welcome to ScottBots! Currently in development.");
}
Console.WriteLine("loop: " + i);
i++;
}
Look the the while true loop... Everything good?
Now look at what this console application gives me:
Joining Room
Joined Room
loop: 0
loop: 1
loop: 2
loop: 3
loop: 4
loop: 5
loop: 6
loop: 7
loop: 8
loop: 9
It just stops at 9?
Many of ya'll have been asking for my ircClient Code:
private string username;
private string channel;
private TcpClient tcpClient;
private StreamReader inputStream;
private StreamWriter outputSteam;
public IrcClient(string ip, int port, string username, string password)
{
this.username = username;
tcpClient = new TcpClient(ip, port);
inputStream = new StreamReader(tcpClient.GetStream());
outputSteam = new StreamWriter(tcpClient.GetStream());
try
{
outputSteam.WriteLine("PASS " + password);
outputSteam.WriteLine("NICK " + username);
outputSteam.WriteLine("USER " + username + " 8 * :" + username);
outputSteam.Flush();
} catch (Exception e)
{
}
}
public void joinRoom(string channel)
{
try
{
this.channel = channel;
outputSteam.WriteLine("JOIN #" + channel);
outputSteam.Flush();
}
catch (Exception e)
{
Console.WriteLine("Failed to join room");
}
}
public void sendIrcMessage(string message)
{
try
{
outputSteam.WriteLine(message);
outputSteam.Flush();
}
catch (Exception e)
{
Console.WriteLine("failed to run sendIrcMessage() method");
}
}
public void sendChatMessage(string message)
{
sendIrcMessage(":" + username + "!" + username + "@" + username + ".tmi.twitch.tv PRIVNSG #" + channel + " : " + message);
}
public string readMessage()
{
string message = inputStream.ReadLine();
return message;
}