🏡 index : ~doyle/titanirc.git

author Jordan Doyle <jordan@doyle.la> 2023-01-07 23:45:10.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2023-01-07 23:45:10.0 +00:00:00
commit
62b2142b866d4501827c00ddedd8015f6c237896 [patch]
tree
b62d812e0c6063aa5a7e1490b8221c406ab2b2f5
parent
51566d7610963b1eaf78b3f3938f95fa661dd93d
download
62b2142b866d4501827c00ddedd8015f6c237896.tar.gz

Implement MOTD command



Diff

 src/client.rs   | 20 +++++++++++++++++++-
 src/messages.rs |  7 +++++++
 src/server.rs   | 12 ++++++++++++
 3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/src/client.rs b/src/client.rs
index 14924fe..7fc1927 100644
--- a/src/client.rs
+++ a/src/client.rs
@@ -16,7 +16,7 @@
    messages::{
        Broadcast, ChannelFetchTopic, ChannelInvite, ChannelJoin, ChannelKickUser, ChannelList,
        ChannelMemberList, ChannelMessage, ChannelPart, ChannelUpdateTopic, FetchClientDetails,
        ServerDisconnect, UserKickedFromChannel, UserNickChange,
        ServerDisconnect, ServerFetchMotd, UserKickedFromChannel, UserNickChange,
    },
    server::Server,
    SERVER_NAME,
@@ -438,7 +438,23 @@
                }
            }
            Command::NOTICE(_, _) => {}
            Command::MOTD(_) => {}
            Command::MOTD(_) => {
                let span = Span::current();
                let fut = self
                    .server
                    .send(ServerFetchMotd { span })
                    .into_actor(self)
                    .map(|result, this, _ctx| {
                        for message in result
                            .unwrap()
                            .into_messages(this.connection.nick.to_string())
                        {
                            this.writer.write(message);
                        }
                    });

                ctx.spawn(fut);
            }
            Command::LUSERS(_, _) => {}
            Command::VERSION(_) => {
                self.writer.write(Message {
diff --git a/src/messages.rs b/src/messages.rs
index 9c4a8aa..94344cc 100644
--- a/src/messages.rs
+++ a/src/messages.rs
@@ -83,6 +83,13 @@
    pub reason: Option<String>,
}

/// Fetch the message of the day from the server.

#[derive(Message)]
#[rtype(result = "super::server::response::Motd")]
pub struct ServerFetchMotd {
    pub span: Span,
}

/// Sent from channels to users when a user is removed from the channel.

#[derive(Message)]
#[rtype(result = "()")]
diff --git a/src/server.rs b/src/server.rs
index 2222d9e..8346421 100644
--- a/src/server.rs
+++ a/src/server.rs
@@ -15,7 +15,7 @@
    connection::InitiatedConnection,
    messages::{
        Broadcast, ChannelFetchTopic, ChannelJoin, ChannelList, ChannelMemberList,
        FetchClientByNick, ServerDisconnect, UserConnected, UserNickChange,
        FetchClientByNick, ServerDisconnect, ServerFetchMotd, UserConnected, UserNickChange,
    },
    server::response::Motd,
    SERVER_NAME,
@@ -85,6 +85,16 @@
        }

        self.clients.insert(msg.handle, msg.connection);
    }
}

/// Returns the MOTD when requested.

impl Handler<ServerFetchMotd> for Server {
    type Result = MessageResult<ServerFetchMotd>;

    #[instrument(parent = &msg.span, skip_all)]
    fn handle(&mut self, msg: ServerFetchMotd, _ctx: &mut Self::Context) -> Self::Result {
        MessageResult(Motd::new(self))
    }
}