Experimental topic implementation
This commit is contained in:
parent
340c652bb1
commit
dde7aeb43f
|
@ -40,5 +40,5 @@ async fn main() -> Result<(), tokio::io::Error> {
|
|||
Happy hacking!
|
||||
|
||||
todo list for famfo:
|
||||
- [ ]: implement getting the topic of a channel
|
||||
- [x]: implement getting the topic of a channel
|
||||
- [ ]: implement getting users in a channel
|
||||
|
|
|
@ -217,9 +217,11 @@ pub enum Command {
|
|||
/// Channel
|
||||
String,
|
||||
/// Topic
|
||||
Option<String>,
|
||||
String,
|
||||
),
|
||||
#[doc(hidden)]
|
||||
TopicBy(String, String),
|
||||
#[doc(hidden)]
|
||||
USER(String, String, String, String),
|
||||
}
|
||||
|
||||
|
@ -258,6 +260,16 @@ impl Command {
|
|||
let msg = parts[3..].join(" ");
|
||||
|
||||
return Self::PRIVMSG(nick, target.to_string(), (msg[1..]).to_string());
|
||||
} else if parts.get(1) == Some(&"332") {
|
||||
let channel = parts[3];
|
||||
let topic = parts[4..].join(" ");
|
||||
|
||||
return Self::TOPIC(channel.to_string(), topic.to_string());
|
||||
} else if parts.get(1) == Some(&"333") {
|
||||
let user = parts[4];
|
||||
let time = parts[5];
|
||||
|
||||
return Self::TopicBy(user.to_string(), time.to_string());
|
||||
}
|
||||
|
||||
Self::OTHER(new.to_string())
|
||||
|
|
24
src/lib.rs
24
src/lib.rs
|
@ -527,14 +527,34 @@ impl Client {
|
|||
/// ```
|
||||
/// # Errors
|
||||
/// Returns IO errors from the TcpStream.
|
||||
pub async fn topic(&mut self, channel: &str, topic: Option<&str>) -> Result<(), Error> {
|
||||
pub async fn topic(
|
||||
&mut self,
|
||||
channel: &str,
|
||||
topic: Option<&str>,
|
||||
) -> Result<(String, String, String, String), Error> {
|
||||
if let Some(topic) = topic {
|
||||
self.write(format!("TOPIC {} :{}\r\n", channel, topic))
|
||||
.await?;
|
||||
return Ok((String::new(), String::new(), String::new(), String::new()));
|
||||
} else {
|
||||
// Can we make this more efficient? Yes! But how?
|
||||
self.write(format!("TOPIC {}\r\n", channel)).await?;
|
||||
let mut channel_channel = String::new();
|
||||
let mut channel_topic = String::new();
|
||||
if let Some(command) = self.read().await? {
|
||||
if let commands::Command::TOPIC(channel, topic) = command {
|
||||
channel_channel = channel;
|
||||
channel_topic = topic;
|
||||
}
|
||||
}
|
||||
let mut topic_return = (String::new(), String::new(), String::new(), String::new());
|
||||
if let Some(command) = self.read().await? {
|
||||
if let commands::Command::TopicBy(user, time) = command {
|
||||
topic_return = (channel_channel, channel_topic, user, time);
|
||||
}
|
||||
}
|
||||
return Ok(topic_return);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
|
|
Loading…
Reference in a new issue