Closed Bassetts closed 5 years ago
If you're sending a message to a channel, you should probably wait until you receive your first message listing users in that channel, which IIRC should be a RPL_NAMREPLY
.
Thanks for the quick response. Am I right in thinking I would accomplish that in the following way?
extern crate irc;
use irc::client::prelude::*;
use std::default::Default;
fn main() {
let config = Config {
nickname: Some("pickles".to_owned()),
server: Some("irc.mozilla.org".to_owned()),
channels: Some(vec!["#rust-spam".to_owned()]),
..Default::default()
};
let client = IrcClient::from_config(config).unwrap();
client.identify().unwrap();
client.for_each_incoming(|message| {
match message.command {
Command::Response(Response::RPL_NAMREPLY, _, _) => {
client.send_privmsg("#rust-spam", "TWEET TWEET").unwrap();
client.send_quit("QUIT").unwrap();
},
_ => (),
}
}).unwrap();
}
It would probably be best to check if the RPL_NAMREPLY is for the channel you're sending it to, but otherwise, that's roughly the right idea.
@aatxe thanks, should this issue actually be that the tweeter example causes a 451 ERR_NOTREGISTERED
on the first loop, or is that not really worrying as it's just an example?
In the case of the tweeter example, my current stance is that it's not super important since it's a toy program and doesn't really have any kind of spec anyway. I'm closing the issue since I'm fine with the example as is, but if you (or anyone else) feels strongly about it, I'm happy to reconsider.
It seems that the tweeter example attempts calls
send_privmsg
before the connection to the server is complete which results in the first iteration of the loop getting a451 ERR_NOTREGISTERED
from the server.I discovered this when trying to setup a very simple bot that connects to a channel, sends a message, then quits. My message never showed in the channel because
send_privmsg
was running before registration had completed.What is the correct way to make sure the message is not sent until registration has successfully completed?