forked from lavina/lavina
1
0
Fork 0

- change trait's signature

This commit is contained in:
homycdev 2024-04-22 07:44:16 +03:00
parent 07f2730c8f
commit f2ccdee9d5
4 changed files with 39 additions and 28 deletions

View File

@ -1,12 +1,19 @@
use lavina_core::prelude::Str;
use lavina_core::repo::Storage;
use proto_irc::response::SendResponseBody;
use std::future::Future;
use tokio::io::AsyncWrite;
use proto_irc::response::SendResponseBody;
pub mod whois;
pub trait Handler<Command> {
struct HandlerY<T: AsyncWrite + Unpin> {
server_name: Str,
client: Str,
writer: T,
storage: Storage,
}
pub trait Handler {
fn handle(
&self,
server_name: &Str,

View File

@ -3,33 +3,37 @@ use tokio::io::{AsyncWrite, AsyncWriteExt};
use lavina_core::prelude::Str;
use proto_irc::response::SendResponseBody;
pub struct ERR_NOSUCHNICK_401 {
/// ERR_NOSUCHNICK (401)
pub struct ErrNoSuchNick401 {
client: Str,
nick: Str,
}
impl ERR_NOSUCHNICK_401 {
impl ErrNoSuchNick401 {
pub fn new(client: Str, nick: Str) -> Self {
ERR_NOSUCHNICK_401 { client, nick }
ErrNoSuchNick401 { client, nick }
}
}
struct ERR_NOSUCHSERVER_402 {
/// ERR_NOSUCHSERVER (402)
struct ErrNoSuchServer402 {
client: Str,
/// target parameter in WHOIS
/// example: `/whois <target> <nick>`
server_name: Str,
}
pub struct ERR_NONICKNAMEGIVEN_431 {
/// ERR_NONICKNAMEGIVEN (431)
pub struct ErrNoNicknameGiven431 {
client: Str,
}
impl ERR_NONICKNAMEGIVEN_431 {
impl ErrNoNicknameGiven431 {
pub fn new(client: Str) -> Self {
ERR_NONICKNAMEGIVEN_431 { client }
ErrNoNicknameGiven431 { client }
}
}
impl SendResponseBody for ERR_NOSUCHNICK_401 {
impl SendResponseBody for ErrNoSuchNick401 {
async fn write_response(self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> {
writer.write_all(b"401 ").await?;
writer.write_all(self.client.as_bytes()).await?;
@ -41,7 +45,7 @@ impl SendResponseBody for ERR_NOSUCHNICK_401 {
}
}
impl SendResponseBody for ERR_NONICKNAMEGIVEN_431 {
impl SendResponseBody for ErrNoNicknameGiven431 {
async fn write_response(self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> {
writer.write_all(b"431").await?;
writer.write_all(self.client.as_bytes()).await?;
@ -51,7 +55,7 @@ impl SendResponseBody for ERR_NONICKNAMEGIVEN_431 {
}
}
impl SendResponseBody for ERR_NOSUCHSERVER_402 {
impl SendResponseBody for ErrNoSuchServer402 {
async fn write_response(self, writer: &mut (impl AsyncWrite + Unpin)) -> std::io::Result<()> {
writer.write_all(b"402 ").await?;
writer.write_all(self.client.as_bytes()).await?;

View File

@ -6,14 +6,14 @@ use lavina_core::repo::Storage;
use proto_irc::client::command_args::Whois;
use proto_irc::response::{IrcResponseMessage, SendResponseBody, SendResponseMessage};
use crate::commands::whois::error::{ERR_NONICKNAMEGIVEN_431, ERR_NOSUCHNICK_401};
use crate::commands::whois::error::{ErrNoNicknameGiven431, ErrNoSuchNick401};
use crate::commands::whois::response::{RplWhoIsUser311, RPL_ENDOFWHOIS_318};
use crate::commands::Handler;
pub mod error;
pub mod response;
impl Handler<Whois> for Whois {
impl Handler for Whois {
async fn handle(
&self,
server_name: &Str,
@ -29,7 +29,7 @@ impl Handler<Whois> for Whois {
Whois::EmptyArgs => {
IrcResponseMessage::empty_tags(
Some(server_name.clone()),
ERR_NONICKNAMEGIVEN_431::new(server_name.clone()),
ErrNoNicknameGiven431::new(server_name.clone()),
)
.write_response(writer)
.await?
@ -68,7 +68,7 @@ async fn handle_nick_target(
.write_response(writer)
.await?
} else {
ERR_NOSUCHNICK_401::new(client.clone(), nick.clone()).write_response(writer).await?
ErrNoSuchNick401::new(client.clone(), nick.clone()).write_response(writer).await?
}
Ok(())
}

View File

@ -3,8 +3,8 @@ use tokio::io::{AsyncWrite, AsyncWriteExt};
use lavina_core::prelude::Str;
use proto_irc::response::SendResponseBody;
struct RplWhoiscertfp276;
struct RplWhoIsRegNick307;
struct RplWhoisCertfp276;
struct RplWhoisRegNick307;
pub struct RplWhoIsUser311 {
client: Str,
/// unique name
@ -26,16 +26,16 @@ impl RplWhoIsUser311 {
}
}
struct _RplWhoisserver312;
struct _RplWhoisoperator313;
struct _RplWhoisidle317;
struct _RplWhoischannels319;
struct _RplWhoisspecial320;
struct _RplWhoisaccount330;
struct _RplWhoisactually338;
struct _RplWhoishost378;
struct _RplWhoismodes379;
struct _RplWhoissecure671;
struct _RplWhoisServer312;
struct _RplWhoisOperator313;
struct _RplWhoisIdle317;
struct _RplWhoisChannels319;
struct _RplWhoisSpecial320;
struct _RplWhoisAccount330;
struct _RplWhoisActually338;
struct _RplWhoisHost378;
struct _RplWhoisModes379;
struct _RplWhoisSecure671;
struct _RplAway301;
pub struct RPL_ENDOFWHOIS_318 {
client: Str,