I did a simple irc bot how can i send a message to the channel after
joined a channel?
This is the code :
private void connectToIrc()
{
//Connect to irc server and get input and output text streams
from TcpClient.
nick = textBox1.Text;
owner = textBox2.Text;
server = textBox3.Text;
port = Convert.ToInt32(textBox4.Text);
chan = "#" + textBox5.Text;
sock.Connect(server, port);//server, port);
richTextBox1.Invoke((MethodInvoker)delegate
{
ColorText.AppendText(richTextBox1, "Server: ", Color.Green);
ColorText.AppendText(richTextBox1, server+" ",
Color.Red);
ColorText.AppendText(richTextBox1, "Port: ", Color.Green);
ColorText.AppendText(richTextBox1, port.ToString() +
Environment.NewLine + Environment.NewLine, Color.Red);
});
if (!sock.Connected)
{
Console.WriteLine("Failed to connect!");
return;
}
input = new System.IO.StreamReader(sock.GetStream());
output = new System.IO.StreamWriter(sock.GetStream());
//Starting USER and NICK login commands
output.Write(
"USER " + nick + " 0 * :" + owner + "\r\n" +
"NICK " + nick + "\r\n"
);
output.Flush();
//Process each line received from irc server
//buf = input.ReadLine();
while ((buf = input.ReadLine()) != null)
{
buf = buf + Environment.NewLine;
//Display received irc message
//Console.WriteLine(buf);
richTextBox1.Invoke((MethodInvoker)delegate
{
ColorText.AppendText(richTextBox1, buf,Color.Black);
});
if (buf.StartsWith("ERROR")) break;
//Send pong reply to any ping messages
if (buf.StartsWith("PING ")) {
output.Write(buf.Replace("PING", "PONG") + "\r\n");
output.Flush(); }
if (buf[0] != ':') continue;
//After server sends 001 command, we can set mode to bot and
join a channel
if (buf.Split(' ')[1] == "001")
{
output.Write(
"MODE " + nick + " +B\r\n" +
"JOIN " + chan + "\r\n" + "PRIVMSG " + chan + " :hello"
);
output.Flush();
}
buf = input.ReadLine();
}
}
I added this part to the code: + "PRIVMSG " + chan + " :hello" But it does
nothing i dont see any "hello" in the channel.
I used the example in this site :
http://jakash3.wordpress.com/2012/02/13/simple-vb-net-and-csharp-irc-client/
The C# example.
How can i send a message to the channel after joined one ? I want to send
one message and if its working next step is to add messages in queue and
they will be send automatic one by one.
How can i do it ?
No comments:
Post a Comment